Jump to content

Quantity discount on category view


thehurricane

Recommended Posts

Hello,

I have (I hope) small problem. On Product page i have table with quantity discounts for each product. I want to place the same table on category view (for each product), but suddenly when I @var_dump product variable it is null, how can I show this table? Any suggestions? :)

Link to comment
Share on other sites

prestashop does not have a feature to build such "quantity discount" table on category pages,
if you want it: it requires major "background" core code that will pass the 'quantity discounts' for each product + template file (modification or own .tpl file) that will show it on list of products (product-list.tpl). 

simply saying, you need to assign results (for each product) of "formatQuantityDiscounts" function:

    protected function formatQuantityDiscounts($specific_prices, $price, $tax_rate, $ecotax_amount)
    {
        $customerGroupDiscountPercent = 1 - ((float)Group::getReduction((int)$this->context->customer->id) / 100);
        $displayPriceMethod = (int)Group::getPriceDisplayMethodByGroup((int)Group::getCurrent()->id);
        foreach ($specific_prices as $key => &$row) {
            $row['quantity'] = &$row['from_quantity'];
            if ($row['price'] >= 0) {
                // The price may be directly set
                $cur_price = ($displayPriceMethod === 1 ? $row['price'] : $row['price'] * (1 + $tax_rate / 100)) + (float)$ecotax_amount;
                if ($row['reduction_type'] == 'amount') {
                    $cur_price -= ($row['reduction_tax'] ? $row['reduction'] : $row['reduction'] / (1 + $tax_rate / 100));
                    $row['reduction_with_tax'] = $row['reduction_tax'] ? $row['reduction'] : $row['reduction'] / (1 + $tax_rate / 100);
                } else {
                    $cur_price *= 1 - $row['reduction'];
                }
                /** Apply the group reduction */
                $cur_price *= $customerGroupDiscountPercent;
                $row['real_value'] = $row['base_price'] > 0 ? $row['base_price'] - $cur_price : $cur_price;
            } else {
                if ($row['reduction_type'] == 'amount') {
					if (Product::$_taxCalculationMethod == PS_TAX_INC) {
						$row['real_value'] = $row['reduction_tax'] == 1 ? $row['reduction'] : $row['reduction'] * (1 + $tax_rate / 100);
					} else {
						$row['real_value'] = $row['reduction_tax'] == 0 ? $row['reduction'] : $row['reduction'] / (1 + $tax_rate / 100);
					}
                    $row['reduction_with_tax'] = $row['reduction_tax'] ? $row['reduction'] : $row['reduction'] +  ($row['reduction'] *$tax_rate) / 100;
                } else {
                    $row['real_value'] = $row['reduction'] * 100;
                }
            }
            $row['nextQuantity'] = (isset($specific_prices[$key + 1]) ? (int)$specific_prices[$key + 1]['from_quantity'] : - 1);
        }
        return $specific_prices;
    }

to smarty array and then you will be able to show specific prices table (quantity discount table) on list of products

 

module that does it already exists it is available here:
https://www.prestashop.com/forums/topic/557285-module-quantity-discounts-on-products-list-categories-featured-products-etc-prestashop-17-16

 

 

  • Thanks 1
Link to comment
Share on other sites

  • 5 months later...
On 14/04/2018 at 12:51 AM, vekia said:

prestashop does not have a feature to build such "quantity discount" table on category pages,
if you want it: it requires major "background" core code that will pass the 'quantity discounts' for each product + template file (modification or own .tpl file) that will show it on list of products (product-list.tpl). 

simply saying, you need to assign results (for each product) of "formatQuantityDiscounts" function:


    protected function formatQuantityDiscounts($specific_prices, $price, $tax_rate, $ecotax_amount)
    {
        $customerGroupDiscountPercent = 1 - ((float)Group::getReduction((int)$this->context->customer->id) / 100);
        $displayPriceMethod = (int)Group::getPriceDisplayMethodByGroup((int)Group::getCurrent()->id);
        foreach ($specific_prices as $key => &$row) {
            $row['quantity'] = &$row['from_quantity'];
            if ($row['price'] >= 0) {
                // The price may be directly set
                $cur_price = ($displayPriceMethod === 1 ? $row['price'] : $row['price'] * (1 + $tax_rate / 100)) + (float)$ecotax_amount;
                if ($row['reduction_type'] == 'amount') {
                    $cur_price -= ($row['reduction_tax'] ? $row['reduction'] : $row['reduction'] / (1 + $tax_rate / 100));
                    $row['reduction_with_tax'] = $row['reduction_tax'] ? $row['reduction'] : $row['reduction'] / (1 + $tax_rate / 100);
                } else {
                    $cur_price *= 1 - $row['reduction'];
                }
                /** Apply the group reduction */
                $cur_price *= $customerGroupDiscountPercent;
                $row['real_value'] = $row['base_price'] > 0 ? $row['base_price'] - $cur_price : $cur_price;
            } else {
                if ($row['reduction_type'] == 'amount') {
					if (Product::$_taxCalculationMethod == PS_TAX_INC) {
						$row['real_value'] = $row['reduction_tax'] == 1 ? $row['reduction'] : $row['reduction'] * (1 + $tax_rate / 100);
					} else {
						$row['real_value'] = $row['reduction_tax'] == 0 ? $row['reduction'] : $row['reduction'] / (1 + $tax_rate / 100);
					}
                    $row['reduction_with_tax'] = $row['reduction_tax'] ? $row['reduction'] : $row['reduction'] +  ($row['reduction'] *$tax_rate) / 100;
                } else {
                    $row['real_value'] = $row['reduction'] * 100;
                }
            }
            $row['nextQuantity'] = (isset($specific_prices[$key + 1]) ? (int)$specific_prices[$key + 1]['from_quantity'] : - 1);
        }
        return $specific_prices;
    }

to smarty array and then you will be able to show specific prices table (quantity discount table) on list of products

 

module that does it already exists it is available here:
https://www.prestashop.com/forums/topic/557285-module-quantity-discounts-on-products-list-categories-featured-products-etc-prestashop-17-16

 

 

 

I'm a bit confused by this one to be honest, where is this code supposed to go?

Link to comment
Share on other sites

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...