brille24/sylius-special-price-plugin

Provides time based special pricing for Sylius.

Installs: 16 339

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 4

Forks: 2

Open Issues: 2

Type:sylius-plugin


README

Build Status

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.

Installation

  1. Require the plugin

    composer require brille24/sylius-special-price-plugin
  2. Register the plugin in your bundles.php

    return [
        ...
        Brille24\SyliusSpecialPricePlugin\Brille24SyliusSpecialPricePlugin::class => ['all' => true],
    ];
  3. Import plugin config

    imports:
        ...
        - { resource: "@Brille24SyliusSpecialPricePlugin/Resources/config/config.yml" }
  4. Add migrations

    1. Copy migrations from tests/Application/migration to your desired spot for migrations.
  5. Override ProductVariant entity

    1. Write new class which will use ProductVariantSpecialPricableTrait and implement ProductVariantSpecialPricableInterface
    2. Override the models class in config
      sylius_product:
          resources:
              product_variant:
                  classes:
                      model: Brille24\SyliusSpecialPricePlugin\Entity\ProductVariant
  6. Add mapping and validation

    1. 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>
    2. 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>
  7. Override SyliusAdminBundle/ProductVariant/Tab/_details.html.twig

    Add this:

    <div class="ui segment">
        {% include 'Brille24SyliusSpecialPricePlugin::_specialPrice.html.twig' with {
            'form': form.channelSpecialPricings
        } %}
    </div>
  8. Update the database schema

    bin/console doctrine:schema:update --force

Running the test server

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)

Testing

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