GithubHelp home page GithubHelp logo

brille24 / syliustierpriceplugin Goto Github PK

View Code? Open in Web Editor NEW
43.0 5.0 37.0 998 KB

A plugin for Sylius that implements tier pricing

License: MIT License

PHP 81.94% JavaScript 11.24% Gherkin 0.89% Twig 5.92%
sylius tier-prices variants product-variant price

syliustierpriceplugin's Introduction

Sylius Tier Price Plugin

Build Status

This plugin adds tier pricing to Sylius one product has different prices based on the quantity.

Installation

  • Install the bundle via composer composer require brille24/sylius-tierprice-plugin
  • Register the bundle in your bundles.php:
return [
    //...

    Brille24\SyliusTierPricePlugin\Brille24SyliusTierPricePlugin::class => ['all' => true],
];
  • Add the config.yml to your local config/config.yml
imports:
    ...
    - { resource: '@Brille24SyliusTierPricePlugin/Resources/config/config.yml'}
  • For API functionality add the bundle's routing.yml to the local app/config/routing.yml
...
brille24_tierprice_bundle:
    resource: '@Brille24SyliusTierPricePlugin/Resources/config/routing.yml'
  • Go into your ProductVariant class and add the following trait and add one method call to the constructor
class ProductVariant extends BaseProductVariant implements \Brille24\SyliusTierPricePlugin\Entity\ProductVariantInterface
{
    use \Brille24\SyliusTierPricePlugin\Traits\TierPriceableTrait;

    public function __construct() {
        parent::__construct(); // Your contructor here

        $this->initTierPriceableTrait(); // "Constructor" of the trait
    }

    protected function createTranslation(): ProductVariantTranslationInterface
    {
        return new ProductVariantTranslation();
    }
}
  • Finally update the database, install the assets and update the translations:
bin/console doctrine:schema:update --force
bin/console assets:install
bin/console translation:update <locale> --force

Integration

  • This bundle decorates the sylius.calculator.product_variant_price service. If you wish to change that, you could register a compiler pass.
  • This bundle decorates the sylius.order_processing.order_prices_recalculator service. If you wish to use your own order processor or change its priority, you could register a compiler pass.

Usage

First of all you have to set up a product with as many variants as you want. Then in each of these variants you can set the tier pricing based on the channels. The table automatically sorts itself to provide a better overview for all different tiers, you configured.

In the frontend the user will see a nice looking table right next to the "add to cart" button that shows the discount for the different tiers like so:

Creating data

You can easily create the tier prices with fixtures like that.

sylius_fixtures:
    suites:
        my_suite:
            fixtures:
                tier_prices:
                    options:
                        custom:
                            - product_variant: "20125148-54ca-3f05-875f-5524f95aa85b"
                              channel: US_WEB
                              quantity: 10
                              price: 5

For this the products need to be created first and the product variant must also exist.

Extending

If you want to extend the tierprices please be aware that this plugin is using XML for configuration. This might collide with projects that use Annotations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.