Product page displaying incorrect prices when using combinations price reduction and customer group discounts



  • Hi,

    I am using combinations with price reductions. As I sell secondhand books, my main listed price is ‘As New’. I reduce for each degradation in book condition such as ‘Very Good’, ‘Good’, ‘Acceptable’ etc in the combinations.

    I have just created a new customer group, offering these shoppers a 10% discount. The product page reduces the price of the combination price by 10% of the main ‘As New’ price, when displaying combinations. The shopping cart is unaffected.

    0_1543834790195_Price-difference-screenshot.png

    There is something on the Prestashop forum about this but the solution is to replace the following files:

    \controllers\front\ProductController.php
    \classes\Product.php

    https://www.prestashop.com/forums/topic/499621-1609-to-1614-item-with-combination-is-showing-incorrect-prices/

    Is there anyway to sort this quickly or should I report this as a bug on GitHub?

    Any help would be greatly appreciated.

    Regards,

    Luke



  • Price on the product page and in the shopping cart being different can’t be right.

    But which is the right price? 8.64 - 10% = 7.85



  • P.S.: replacing entire files is a bad idea. Perhaps this gets rid of this particular problem, but it also resets all bug fixes since then.



  • Thanks for replying. The shopping cart price is correct. The Retail Price is RM12. The price is reduced by RM2.40 for being a Library Very Good Copy (RM9.60).

    A customer group discount of 10% (RM0.96) should reduce this to RM8.64 as the cart displays. However, on the product listing 10% of the Retail price (RM1.20) is being subtracted RM9.60 - RM1.20 = RM8.40.



  • I managed to recreate the exact same problem on the http://back.thirtybees.com. I wanted to be sure that it wasn’t something on my installation.

    0_1543844040178_price-wrong-1.png

    0_1543844051525_price-wrong-2.png



  • rm 12
    -30 % => 8,40



  • @lukewood said in Product page displaying incorrect prices when using combinations price reduction and customer group discounts:

    I managed to recreate the exact same problem on the http://back.thirtybees.com. I wanted to be sure that it wasn’t something on my installation.

    I’ve also noticed some unexpected behavior when it comes to combination reductions, though independently of customer group discounts. It could be the bug is there somewhere.



  • I managed to fix the problem by editing contollers/front/ProductController.php.

    I added the following function

    protected function getGroupReduction() {
        $id_customer = (isset($this->context->customer) ? (int)$this->context->customer->id : 0);
        $id_group = (int)Group::getCurrent()->id;
        $id_country = $id_customer ? (int)Customer::getCurrentCountry($id_customer) : (int)Tools::getCountry();
    
        $group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group);
        if ($group_reduction === false) {
            $group_reduction = Group::getReduction((int)$this->context->cookie->id_customer) / 100;
        }
        return $group_reduction;
    }
    

    One line 742 (after function about line 756), I replaced the following code:

    $combinations[$row['id_product_attribute']]['price'] = (float) Tools::convertPriceFull($row['price'], null, $this->context->currency, false);
    

    with

    $group_reduction = $this->getGroupReduction();
    $price = $row['price'] - $row['price']* $group_reduction;
    $combinations[$row['id_product_attribute']]['price'] = (float)Tools::convertPriceFull($price, null, Context::getContext()->currency, false);
    

    My test server appears to be working well. I would appreciate it if any programmers could see if this could cause any other problems down the line. I am not a coder and worried that I might make spheres of things.

    Cheers,

    Luke



  • thanks for the information



  • Thanks for the code.

    Still it smells like too much code. Cart calculates the price correctly already, so code for the right calculation has to exist somewhere already.



  • I just see we have a bug report for this already: https://github.com/thirtybees/thirtybees/issues/538 Does the description there match your case?



  • @traumflug

    Yes, this appears to be the same although I could not tell you if it is JS Variables or PHP.

    i did try this fix but it did not work for me:

    Modify from themes the product.js

    find around line 680

    basePriceWithTax = basePriceWithTax + +combination.price * (taxRate/100 + 1)
    and replace with

    basePriceWithTax = basePriceWithTax + +combination.price * (taxRate/100 + 1) * (1 - groupReduction);
    and few lines bellow find

    basePriceWithTax = +combination.specific_price.price * (taxRate/100 + 1)
    and replace with

    basePriceWithTax = +combination.specific_price.price * (taxRate/100 + 1) * (1 - groupReduction);



  • @Traumflug

    Yes, this is definitely the same issue. I tested on http://back.thirtybees.com and it behaves the same.



  • Thanks for the investigation, @lukewood.


 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.