loevgaard / sylius-barcode-plugin
Add barcodes to your products using this plugin
Installs: 22 685
Dependents: 2
Suggesters: 2
Security: 0
Stars: 7
Watchers: 3
Forks: 5
Open Issues: 8
Type:sylius-plugin
Requires
- php: >=7.4
- doctrine/persistence: ^1.3 || ^2.0
- setono/doctrine-orm-batcher-bundle: ^0.3.1
- sylius/sylius: ^1.3
- symfony/config: ^4.4 || ^5.4
- symfony/event-dispatcher: ^4.4 || ^5.4
- symfony/event-dispatcher-contracts: ^1.0 || ^2.0 || ^3.0
- symfony/messenger: ^4.4 || ^5.4
- thecodingmachine/safe: ^1.0
- violuke/php-barcodes: ^1.0
Requires (Dev)
- behat/behat: ^3.4
- behat/mink: ^1.7@dev
- behat/mink-browserkit-driver: ^1.3
- behat/mink-extension: ^2.2
- behat/mink-selenium2-driver: ^1.3
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.0
- friends-of-behat/variadic-extension: ^1.1
- lakion/mink-debug-extension: ^1.2.3
- phpspec/phpspec: ^6.1
- phpunit/phpunit: ^8.3
- roave/security-advisories: dev-latest
- sensiolabs/security-checker: ^5.0
- setono/code-quality-pack: ^2.1.3
- symfony/browser-kit: ^4.4 || ^5.0
- symfony/debug-bundle: ^4.4 || ^5.0
- symfony/dotenv: ^4.4 || ^5.0
- symfony/intl: ^4.4 || ^5.0
- symfony/web-profiler-bundle: ^4.4 || ^5.0
- symfony/web-server-bundle: ^4.4 || ^5.0
- v1.6.0
- v1.5.1
- v1.5.0
- dev-master / 1.4.x-dev
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/composer/sylius-labs/coding-standard-tw-4.1
- dev-dependabot/composer/phpspec/phpspec-tw-7.1
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/phpunit/phpunit-tw-9.5
- dev-dependabot/composer/lakion/mink-debug-extension-tw-2.0.0
- dev-sylius-1.8-upgrade
- dev-dependabot/composer/sensiolabs/security-checker-tw-6.0
- dev-feature-grid-with-invalid-barcodes
- dev-improvements
This package is auto-updated.
Last update: 2024-11-07 18:13:09 UTC
README
Add barcodes to your products.
Installation
Step 1: Download the plugin
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require loevgaard/sylius-barcode-plugin
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the plugin
Then, enable the plugin by adding it to the list of registered plugins/bundles
in the config/bundles.php
file of your project:
<?php // config/bundles.php return [ // ... Setono\DoctrineORMBatcherBundle\SetonoDoctrineORMBatcherBundle::class => ['all' => true], Loevgaard\SyliusBarcodePlugin\LoevgaardSyliusBarcodePlugin::class => ['all' => true], // ... ];
Note that adding SetonoDoctrineORMBatcherBundle
also required.
Step 3: Configure the plugin
# config/packages/loevgaard_sylius_barcode.yaml imports: # ... - { resource: "@LoevgaardSyliusBarcodePlugin/Resources/config/app/config.yaml" } loevgaard_sylius_barcode: form: require: true # If true the barcode field will be required in the product forms require_valid: true # If true the barcode must be valid when entered in the product forms
Step 4: Import product variant trait
<?php // src/Entity/ProductVariant.php declare(strict_types=1); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Loevgaard\SyliusBarcodePlugin\Model\ProductVariantInterface as LoevgaardSyliusBarcodePluginProductVariantInterface; use Loevgaard\SyliusBarcodePlugin\Model\ProductVariantTrait as LoevgaardSyliusBarcodePluginProductVariantTrait; use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant; /** * @ORM\Entity * @ORM\Table(name="sylius_product_variant") */ class ProductVariant extends BaseProductVariant implements LoevgaardSyliusBarcodePluginProductVariantInterface { use LoevgaardSyliusBarcodePluginProductVariantTrait; // ... }
NOTE: If you haven't extended the ProductVariant
entity yet, follow the customization instructions first because you need to add a bit more configuration:
# config/packages/_sylius.yaml
sylius_product:
resources:
product_variant:
classes:
model: App\Entity\ProductVariant
Step 5: Update your database schema
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
Step 6: Add form widgets to twig templates
You need to override the template displaying the product and product variant form and add a form_row
statement with the barcode:
{# templates/bundles/SyliusAdminBundle/ProductVariant/Tab/_details.html.twig #} {# ... #} <div class="ui segment"> {{ form_row(form.code) }} {{ form_row(form.barcode) }} {# This is the part you should add #} <div class="two fields"> {{ form_row(form.shippingCategory) }} </div> {{ form_row(form.channelPricings) }} </div> {# ... #}
{# templates/bundles/SyliusAdminBundle/Product/Tab/_details.html.twig #} <div class="ui segment"> {{ form_row(form.code) }} {{ form_row(form.enabled) }} {% if product.simple %} {{ form_row(form.variant.barcode) }} {# This is the part you should add #} {{ form_row(form.variant.onHand) }} {{ form_row(form.variant.tracked) }} {{ form_row(form.variant.shippingRequired) }} {{ form_row(form.variant.version) }} {% else %} {{ form_row(form.options) }} {{ form_row(form.variantSelectionMethod) }} {% endif %} {# Nothing to see here. #} <div class="ui hidden element"> {% if product.simple %} {{ form_row(form.variant.translations) }} {% endif %} {{ form_row(form.variantSelectionMethod) }} </div> </div>
If you haven't overridden the template yet, you can just copy the templates from vendor/loevgaard/sylius-barcode-plugin/src/Resources/views/SyliusAdminBundle
to templates/bundles/SyliusAdminBundle/
Step 7: Add validator constraint
Create config/validator/ProductVariant.xml
:
<?xml version="1.0" encoding="UTF-8"?> <constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd"> <class name="App\Entity\ProductVariant"> <constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity"> <option name="fields">barcode</option> <option name="message">loevgaard_sylius_barcode.product_variant.barcode.unique</option> <option name="groups">sylius</option> </constraint> </class> </constraint-mapping>
Like it configured at example application.
Step 8: Using asynchronous transport (optional, but recommended)
All commands in this plugin will extend the CommandInterface. Therefore you can route all commands easily by adding this to your Messenger config:
# config/packages/messenger.yaml framework: messenger: routing: # Route all command messages to the async transport # This presumes that you have already set up an 'async' transport 'Loevgaard\SyliusBarcodePlugin\Message\Command\CommandInterface': async
Usage
Run the check command:
$ php bin/console loevgaard:barcode:check
This will mark all product variant as checked and updated the field barcodeValid
to either true or false depending on the result of the check.