The Sylius supplier plugin adds support for a supplier model which can be used to extend products.
-
Install with Composer
composer require babdev/supplier-plugin:^1.0-dev
-
Add the plugin to
config/bundles.phpafter the SyliusResourceBundle, but before the SyliusGridBundleSylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], // other plugins and bundles BabDev\SyliusSupplierPlugin\BabDevSyliusSupplierPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
-
Import config
(in
config/packages/_sylius.yamlorconfig/packages/babdev_sylius_supplier.yaml))imports: - { resource: "@BabDevSyliusSupplierPlugin/Resources/config/app/config.yml" }
-
Import the routing
(in
config/routes.yamlorconfig/routes/babdev_sylius_supplier.yaml)babdev_sylius_supplier_admin: resource: "@BabDevSyliusSupplierPlugin/Resources/config/app/admin_routing.yml" prefix: /%sylius_admin.path_name%
-
Add the corresponding traits
-
use BabDev\SyliusSupplierPlugin\Model\ProductTrait; use BabDev\SyliusSupplierPlugin\Model\SupplierAwareInterface; use Sylius\Component\Core\Model\Product as BaseProduct; class Product extends BaseProduct implements SupplierAwareInterface { use ProductTrait; }
-
use BabDev\SyliusSupplierPlugin\Model\ProductVariantTrait; use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant; class ProductVariant extends BaseProductVariant { use ProductVariantTrait; }
-
-
Add the Doctrine mapping in the preferred format.
-
-
Annotations
namespace App\Entity\Product; use BabDev\SyliusSupplierPlugin\Model\ProductTrait; use BabDev\SyliusSupplierPlugin\Model\SupplierAwareInterface; use BabDev\SyliusSupplierPlugin\Model\SupplierInterface; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Product as BaseProduct; /** * @ORM\Entity * @ORM\Table(name="sylius_product") */ class Product extends BaseProduct implements SupplierAwareInterface { use ProductTrait; /** * @ORM\ManyToOne(targetEntity="BabDev\SyliusSupplierPlugin\Model\SupplierInterface") * @ORM\JoinColumn(name="supplier_id") * * @var SupplierInterface */ protected $supplier;
-
XML
<many-to-one field="supplier" target-entity="BabDev\SyliusSupplierPlugin\Model\SupplierInterface"> <join-column name="supplier_id" /> </many-to-one>
-
YAML
manyToOne: supplier: targetEntity: BabDev\SyliusSupplierPlugin\Model\SupplierInterface joinColumn: name: supplier_id
-
-
-
Annotations
namespace App\Entity\Product; use BabDev\SyliusSupplierPlugin\Model\ProductVariantTrait; use BabDev\SyliusSupplierPlugin\Model\SupplierPricingInterface; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant; /** * @ORM\Entity * @ORM\Table(name="sylius_product_variant") */ class ProductVariant extends BaseProductVariant { use ProductVariantTrait; /** * @ORM\ManyToOne(targetEntity="BabDev\SyliusSupplierPlugin\Model\SupplierPricingInterface", inversedBy="productVariant", cascade="ALL") * @ORM\JoinColumn(name="supplier_pricing_id", onDelete="SET NULL") * * @var SupplierPricingInterface */ protected $supplierPricing;
-
XML
<many-to-one field="supplierPricing" target-entity="BabDev\SyliusSupplierPlugin\Model\SupplierPricingInterface" inversed-by="productVariant"> <join-column name="supplier_pricing_id" on-delete="SET NULL" /> <cascade> <cascade-all/> </cascade> </many-to-one>
-
YAML
manyToOne: supplierPricing: targetEntity: BabDev\SyliusSupplierPlugin\Model\SupplierPricingInterface inversedBy: productVariant joinColumn: name: supplier_pricing_id onDelete: SET NULL
-
-
-
Update database schema via Doctrine migrations
-
Generate the migration
bin/console doctrine:migrations:diff
-
Check the generated migration, then execute it
bin/console doctrine:migrations:migrate
-
-
Add the field to the admin product form, for example in templates/bundles/SyliusAdminBundle/Product/Tab/_details.html.twig
{{ form_row(form.supplier) }}
-
Clone the repository (or a repository fork)
git clone https://github.com/BabDev/supplier-plugin cd supplier-plugin -
Install the dependencies
composer install
-
Initialize the test app with the following commands:
(cd tests/Application && yarn install) (cd tests/Application && yarn build) (cd tests/Application && bin/console APP_ENV=test assets:install public) (cd tests/Application && bin/console APP_ENV=test doctrine:database:create) (cd tests/Application && bin/console APP_ENV=test doctrine:schema:create)
-
(Optional) Setup MySQL database
By default, an SQLite database will be used, but you can setup a MySQL database, and configure its credentials in
tests/Application/.env.test.local.Here's an example for running MySQL database in a Docker container:
docker run -p 3307:3306 --env MYSQL_ROOT_PASSWORD=root --env MYSQL_DATABASE=sylius_test --env MYSQL_USER=sylius --env MYSQL_PASSWORD=sylius --name sylius-supplier-test -v sylius-supplier-test-data:/var/lib/mysql mysql:5.7
and the
tests/Application/.env.test.localDATABASE_URL=mysql://sylius:sylius@127.0.0.1:3307/sylius_test?serverVersion=5.7
-
PHPUnit
vendor/bin/phpunit
-
PHPSpec
vendor/bin/phpspec run
-
Behat (non-JS scenarios)
vendor/bin/behat --strict --tags="~@javascript" -
Behat (JS scenarios)
-
Start Headless Chrome:
google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1
- Install SSL certificates (only once needed) and run test application's webserver on
127.0.0.1:8080:
symfony server:ca:install APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
- Run Behat:
vendor/bin/behat --strict --tags="@javascript" -
Static Analysis
-
Psalm
vendor/bin/psalm
-
PHPStan
vendor/bin/phpstan analyse -c phpstan.neon -l max src/
-
-
Coding Standard
vendor/bin/ecs check src
-
Using
testenvironment:(cd tests/Application && APP_ENV=test bin/console sylius:fixtures:load) (cd tests/Application && APP_ENV=test symfony serve)
-
Using
devenvironment:(cd tests/Application && APP_ENV=dev bin/console sylius:fixtures:load) (cd tests/Application && APP_ENV=dev symfony serve)
If you believe you have discovered a security issue with this plugin, please email michael.babker@gmail.com with information about the issue. Do NOT use the public issue tracker for security issues.
Sylius and this plugin is licensed under the MIT License. See the LICENSE file for full details.