PHPackages                             it-bens/shopware-store-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. it-bens/shopware-store-api-client

ActivePackage[API Development](/categories/api)

it-bens/shopware-store-api-client
=================================

06PHP

Since Jul 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/it-bens/shopware-store-api-client)[ Packagist](https://packagist.org/packages/it-bens/shopware-store-api-client)[ RSS](/packages/it-bens-shopware-store-api-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Shopware Store API Client
=========================

[](#shopware-store-api-client)

Shopware provides a Store API to access all the content that is normally provided via storefront in a headless way. The documentation can be found here:  (this is for Shopware 6.5).

A JS library to use the Store API is provided directly by Shopware:

Currently, there is no PHP library provided by Shopware. Other libraries are partly or fully generated by the Store API documentation that can be found here: . However, the documentations contains a lot of errors: wrong response codes, wrong data structure documentation and a lack of nullability declarations. Although the obvious use code for a Store API client is to use the Store API with it, it also provides a type safe (but not necessarily complete and correct) documentation for data structures and response codes.

Installation
------------

[](#installation)

The client(s) can be installed via composer.

```
composer require it-bens/shopware-store-api-client
```

Usage
-----

[](#usage)

This package provides multiple clients for different parts of the Store API. They share the same dependencies during initialization, use the same processing flow and throw the same exceptions when something goes wrong. The clients are there functions are shown later.

### Initialization

[](#initialization)

The client initialization will be shown with the `CartClient` as an example.

```
use ITB\ShopwareStoreApiClient\RequestBuilder;
use ITB\ShopwareStoreApiClient\Auth\AccessTokenProvider\WithStaticAccessToken as AccessTokenProviderWithStaticAccessToken;
use ITB\ShopwareStoreApiClient\Tests\E2E\Helper\Psr18Client;
use Symfony\Component\Serializer\Serializer;
use ITB\ShopwareStoreApiClient\CartClient;

$shopwareStoreUrl = 'https://example.shopware.com';
$requestBuilder = new RequestBuilder();
$accessTokenProvider = new AccessTokenProviderWithStaticAccessToken('WYFFSAEAFGWEG');
$httpClient = new Psr18Client();
$serializer = new Serializer(...); // The symfony serializer initialization is a lot more complex. It will be shown later.
$responseProcessor = new ResponseProcessor($serializer);

$cartsClient = new CartClient(
    $shopwareStoreUrl,
    $requestBuilder,
    $accessTokenProvider,
    $httpClient,
    $serializer,
    $responseProcessor
);
```

#### Access Token Provider

[](#access-token-provider)

Shopware sales channels require an access token to be present in the request headers. `AccessTokenProvider` is an interface that aims to provide `AccessToken` objects at runtime. The `WithStaticAccessToken` class is the simplest implementation of this interface. The access token is just stored inside the object. Other implementations may fetch the access token from other sources.

The access token for a sales channel doesn't change by itself. So the "static" usage is usually sufficient.

#### HTTP Client

[](#http-client)

This package uses the PSR-18 standard for HTTP clients. The symfony version of this client is used in the E2E tests. However, every PSR-18 compatible implementation can be used. Feel free to use the one you like.

#### Serializer

[](#serializer)

The symfony serializer is used to deserialize the responses of the Store API into strictly types (as far as possible) data structures. In projects that use the symfony framework bundle, the serializer is already available. It just requires some custom normalizers from this package.

However, the serializer must be initialized by yourself if you don't use the symfony framework.

 Click to see the symfony serializer initialization```
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
use ITB\ShopwareStoreApiClient\ModelNormalizer\CustomerAddressNormalizer;
use ITB\ShopwareStoreApiClient\ModelNormalizer\OrderStateNormalizer;
use ITB\ShopwareStoreApiClient\ModelNormalizer\DeliveryStateNormalizer;
use ITB\ShopwareStoreApiClient\ModelNormalizer\TransactionStateNormalizer;
use ITB\ShopwareStoreApiClient\ModelNormalizer\ContextSourceNormalizer;
use ITB\ShopwareStoreApiClient\ModelNormalizer\OrderCollectionNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Serializer;

$encoders = [new JsonEncoder()];

$phpDocExtractor = new PhpDocExtractor(); // required to detect array types
$reflectionExtractor = new ReflectionExtractor(); // required to detect constructor arguments
$propertyInfoExtractor = new PropertyInfoExtractor(
    listExtractors: [$reflectionExtractor],
    typeExtractors: [$phpDocExtractor, $reflectionExtractor],
    descriptionExtractors: [$phpDocExtractor],
    accessExtractors: [$reflectionExtractor],
    initializableExtractors: [$reflectionExtractor]
);

$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader()); // required to detect discriminator mappings
$discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);

// custom normalizers / denormalizers (some of the require the serializer itself because they only prepare the data for the deserialization process)
$customerAddressNormalizer = new CustomerAddressNormalizer();
$orderStateNormalizer = new OrderStateNormalizer();
$deliveryStateNormalizer = new DeliveryStateNormalizer();
$transactionStateNormalizer = new TransactionStateNormalizer();
$contextSourceNormalizer = new ContextSourceNormalizer();
$orderCollectionNormalizer = new OrderCollectionNormalizer();

$objectNormalizer = new ObjectNormalizer(
    classMetadataFactory: $classMetadataFactory,
    propertyAccessor: PropertyAccess::createPropertyAccessor(),
    propertyTypeExtractor: $propertyInfoExtractor,
    classDiscriminatorResolver: $discriminator
);

$normalizers = [
    $customerAddressNormalizer,
    $orderStateNormalizer,
    $deliveryStateNormalizer,
    $transactionStateNormalizer,
    $contextSourceNormalizer,
    $orderCollectionNormalizer,
    new BackedEnumNormalizer(),
    new ArrayDenormalizer(),
    $objectNormalizer, // the object normalizer will try to denormalize everything without any specific logic, so it should be the last one in the list
];

$serializer = new Serializer($normalizers, $encoders);

$customerAddressNormalizer->setDenormalizer($serializer);
$customerAddressNormalizer->setNormalizer($serializer);
$orderStateNormalizer->setDenormalizer($serializer);
$deliveryStateNormalizer->setDenormalizer($serializer);
$transactionStateNormalizer->setDenormalizer($serializer);
```

### API functions

[](#api-functions)

#### Context Token Provider

[](#context-token-provider)

The context token identifies a customer(session) in Shopware. It is transmitted as a header like the access token. Not all API functions require a context token. `ContextTokenProvider` is an interface that aims to provide context tokens at runtime. This package provides two implementations: `WithAnonymousUser` and `WithAuthenticatedUser`.

##### With Anonymous User

[](#with-anonymous-user)

The `WithAnonymousUser` class uses the `/store-api/context` route to fetch or create a context token without any login. The provider stores the context token until the `resetContextToken` method is called.

##### With Authenticated User

[](#with-authenticated-user)

The `WithAuthenticatedUser` class takes customer credentials at creation and uses the `/store-api/account/login` route to perform the login. The context token is returned by Shopware. The provider stores the context token until the `resetContextToken` method is called.

#### Search Criteria

[](#search-criteria)

Shopware provides a very powerful search via API (not the product search). The options are documented here: . This packages depicts the search data structure with the `SearchCriteria` class.

It also contains two options that are inconsistently documented: `fields` and `includes`. While the `fields` option is documented in the Store API, the `includes` option is documented in the Admin API. They seem to have the same purpose but the format and the internal processing are working differently. The `fields` option restricts the fields that Shopware queries from the database (associations are considered). Restricting the queried fields can improve the performance a lot! The option takes a plain array of strings. Points are used as field separators. The `includes` option restricts the fields that are returned in the response (but they are still queried). The option takes a recursivly associative array. The keys are the API/entity aliases. The value can be a plain array of strings or another associative array. The combined usage of the `fields` and `includes` options grants the greatest performance improvements.

#### Address Client

[](#address-client)

API functiondescriptionrequest dataresponse datarequires contextfetchCustomerAddressesfetches addresses of the current customer by the provided search criteria`SearchCriteria``CustomerAddressCollection`yescreateCustomerAddresscreates a new address for the current customer`AddressData``CustomerAddress`yesupdateCustomerAddressupdates an existing address of the current customerID + `AddressData``CustomerAddress`yesdeleteCustomerAddressdeletes an existing address of the current customer (the last address cannot be deleted)IDnoneyeschangeCustomerDefaultBillingAddresschanges the default billing address of the current customerIDnoneyeschangeCustomerDefaultShippingAddresschanges the default shipping address of the current customerIDnoneyes#### Cart Client

[](#cart-client)

API functiondescriptionrequest dataresponse datarequires contextfetchOrCreateCartfetches the current cart or creates one if it does not exist yesnone`Cart`noaddLineItemsToCartadds line item(s) to the cart and forces a recalculation`LineItemCollection` with `LineItem`(s)`Cart`noupdateLineItemsInCartupdates line item(s) in the cart by the passed IDs (`LineItem` requires ID)`LineItemCollection` with `LineItem`(s)`Cart`nodeleteProductFromCartByProductIddeletes line item(s) from the cart by passed IDs (`LineItem` requires ID)`LineItemCollection` with `LineItem`(s)`Cart`nodeleteCartdeletes/clears the cartnonenonenoAll line item related functions require a `LineItemCollection`. It contains `LineItem` implementations. Currently, three `LineItem` implementations exist: `ProductLineItem`, `PromotionLineItem` and `LineItemReference`. The first two should be self-explanatory. The last one is used to reference a line item and can be used for the deletion of line items from the cart. A `CustomLineItem` implementation is planned. Shopware supports discount line items internally but they are not supported in the Store API and are mainly used via Plugins.

The `Cart` object contains an array of `Error` objects. The name is misleading because Shopware used them for errors, warning and notices. Only a few types are currently supported by this package. More will be added as soon as they appear in tests or usage in this package. **Contributions and issues are welcome.**

#### Context Client

[](#context-client)

API functiondescriptionrequest dataresponse datarequires contextfetchCurrentContextfetches the current context (you don't say!)none`Context`yesupdateCurrentContextupdates several values of the current context`ContextData`noneyesThe context contains a lot of information about the current customer(session). Updating the context is the designated way to change the addresses, the payment method and the shipping method that are used during the checkout process.

#### Order Client

[](#order-client)

API functiondescriptionrequest dataresponse datarequires contextfetchOrdersfetches orders of the current customer by the provided search criteria`SearchCriteria``OrderCollection`yescreateOrderFromCartcreates an order from the current cart through checkout`OrderMetadata` (optional)`Order`yescancelOrdercancels an order (state is set to cancelled)ID`OrderState`yesThe `createOrderFromCart` method will throw an exception if Shopware complains about something about the cart data. The thrown `RequestExceptionWithHttpStatusCode` provides a `getErrors` method the should provide all the errors that Shopware returned.

Contributing
------------

[](#contributing)

I am really happy that the software developer community loves Open Source, like I do! ♥

That's why I appreciate every issue that is opened (preferably constructive) and every pull request that provides other or even better code to this package.

You are all breathtaking!

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/94aa1cc7aa38ca9d3f6bb96541ff813027df1f0cf478b3c53c41385876503b2c?d=identicon)[SpiGAndromeda](/maintainers/SpiGAndromeda)

---

Top Contributors

[![SpiGAndromeda](https://avatars.githubusercontent.com/u/15141351?v=4)](https://github.com/SpiGAndromeda "SpiGAndromeda (13 commits)")

---

Tags

api-clientshopwarestore-api

### Embed Badge

![Health badge](/badges/it-bens-shopware-store-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/it-bens-shopware-store-api-client/health.svg)](https://phpackages.com/packages/it-bens-shopware-store-api-client)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
