Giter Site home page Giter Site logo

brille24 / syliustierpriceplugin Goto Github PK

View Code? Open in Web Editor NEW
44.0 5.0 36.0 1002 KB

A plugin for Sylius that implements tier pricing

License: MIT License

PHP 81.88% JavaScript 11.28% Gherkin 0.89% Twig 5.94%
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
{
    use \Brille24\SyliusTierPricePlugin\Traits\TierPriceableTrait;

    public function __construct() {
        // Your contructor here

        $this->initTierPriceableTrait() // "Constructor" of the trait
    }
}
  • 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 uses XML mappings, if you are using attributes for mappings these classes don't work.

  • 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.

syliustierpriceplugin's People

Contributors

antiseptikk avatar bartoszpietrzak1994 avatar bitbager avatar daniellienert avatar jakobtolkemit avatar jdubuisson avatar joppedc avatar julientroopers avatar lchrusciel avatar lsmith77 avatar lucagallinari avatar maikrosenthal avatar mamazu avatar marek-pietrzak-tg avatar markbeazley avatar olia avatar pamil avatar pierre-h avatar pjedrzejewski avatar radnok avatar roshyo avatar stefandoorn avatar t-n-y avatar tavy315 avatar teohhanhui avatar tuxes3 avatar zales0123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

syliustierpriceplugin's Issues

Schema not updating in default installation.

Recieving
bin/console doctrine:schema:update --force
[OK] Nothing to update - your database is already in sync with the current entity metadata.

On base installation (all caches cleared). Tested on both Sylius 1.8 and 1.7.

Dependency injection fails: non-existent service brille24.factory.tierprice

Container fails to compile if I import resource '@Brille24SyliusTierPricePlugin/Resources/config/config.yml' via config/config.yaml (so: following Readme instructions).

The service "Brille24\SyliusTierPricePlugin\Factory\TierPriceFactoryInterface" has a dependency on a non-existent service "brille24.factory.tierprice".

But it will compile if I include / replace relevant lines in _sylius.yaml config file.

Main packages are

    "require": {
        "php": "^8.2",
        "ext-json": "*",
        "brille24/sylius-tierprice-plugin": "2.3.2",
        "sylius/invoicing-plugin": "^0.24.0",
        "sylius/paypal-plugin": "^1.5.1",
        "sylius/refund-plugin": "^1.4",
        "sylius/sylius": "1.12.12",
        "symfony/dotenv": "^6.3.7",
        "symfony/flex": "^2.4.1",
        "symfony/runtime": "^6.3.2"
    },

Update: while container complies if I make changes / additions to sylius resources in _sylius.yaml file, attempting to update doctrine schema ill fail with The table with name "alka_webshop.sylius_product_variant" already exists.

It will work if I update ProductVariant definitions in App bundle with SyliusTierPrice bundle relevant changes.

Plugin installation override the doctrine migration_paths order

Sylius version : 1.9
Plugin version : v2.0.1

After installing the plugin, I noticed that all the migrations that we create using the doctrine:migrations:diff (or :generate) ends up in the plugins migration folder, instead of the project's directory.

Turns out the plugin's Brille24SyliusTierPriceExtension class prepend its migration_path, causing the following thing :
image

Migrations are correctly setup in our project (see our config/packages/doctrine_migrations.yaml file)
image

image

Maybe you can follow this patch from BitBagCommerce/SyliusWishlistPlugin

Thanks

Sylius plugins conventions

Hello everyone, I would like to congrats you for this awesome plugin, great job! It surly provides really useful functionality for Sylius :) I think we would be very proud to show your plugin on plugins list on our website, however we have some strict naming conventions defined, which not all of them are fulfilled by this project - take a look at http://docs.sylius.com/en/1.1/plugins/creating-plugin.html#naming-conventions. The most important thing is using SyliusPluginTrait and proper extension naming.
Moreover, if you would need/want some code review regarding Sylius coding standards, I'm sure some of us would be pleased to do this :)

Nevertheless, great work, it's good to have such a plugin in Sylius ecosystem and such a team in Sylius community :)

Expected argument of type "int", "null" given at property path "qty".

I discovered an issue when i tried saving an empty row. I expected it to have the same behaviour as delete_empty would have, but instead the plugin tried to save the empty row. Which throwed an exception because null is not a NumberType. I tried to add the delete_empty => true to the collection type, but this did not have any effect. I added a suggestion to fix this, but of course any other fix is also very welcome. I am not able to provide a PR due to time constraints.

How to reproduce issue

  • Add 1 or more valid tierprice to any product variant
  • Add a empty row to tierprices
  • Save tierpricing
    Then the following error is shown:
    Expected argument of type "int", "null" given at property path "qty".

