Download the PHP package it-bens/shopware-sdk-bundle without Composer
On this page you can find all versions of the php package it-bens/shopware-sdk-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download it-bens/shopware-sdk-bundle
More information about it-bens/shopware-sdk-bundle
Files in it-bens/shopware-sdk-bundle
Package shopware-sdk-bundle
Short Description Bundle for the Shopware PHP SDK.
License MIT
Informations about the package shopware-sdk-bundle
Shopware 6 SDK Bundle for Symfony
This bundle wraps the Shopware 6 SDK into a Symfony bundle.
The bundle is tested with PHP Symfony 6.4 (PHP 8.3, PHP 8.4) and with Symfony 7.1 (PHP 8.3, PHP 8.4).
Installation
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
Requirements
- PHP 8.3 or higher
- Symfony 6.4 / 7.1 or higher
- a PSR-7 implementation
- a PSR-16 implementation (not required if the access token cache is disabled)
- a PSR-17 implementation
- a PSR-18 implementation
- a PSR-20 implementation
The PSR implementations can be chosen freely.
Configuration
Add the following configuration to your config/packages/itb_shopware_sdk.yaml
:
The shopware_version
key determines what entity schema is used for the native Shopware entities. Available versions are: 0.0.0.0
, 6.5.5.0
, 6.5.6.0
, 6.5.7.1
, 6.5.8.0
, 6.5.8.3
, 6.5.8.8
, 6.5.8.12
, 6.6.0.0
, 6.6.3.0
, 6.6.4.0
, 6.6.5.0
, 6.6.6.0
and 6.6.7.0
.
Use the next lower version in comparison to your Shopware version. The listed versions were the lowest that introduced entity schema changes.
0.0.0.0
can be used to use the entity schemas and definitions from the original SDK package.
There are two grant types available: client_credentials
and password
. A authentication with the password
grant type requires this configuration:
The credentials
block will not be merged with other configuration files or environments to prevent Environment variables ... are never used.
errors when different grant types are used in different environments. The block will be overwritten according to the hirarchy defined by Symfony: https://symfony.com/doc/current/configuration.html#configuration-environments.
Cache
The cache
key in the configuration determines if the obtained OAuth token should be cached. If set to null
every request will request a new token from Shopware, before doing anything else.
In a typical Symfony project, there are already several cache pools available. However, these implement Symfonys own cache contracts/interfaces. This Shopware SDK requires a PSR-16 implementation to make it compatible with other frameworks and framework-less applications.
A PSR-16 implementation can be easily defined as a service if the symfony/cache
component is installed:
Usage
CRUD Repository
Shopware provides the usual CRUD operations for entities. The bundle provides repositories to execute this operations.
The repositories can injected directly via autowiring:
The dependency injection container will automatically will let the RepositoryProvider
create the requested repositories based on the argument name.
The argument name has to be the entity name in camel case with the suffix EntityRepository
. The RepositoryInterface
type hint is required.
Alternatively, they can be obtained via the RepositoryProviderInterface
.
The provider caches the repositories, so they don't have to be recreated every time, the method is called.
[!IMPORTANT]
The chosen Shopware version determines which entity classes are hydrated and returned by the repository. Pay attention to the usage of the correct entity classes in your project.
API Service
Besides from the CRUD entity endpoints, Shopware provides endpoints that are either not entity related or perform special operations outside the CRUD scope. The currently available API services are:
- Admin Search API (read-equivalent to the Sync API)
- Document API + Document Generator API
- Info API
- Mail Send API
- Media API
- Notification API
- Number Range API
- State Machine API
- Sync API (upserting/deleting multiple entities in a single request)
- System Config API
- User Config API
- User API
They can be obtained directly via their interfaces:
Adding and Overriding Entity Definitions
The SDK package provides definitions, entity classes and collection classes for the native Shopware entities. New entities can be added to Shopware via Plugins. The SDK package and this bundle provide a way to add these entities to your project.
This requires an implementation of the DefinitionCollectionPopulator
interface.
If the service has the AsEntityDefinitionCollectionPopulator
attribute and is marked for autoconfiguration (this will likely happen in a typical Symfony project), the service is automatically tagged as a DefinitionCollectionPopulator
.
After that a compiler pass in this bundle will detect the tag and add the service to the DefinitionCollectionProvider
.
Of cause the service can be tagged manually as well:
The priority determines the order in which the populators are used. The native populator has the priority 1000 and is used first. This allows to override existing definitions by populators with a lower priority. The entity name is used as a key in the definition collection and allows to overwrite native/existing definitions by usage of the same entity name.
[!TIP] If a Shopware plugin adds relations to existing entities, these relations have to be present in the entity definition in this bundle as well. Overwriting the native definition with a populator is the way to go.
The native definition class can be copied and modified. The entity class does not have to be modified because Shopware returns tha added relations as an extension and extensions are already part of all entity classes.
Custom Usages
This bundle provides the following additional services via dependency injection:
The purpose and usage of this services is explained in the SDK repository.
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!
All versions of shopware-sdk-bundle with dependencies
it-bens/shopware-sdk Version ^0.6
symfony/config Version ^6.4|^7.1
symfony/dependency-injection Version ^6.4|^7.1
symfony/http-kernel Version ^6.4|^7.1