PrestaShop / PrestaShop

PrestaShop is the universal open-source software platform to build your e-commerce solution.
https://www.prestashop-project.org/
Other
8.09k stars 4.79k forks source link

Impact on price per unit (combinations option) does not compute unit_price correctly #20156

Open ballashop opened 4 years ago

ballashop commented 4 years ago

Dear staff, I have a problem with "Impact on price per unit (tax excl.)" into the combination item. first change some option: Customers Setting → Groups Price display method all Groups are Tax excluded

Create new Attributes & Features add new attributes Name: Quantity Public name: Quantity Attribute type: Radio buttons

Add new values 2 pieces 6 pieces 12 pieces 26 pieces

Create new product Name: Green apple Pricing tab Price (tax excl.): 1 € Price per unit (tax excl.) 1 €

retail price

Select → Product with combinations Add all pieces value and price

value

Add a combination price (combination price € X less Price (tax excl.): 1 € ) 2 pieces € 2 less Price (tax excl.): 1 € = 1 € (unit cost → 1€ ) 6 pieces € 6 less Price (tax excl.): 1 € = 5 (unit cost → 1€ ) 12 pieces € 12 less Price (tax excl.): 1 € = 11 (unit cost → 1€ ) 26 pieces € 26 less Price (tax excl.): 1 € = 25 (unit cost → 1€ )

Impact on price

1) The price is shown correctly 2) The unit price is not! How should I manage the unit price of the combinations so that the correct unit price is always shown? If I don't add nothing, the front end show unit price like price Example for firs combination: first-combination and the second combination: second-combination What am I doing wrong? Thanks for any reply.

prestashop-issue-bot[bot] commented 4 years ago

Thanks for opening this issue! We will help you to keep its state consistent

matks commented 4 years ago

Hi @ballashop ! The description of this bug is very good (that's nice ! not everybody does it) but I need the prestashop version of your shop 😅 because this behavior might be different, depending on the version

ballashop commented 4 years ago

Hi @matks thanks to reply me, we use: 1.7.6.3 I apologize for forgetting it. Thanks for any reply. Balla.

matks commented 4 years ago

Hi @ballashop,

So I understood what is the issue here 😄 .

The unit price is actually being stored as a divisor, and applied for each of your combination.

So, when you created your product you set

So, for 2 pieces, PrestaShop is going to say "price for 2 pieces is 2€, then unit price is 100% of 2€ => 2€" So, for 4 pieces, PrestaShop is going to say "price for 2 pieces is 4€, then unit price is 100% of 4€ => 4€"

=> wrong 😱

So ... one solution might be to use the following settings:

So, for 2 pieces, PrestaShop is going to say "price for 2 pieces is 2€, then unit price is 50% of 1€ => 1€" 🎉 So, for 4 pieces, PrestaShop is going to say "price for 4 pieces is 4€, then unit price is 50% of 4€ => 2€" NO 😱 So, for 6 pieces, PrestaShop is going to say "price for 6 pieces is 6€, then unit price is 50% of 3€ => I display 3€" NO 😱

So the root cause is that "unit price" does not work well with "impact on price".

This is definitely a buggy behavior 👍 that we need to fix so I add it to the roadmap. However it's going to require quite a lot of thoughts to fix it 😄 this is a bit complex.

@MatShir FYI, some interesting usecase

@ballashop As you probably cannot wait for the bugfix (it will probably be quite long) I can provide the 2 workarounds:

Capture d’écran 2020-07-13 à 14 51 09

ballashop commented 3 years ago

Hi, @matks @khouloudbelguith any news about this bug? At the moment we are using 1.7.6.9 Thanks a lot for any reply. Balla

matks commented 3 years ago

Hi @ballashop nothing new, topic is still in "To Do".

ballashop commented 3 years ago

@matks, thanks for the reply, we hope it will be resolved soon. Balla

Shoprunners commented 3 years ago

Hi, as stated out by matks, unit_price_impact entry is not really userfriendly and if you want to use it as it is, you should create a Excel table with some formulars... BUT: there is a bug in the code as well:

Class "Product", method "getProductProperties" around row 4950

replace ` if (0 != $combination->unit_price_impact && 0 != $row['unit_price_ratio']) {

        $unitPrice = ($row['price_tax_exc'] / $row['unit_price_ratio']) + $combination->unit_price_impact;          
       $row['unit_price_ratio'] = $row['price_tax_exc'] / $unitPrice;
    }`

with

` if (0 != $combination->unit_price_impact && 0 != $row[\'unit_price_ratio\']) {

        $unitPrice = ($row['price_tax_exc'] / $row['unit_price_ratio']) + $combination->unit_price_impact;          
        $main_product_price_excl = Product::getPriceStatic((int) $row['id_product'],false,null,6,null,false,true,1,true,null,null,null,$specific_prices);           
        $row['unit_price_ratio'] = $row['unit_price_ratio']*($row['price_without_reduction'] / $my_main_product_price_excl);
    }`

WHY? Because original code takes the unit_price_ration of the main product (without attributes) into account and not the unit_price_ratio of the combination. This will fail...

Since you are planning a redesign of this, I won't submit a CR but give a hint, that you might have a closer look here.

By the way: please have a closer look in the same function how the cache_key is computed. It does not take into account every argument of the function. Possible problem....

ballashop commented 3 years ago

@Shoprunners thanks a lot for the message and really sorry for the late. I am not a developer so I'll avoid to manage to the code, if you can do it we can contact us privately. Thanks, bye. Balla

KoreLewi commented 11 months ago

Hi

Any news on this? I am using PrestaShop 1.7.8.10, and the bug still here . :(

Brig74 commented 5 months ago

Hi

Same issue here, using Prestashop 1.7.8.2. Is it resolved in the latest versions?