shopsys / plugin-interface
General Shopsys Platform plugin interface
Requires
- php: ^8.3
- symfony/monolog-bridge: ^5.4.0
- 16.0.x-dev
- 15.0.x-dev
- v15.0.0
- 14.0.x-dev
- v14.0.1
- v14.0.0
- 13.0.x-dev
- v13.0.0
- 12.1.x-dev
- 12.0.x-dev
- v12.0.0
- v11.1.0
- dev-master / 11.0.x-dev
- v11.0.0
- 10.0.x-dev
- v10.0.5
- v10.0.4
- v10.0.3
- v10.0.2
- v10.0.1
- v10.0.0
- 9.1.x-dev
- v9.1.3
- v9.1.2
- v9.1.1
- v9.1.0
- 9.0.x-dev
- v9.0.4
- v9.0.3
- v9.0.2
- v9.0.1
- v9.0.0
- 8.1.x-dev
- v8.1.2
- v8.1.1
- v8.1.0
- 8.0.x-dev
- v8.0.0
- 7.3.x-dev
- v7.3.7
- v7.3.6
- v7.3.5
- v7.3.4
- v7.3.3
- v7.3.2
- v7.3.1
- v7.3.0
- 7.2.x-dev
- v7.2.2
- v7.2.1
- v7.2.0
- 7.1.x-dev
- v7.1.1
- v7.1.0
- 7.0.x-dev
- v7.0.1
- v7.0.0
- v7.0.0-beta6
- v7.0.0-beta5
- v7.0.0-beta4
- v7.0.0-beta3
- v7.0.0-beta2
- v7.0.0-beta1
- v7.0.0-alpha6
- v7.0.0-alpha5
- v7.0.0-alpha4
- v7.0.0-alpha3
- v7.0.0-alpha2
- v7.0.0-alpha1
- v0.3.0
- v0.2.0
- v0.1.0
- dev-alpha
- dev-tl-fix-using-wrong-classes
- dev-tl-convertim-backend
- dev-pt-yaml-standards-vol-2
- dev-rc-12-0-0
- dev-tl-fix-failing-12-0-builds
- dev-mg-js-translations-fix
- dev-mg-split-repo
- dev-rc-11-1-0
- dev-mg-deployment
- dev-mg-project-cold-fusion
- dev-mg-remove-manifests
- dev-tl-fix-project-base
- dev-rc-11-0-0
- dev-rc-10-0-5
- dev-rk-fw-uprage-from-10-to-11-part-3
- dev-rc-v9-1-3
- dev-rk-fw-1019-api-query-name-in-symfony-profiler
- dev-rk-fw-uprage-from-10-to-11-part-2
- dev-rc-10-0-4
- dev-rc-10-0-3
- dev-rc-10-0-2
- dev-mg-release-lock
- dev-mg-remove-twig-extension
- dev-rk-fw-uprage-from-10-to-11-part-1
- dev-rc-10-0-1
- dev-mg-fw-933-remove-rootdir
- dev-rc-10-0-0
- dev-mg-upgrade-php8
- dev-mg-remove-be-api-integration
- dev-rv-fw-837-doctrine-upgrade
- dev-rv-fw-847-migrations-tests
- dev-mg-improve-entity-extension
- dev-rv-fw-810-fix-actions
- dev-rc-v9-1-2
- dev-rc-v7-3-7
- dev-mg-allow-dependency
- dev-mg-fix-phpstan-packages
- dev-mg-force-proxy-manager-version
- dev-mg-update-node
- dev-origin/tl-phpstan-all-packages
- dev-tl-release-9-1-1
- dev-ds-coding-standards-allow-symfony-5-higher
- dev-tl-remove-package-builder
- dev-tl-github-actions-for-packages
- dev-ds-fix-ecs
- dev-mg-update-helios-elfinder
- dev-tp-allow-coding-standards-for-symfony5
- dev-rc-v9-1-0
- dev-rc-v7-3-6
- dev-rc-v9-0-4
- dev-tl-fix-docker-limits
- dev-mg-php74-only
- dev-rc-v9-0-3
- dev-ds-more-coding-standards
- dev-rc-v7-3-5
- dev-ds-ecs-path-fix
- dev-rc-v9-0-2
- dev-ds-eof-new-line
- dev-ds-phpstan-lvl-5
- dev-tl-fix-phpstan
- dev-rc-v9-0-1
- dev-tl-add-psr-14
- dev-ds-fixed-framework-standaards
- dev-rc-v7-3-4
- dev-rc-v8-1-2
- dev-rc-v9-0-0
- dev-tl-fix-current-customer-user
- dev-tp-js-fixes
- dev-vitek-rostislav-patch-3
- dev-tg-grunt-webpack
- dev-tp-symfony4
- dev-rv-eur-on-first-domain
- dev-rc-v7-3-3
- dev-tp-update-composer
- dev-ds-easier-elastic-extensebility
- dev-rc-v8-1-1
- dev-rc-v8-1-0
- dev-tp-npm-link
- dev-mg-weird-flex-but-ok
- dev-ds-fix-project-base-dependency
- dev-ds-fix-sed-macos
- dev-mg-graphql-categories
- dev-ds-kubernetes-simplify
- dev-tl-rv-datafixtures-refactoring
- dev-ds-kubernetes-simplify-test
- dev-rv-extended-classes-fixer
- dev-rv-phpstan-lvl4
- dev-ds-test-install-script-automatically
- dev-rc-8-0-0
- dev-ss-api-import-products
- dev-do-version-lock
- dev-rc-v7-3-0
- dev-ss-api-separated-from-default-project-base
- dev-do-elastic-structure-deploy
- dev-mg-fix-k8s-https
- dev-ph-price-calculation
- dev-ph-redis-clients
- dev-tl-fix-tests-bc-break
- dev-tl-removed-tests-bc-break
- dev-tl-united-non-bc-break-service-injections
- dev-ss-tl-api-products
- dev-ph-phing-test
- dev-tl-end-support-php-71
- dev-bb-multidomain-sitemap
- dev-do-mg-mail-attachments
- dev-bb-initcontainer-owner-fix
- dev-bb-flysystem-volume-driver
- dev-do-phpstan-upgrade
- dev-rv-read-model-bck
- dev-jg-redis-cache
- dev-mg-elastic-filtering
- dev-rv-upgrade-ecs
- dev-bb-ecs-hotfix
- dev-jg-form-ordering
- dev-rv-better-php-doc-parser-config
- dev-do-fixtures-project-base
- dev-mg-multiple-cron
- dev-mc-cdn-bucket
- dev-sspooky13-pt-yaml-standards
- dev-do-product-export-fix
- dev-mc-ph-google-cloud-bundle
This package is auto-updated.
Last update: 2024-12-13 13:20:18 UTC
README
Package of interfaces providing compatibility between Shopsys Platform and plugins.
This repository is maintained by shopsys/shopsys monorepo, information about changes is in monorepo CHANGELOG.md.
Features
This package contains interfaces responsible for general functionality usable in almost any plugin. For specific functionality, such as generating product feeds, there are separate repositories.
Example
For example usage see the AcmeProductCrudExtension
in the CRUD extension section below.
Storing data
Best way to store your plugin data is to use Doctrine entities.
Create a folder (e.g. src/Entity
) in your plugin and put your entities there.
Then you need to create DoctrineOrmMappingPass
and add it as CompilerPass
in your YourBundleNameBundle
class. This can be done like this:
// vendor/your-bundle-name-bundle/src/YourBundleNameBundle.php // ... /** * @inheritdoc */ public function build(ContainerBuilder $container) { parent::build($container); $container->addCompilerPass( DoctrineOrmMappingsPass::createAnnotationMappingDriver( [$this->getNamespace() . '\Entity'], [$this->getPath() . '/Entity'] ) ); } // ...
This tells Doctrine where to look for your entities. Now you can create Repository
and manage your data as you are used to.
CRUD extension
Sometimes your plugin needs some extra information to be included in an entity, for example, you need to track the weight of products. This can be solved by extending the entity CRUD model with your custom sub-form.
To do so you should implement PluginCrudExtensionInterface
and tag the service in a DI container with shopsys.crud_extension
tag.
The tag should have a type
attribute defining which CRUD model should be extended (eg. "product"
).
Each form extension has its label, form type and methods for managing the form data.
Example
services: acme.acme_product_crud_extension: class: AcmePlugin\AcmeProductCrudExtension tags: - { name: shopsys.crud_extension, type: product } acme.acme_data_form_type: class: AcmePlugin\AcmeProductFormType tags: - { name: form.type }
// ... class AcmeProductCrudExtension implements PluginCrudExtensionInterface { private $acmeProductFacade; public function __construct(AcmeProductFacade $acmeProductFacade) { $this->acmeProductFacade = $acmeProductFacade; } public function getFormTypeClass() { return AcmeProductFormType::class; } public function getFormLabel() { return 'ACME data'; } public function getData($productId) { $acmeProduct = $this->acmeProductFacade->findByProductId($productId); $pluginData = [ 'attribute' => $acmeProduct->getAttribute(), ]; return $pluginData; } public function saveData($productId, $data) { $acmeProductData = new AcmeProductData(); $acmeProductData->attribute = $data['attribute']; $this->acmeProductFacade->save($productId, $acmeProductData); } public function removeData($productId) { $this->acmeProductFacade->remove($productId); } }
Demo Data
In order to enable easy testing or to demonstrate usage of your plugin, you might want to provide demonstrational data with it.
In that case, you should implement PluginDataFixtureInterface
that will take care of loading demonstrational data into the core.
All you got to do is to implement PluginDataFixtureInterface::load()
method and tag the service in a DI container with shopsys.data_fixture
tag.
Example
services: acme.acme_bundle.data_fixture: class: AcmePlugin\AcmeDataFixture tags: - { name: shopsys.data_fixture }
class AcmeDataFixture implements PluginDataFixtureInterface { private $acmeProductFacade; public function __construct(AcmeProductFacade $acmeProductFacade) { $this->acmeProductFacade = $acmeProductFacade; } public function load() { $firstAcmeProductData = new AcmeProductData(); $firstAcmeProductData->enableWeightCalculation = true; $firstAcmeProductData->weight = 42; $firstAcmeProductData->domainId = 1; $this->acmeProductFacade->save($firstAcmeProductData); $secondAcmeProductData = new AcmeProductData(); $secondAcmeProductData->enableWeightCalculation = false; $secondAcmeProductData->weight = null; $secondAcmeProductData->domainId = 2; $this->acmeProductFacade->save($secondAcmeProductData); } }
CRON modules
When your plugin needs to execute some task periodically, for example downloading currency exchange rates every six hours, you can use a CRON module.
There are 2 types of CRON module interfaces:
SimpleCronModuleInterface
- for short tasks that do not take too long to execute
IteratedCronModuleInterface
- for long-running tasks that can be divided into smaller parts
- if the module takes too long to run it will be suspended and will be woken up and re-run during the next opportunity
You can implement either one of these interfaces and tag the service in a DI container with shopsys.cron
tag.
CRON modules are started automatically every time the current system time matches the specified mask in the tag attributes hours
and minutes
.
Example
acme.data_download_cron_module: class: AcmePlugin\AcmeDataDownloadCronModule tags: - { name: shopsys.cron, hours: '*/6', minutes: '0' }
// ... class AcmeDataDownloadCronModule implements SimpleCronModuleInterface { /** * @var \Symfony\Bridge\Monolog\Logger */ private $logger; public function setLogger(Logger $logger) { $this->logger = $logger; } public function run() { $data = $this->downloadData(); $this->saveData($data); $this->logger->info(sprintf('Downloaded %d new records.', count($data))); } // ... }
How to implement a plugin
Plugins are implemented in a form of a Symfony bundle. For tips on how to write a new bundle see Best Practices for Reusable Bundles.
Contributing
Thank you for your contributions to Shopsys Plugin Interface package. Together we are making Shopsys Platform better.
This repository is READ-ONLY. If you want to report issues and/or send pull requests, please use the main Shopsys repository.
Please, check our Contribution Guide before contributing.
Support
What to do when you are in troubles or need some help? The best way is to join our Slack.
If you want to report issues, please use the main Shopsys repository.