Warning
THIS PLUGIN IS NO LONGER MAINTAINED. Please use the catalog promotion functionality (in 1.13 and later) for this.
This plugin provides a configuration for prices that are just active within a certain date range. So if you want to change the price for a product between the 1st May and the 1st of April, this plugin is for you.
-
Require the plugin
composer require brille24/sylius-special-price-plugin
-
Register the plugin in your
bundles.php
return [ ... Brille24\SyliusSpecialPricePlugin\Brille24SyliusSpecialPricePlugin::class => ['all' => true], ];
-
Import plugin config
imports: ... - { resource: "@Brille24SyliusSpecialPricePlugin/Resources/config/config.yml" }
-
Add migrations
- Copy migrations from
tests/Application/migration
to your desired spot for migrations.
- Copy migrations from
-
Override ProductVariant entity
- Write new class which will use ProductVariantSpecialPricableTrait and implement ProductVariantSpecialPricableInterface
- Override the models class in config
sylius_product: resources: product_variant: classes: model: Brille24\SyliusSpecialPricePlugin\Entity\ProductVariant
-
Add mapping and validation
- Mapping
<!-- ProductVariant.orm.xml --> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"> <mapped-superclass name="Your\Name\Space\ProductVariant" table="sylius_product_variant"> <one-to-many field="channelSpecialPricings" target-entity="Brille24\SyliusSpecialPricePlugin\Entity\ChannelSpecialPricingInterface" mapped-by="productVariant" orphan-removal="true"> <cascade> <cascade-all/> </cascade> </one-to-many> </mapped-superclass> </doctrine-mapping>
- Validation
<!-- ProductVariant.xml --> <constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"> <class name="Your\Name\Space\ProductVariant"> <constraint name="Brille24\SyliusSpecialPricePlugin\Validator\ProductVariantChannelSpecialPriceDateOverlapConstraint"> <option name="groups">sylius</option> </constraint> </class> </constraint-mapping>
- Mapping
-
Override
SyliusAdminBundle/ProductVariant/Tab/_details.html.twig
Add this:
<div class="ui segment"> {% include 'Brille24SyliusSpecialPricePlugin::_specialPrice.html.twig' with { 'form': form.channelSpecialPricings } %} </div>
-
Update the database schema
bin/console doctrine:schema:update --force
From the plugin root directory, run the following commands:
(cd tests/Application && yarn install)
(cd tests/Application && yarn build)
(cd tests/Application && bin/console assets:install --symlink)
(cd tests/Application && bin/console doctrine:database:create)
(cd tests/Application && bin/console doctrine:schema:update --force)
(cd tests/Application && bin/console sylius:fixtures:load)
(cd tests/Application && bin/console server:start)
In order to run the phpspec tests you need to run the command vendor/bin/phpspec run
In order to run the phpunit tests you need to run the command vendor/bin/phpunit
In order to run the behat tests you need to run the command vendor/bin/behat