aimeos / aimeos-laravel

Laravel ecommerce package for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
https://aimeos.org/Laravel
MIT License
7.26k stars 1.05k forks source link

different pricing for select type products logically not working correctly #427

Closed parsester closed 2 years ago

parsester commented 2 years ago

Environment

  1. Aimeos/Laravel 2021.10.3
  2. CentOS 7
  3. PHP v8.0.11
  4. Laravel v8.70.2

Describe the bug for a product with select type, when I set second price such a way that minimum quantity is 2, when I select 2 item of this product with different selection property, the second pricing does not work. I don't set price for each property separately and just set price for Parent Select Type product, that mean customer select 2 different property of a same product and second pricing logically must work.

I think for this situation must be a solution, what can I do?

aimeos commented 2 years ago

We can't reproduce the problem. This is how we test:

1.) Create a product with type "select" 2.) Create two prices with 30€ for one item and 20€ for two items in the price tab 3.) Create two variant products in the "Variants" tab with different variant attributes ("blue" and "black" in our case) 4.) Add the product to a category

If you select one of the variants in the frontend and add it to the basket with a quantity of "2", that the single price is 20€ and the total is 40€ like expected.

parsester commented 2 years ago

yes but I mean customer select two different Variants of "select" type product, so in your example when customer select a product with "blue" color and select another with "black" color, in fact and logically customer buy 2 number of "select" product and price may calculate with quantity of "2". because in reality the product is the same product and just colors is different.

aimeos commented 2 years ago

Then, this are two different products and tier pricing doesn't apply here because it's only for one product.

You can create your own basket plugin which handles that situation: https://aimeos.org/docs/latest/providers/basket-plugins/

parsester commented 2 years ago

ok, and how about Pricing rules (https://aimeos.org/docs/latest/providers/rules/) does this help me? please give me your optimized code to put in my TirePricingPlugin or give code for non "select" type product to use it in plugin, I have no idea about it.

aimeos commented 2 years ago

The price rules won't help here because you can only use them to give a discount to all articles based on some criteria.

If only the selection product has prices, you could adapt this code to use the sum of all variant articles belonging to that selection product and pass it to getLowestPrice(): https://github.com/aimeos/aimeos-core/blob/2020.10/lib/mshoplib/src/MShop/Plugin/Provider/Order/ProductPrice.php#L229-L250

parsester commented 2 years ago

thanks @aimeos

I create "SelectTypeTirePricingPlugin" by making changes to the file aimeos ProductPrice Plugin.

I attach my "SelectTypeTirePricingPlugin" file to this comment for your review: MySelectTypeTirePricingPlugin.txt

this plugin now working for me and my need, I use it to my laravel livewire which I use it for add orders from admin users to another customers when I add product to basket from below method:

public function addToBasket($productCode, $qty, $type, $variant) {
    $context = app('aimeos.context')->get();
    $basketCtrl = \Aimeos\Controller\Frontend::create( $context, 'basket' );

    $productManager = \Aimeos\MShop::create( $context, 'product');
    $productSearch = $productManager->filter();
    $expr = array(
        $productSearch->compare( '==', 'product.code', $productCode ),
    );
    $productSearch->setConditions( $productSearch->combine( '&&', $expr ) );
    $productItem = $productManager->search( $productSearch, ['product', 'price', 'text', 'attribute'] )->first();
    if ($type == 'select') {
        $basketCtrl->addProduct($productItem, $qty, $variant);
    } else {
        $basketCtrl->addProduct($productItem, $qty);
    }
    $this->position = $this->position + 1;
    $this->emit('basketUpdate');
}

first when I add a product on the above method, my "SelectTypeTirePricingPlugin" don't work and not called. I replace $p->attach( $this->getObject(), 'check.after' ); with $p->attach($this->getObject(), 'addProduct.after' ); in register method of plugin and it work in livewire.

now I have this questions?

  1. Is what I did right?
  2. because this plugin is exactly copy of ProductPrice plugin, Will this plugin slow down the process of adding the product to the cart?
  3. If it slows down, do you suggest changes to optimize it?
  4. Do you have any plans to consider requests similar to my request in the next update?
  5. because this plugin is exactly copy of ProductPrice plugin, Can I disable your plugin and enable this plugin?
aimeos commented 2 years ago
  1. Is what I did right?

In principle, yes.

  1. because this plugin is exactly copy of ProductPrice plugin, Will this plugin slow down the process of adding the product to the cart?

No, but you only need to activate your plugin and disable the original ProductPrice plugin.

  1. Do you have any plans to consider requests similar to my request in the next update?

If you create a PR with your changes, we will see if we can merge it for 2022.x

  1. because this plugin is exactly copy of ProductPrice plugin, Can I disable your plugin and enable this plugin?

Yes, and you have to.