> For the complete documentation index, see [llms.txt](https://docs.b2b-sellers.com/b2b-platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.b2b-sellers.com/b2b-platform/3/developer-guides/b2bsellers-core-plugin/b2bcontexttrait.md).

# B2bContextTrait

**What are PHP Traits?**

Since PHP 5.4.0, there is a method of reusing code in PHP called traits. Traits is a mechanism for reusing code that is used in programming languages with simple inheritance such as PHP.

**Why is the B2bContextTrait useful for your individual extension?**

With the B2bContextTrait you can make in your PHP Code a simple function to distinguish the customer ("Customers"). Is the logged-in customer an end customer, an employee/user of a customer or is he a sales employee, you can also query whether the sales employee is currently logged into an end customer.

What are the possible functions:

| Function                                | Description                                                                                                                         |
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| hasB2bPlatformContext                   | Is the B2BPlatformContext set. This means whether the customer/user is logged in and is either a customer user or a sales employee. |
| getB2bPlatformContext                   | Return of the B2BPlatform Context (Type: B2bPlatformContext)                                                                        |
| isLoggedInAsSalesRepresentative         | Is a sales employee logged in.                                                                                                      |
| isLoggedInAsEmployee                    | Is the logged-in user a user/employee of a customer.                                                                                |
| getEmployee                             | Return of all employee fields (type: EmployeeEntity)                                                                                |
| isSalesRepresentativeLoggedInAsCustomer | Is a sales employee currently logged into a customer employee.                                                                      |
| customerIsSalesRepresentative           | Always returns true: when you are logged in as a sales agent and when you are logged in to a customer as a sales agent              |

#### Note (Alert):

You must always hand over the SalesChannelContext as a parameter.

How can you use our B2bContextTrait in your Shopware extension?

With the "use" function you can add the trait to any PHP class...

<div align="left"><img src="https://content.gitbook.com/content/xtXbbs1TkvdlT98tybg5/blobs/lFrhkUWxveqAncvnaBAP/111.png" alt=""></div>

And then call the classes from the trait via $this->\[function-name].

![](https://content.gitbook.com/content/xtXbbs1TkvdlT98tybg5/blobs/5218GyTUupmulxCacTaq/112.png)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.b2b-sellers.com/b2b-platform/3/developer-guides/b2bsellers-core-plugin/b2bcontexttrait.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