Suggested fix / workaround

Add empty_data => 0 to both the qty and price types in the TierPriceType

Issue updating tier prices for customer groups

In order to reproduce (in Admin UI) the problem I'm facing, make sure you have an existing product with only one tier price for one customer group.

price

Delete the existing tier price (don't save yet) and then add new one using exactly the same values as the one deleted. Save the tier price and you will get an exception.

error

Trying the same scenario with no customer group selected isn't throwing the exception.

Fixtures

It should be possible to create the tier prices with the Sylius Fixture mechanic.

Add old prices

Currently it just works for the current price. If you want to display an old price with a line through this will not work in the current version.

Unable to override plugin templates

It seems impossible to override plugin templates using the Symfony's override bundle resource functionality.

This applies to Sylius ThemeBundle as well; neither of structures below work, Symfony Profiler consistently lists rendered template (name & path) as @Brille24SyliusTierPricePlugin/Resources/views/Shop/Product/Show/_tier_price_promo.html.twig / vendor/brille24/sylius-tierprice-plugin/src/Resources/views/Shop/Product/Show/_tier_price_promo.html.twig, also after clearing cache.

App:

- templates
    - bundles
        - Brille24SyliusTierPricePlugin
            - Shop
                - Product
                    - Show
                        - _tier_price_promo.html.twig

Theme:

- themes
    - [theme]
        - Brille24SyliusTierPricePlugin
            - views
                - Shop
                    - Product
                        - Show
                            - _tier_price_promo.html.twig

Price validation is less than or equal to zero

The validation constraint for a TierPrice is defined in SyliusTierpricePlugin/src/Resources/config/validation/validation.xml.
It defines a constraint LessThanOrEqual with value 0 for the price.

Unless I missed something, it should be GreaterThanOrEqual with value 0.

Product menu listener crashes the product edit page

Where did it originate from
In the commit c3f21ee#diff-acdf3d30cb1e2b445a95f6b746645e0f a listener was added to inject the tier price menu item into the product menu in Sylius.

This works for simple product items in Sylius, but when you try to edit or create a product which has variants, it crashes on the form for it can't find the part form.varaint in the twig template of views/Admin/ProductVariant/Tab/_tierprice.html.twig (line 33).

How to reproduce

  1. Use a new Sylius project or existing project
  2. Open Sylius admin
  3. Open the products tab
  4. Open a product with variants/create a new product with variants
  5. The error appears

Temporary fix
The solution to fix it for now in a project was by removing the service brille24.listener.admin.product.form.menu_builder in a compiler pass.

Exception during the database update

Hi,
I try to install your plugin but when I update the database, the console show the exception

In SchemaException.php line 108:
The table with name 'sylius_dev.sylius_product_variant' already exists.

My sylius version is 1.7

Fixtures loading is broken

After upgrading from 1.0 to 1.6, my existing fixtures failed to load.

It seems that the TierPriceExampleFactory is not properly configured to resolve the fixtures data, and turn the given strings (product_variant and channel) into the matching objects.

I cannot see "tier prices" in a configurable product

I have an instance of Sylius v1.11 standard edition runnning where I installed Tier Price plugin following instructions on the readme. However, I cannot see the menu entry For Tier prices as shown in the instructions screenshot.

The deviation I was forced to take from the instruction is that I manually merged the contents of Resources/config/config.yml inside of config/package/_sylius.yaml and also updated src/Entity/Product/ProductVartiant.php to extend from you plugin rather than from Sylius Core.

Please notice that the menu entry and form do show up for simple products. Yet I need configurable products.

Is Standard Edition simply not supported or am I missing something?

Thanks in advance.

Working with 100's of quantities and adjustments

Hi there,

thanks for this great addition to sylius.

Did anyone expierence already some issues with 100's of quantities?
We planned to use this plugin for like quantities of 250 - 1000 units.

The problem what i expierenced is that for all of those quantities it would run as many adjustments on the pricings and applieng coupons and stuff just makes it a huge mess and comes into database lock issues etc. For now i handled that with Memcache to not run in locking issues.

Did anybody solve that? Did you turn off automatic adjustments then? Or any suggestions how to handle 100's of quantities?

Missing file Brille24SyliusTierPriceBundle

After adding the bundle using composer, I added the following part to AppKernel following the README.

public function registerBundles()
{
    return array_merge(parent::registerBundles(), [
        ...

        new \Brille24\SyliusTierPricePlugin\Brille24SyliusTierPriceBundle(),
    ]);
}

This file is missing in the bundle. I would aspect it to be at vendors/brille24/sylius-tierprice-plugin/Brille24SyliusTierPriceBundle.php.

Does the part in the AppKernel need to point to another file, or is the file missing?

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.