Jump to content

quantity discount on product-list.tpl


Recommended Posts

  • 1 month later...

someone made the work for 1.3 version, but there's some difference with 1.4 version. quantity discounts on product-list.tpl is the right way to show prices, marketing has it's rules and to have quantity discounts only on product page is just like not have them. I want to let prestashop's developers that this is ecommerce...if a customer comes on the product list from categories or search and see a single price, the buy decision is taken only on that single price, not many people click on product details. please insert quantity discount showing on product-list.tpl on next official Prestashop version, is important for ALL!!

 

 

 

Does somebody find a fix or solution to add quantity discount on product-list.tpl vor version 1.4X ?

 

On the product site I'm using tue quantity discount from tomer.

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

I've managed a quick and dirty hack to get the discounts into an array as part of the products array. I've done this with 1.4.5.1

 

The code is added to the CategoryController. Of course - you should subclass/override.

 

The code is inserted into function productListAssign

 

The code should be inserted after

 

$this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay);

 

Heres the code.

 

 

$id_customer = (isset(self::$cookie->id_customer) AND self::$cookie->id_customer) ? (int)(self::$cookie->id_customer) : 0;
$id_group = $id_customer ? (int)(Customer::getDefaultGroupId($id_customer)) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_country = (int)($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));

foreach($this->cat_products as &$cat_product){
$cat_product['quantity_discount'] = SpecificPrice::getQuantityDiscounts((int)$cat_product['id_product'], (int)Shop::getCurrentShop(), (int)self::$cookie->id_currency, $id_country, $id_group);
}

 

 

Within the product-list.tpl file, you would access the array via $product.quantity_discount within the foreach statement. You should be able to copy the code that is present in the product.tpl with few changes to make it work for the product-list

 

As I say, its quick and dirty - I'll look at improving it if theres demand for it.

Link to comment
Share on other sites

Following on from the previous post.

 

Create a new file under override/controllers named CategoryController.php. Enter the following.

 

 

<?php

/**
* Custom/Override functions for CategoryController.
*
*
* @author Damon Skelhorn - Sizzle Creative - <[email protected]>;
*
*/

class CategoryController extends CategoryControllerCore {


public function productListAssign()
{
$hookExecuted = false;
Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
if(!$hookExecuted) // The hook was not executed, standard working
{
self::$smarty->assign('categoryNameComplement', '');
$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
$this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay);


// variables used for the getQuantityDiscounts.
$id_customer = (isset(self::$cookie->id_customer) AND self::$cookie->id_customer) ? (int)(self::$cookie->id_customer) : 0;
$id_group = $id_customer ? (int)(Customer::getDefaultGroupId($id_customer)) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_country = (int)($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));

// Grab the quantity discounts for each product.
foreach($this->cat_products as &$cat_product) $cat_product['quantity_discount'] = SpecificPrice::getQuantityDiscounts((int)$cat_product['id_product'], (int)Shop::getCurrentShop(), (int)self::$cookie->id_currency, $id_country, $id_group);

}
else // Hook executed, use the override
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
self::$smarty->assign('nb_products', (int)$this->nbProducts);
}


}

?>

 

Within the product-list.tpl under your theme folder.

 

Access the discounts via $product.quantity_discount array.

 

Example

 

 

{if $product.quantity_discount}
<p>
{l s="Bulk discount starting from"} {$product.quantity_discount[0].from_quantity} {l s="units"}
</p>
{/if}

 

To see what information you can use within the array

 

<pre>{$product.quantity_discount|@print_r}</pre>

Link to comment
Share on other sites

  • 4 weeks later...

Hi there.

I needed to get quantity discounts working in product-list.tpl

 

I got the above solution to work, thank you so much.

In my setup, I used it to produce:

 

$6.50

$5.00 for 3+

 

I added the override file as suggested and added this to my product-list.tpl:

 

<!-- quantity discount display-->
{if $product.quantity_discount}
<span class="price" style="display: inline;">
<br/>
[spam-filter]$product.price *(1-{$product.quantity_discount[0].reduction|floatval})}|convertAndFormatPrice}
{l s=' for'} {$product.quantity_discount[0].from_quantity|intval}{l s='+'}
{/if}
</span><br />{/if}

 

When I did a dump of the variable using

<pre>{$product.quantity_discount|@print_r}</pre>

I got:

Array

(

[0] => Array

(

[id_specific_price] => 7

[id_product] => 10

[id_shop] => 0

[id_currency] => 0

[id_country] => 0

[id_group] => 0

[price] => 0.000000

[from_quantity] => 3

[reduction] => 0.230770

[reduction_type] => percentage

[from] => 0000-00-00 00:00:00

[to] => 0000-00-00 00:00:00

[score] => 0

)

 

)

1

Again, thanks so much.

Using PS 1.4.6

Nik

Link to comment
Share on other sites

How i can to change order in product.tpl, from less to more?

Actually is:

20 | 10 | 5

30% | 15% | 8%

 

But i want:

5 | 10 | 20

8% | 15% | 30%

 

Anybody know how i can do this?, i think maybe in some php, change order in some consult sql from data base, but i can't find the file.

thanks in advanced

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

How i can to change order in product.tpl, from less to more?

Actually is:

20 | 10 | 5

30% | 15% | 8%

 

But i want:

5 | 10 | 20

8% | 15% | 30%

 

Anybody know how i can do this?, i think maybe in some php, change order in some consult sql from data base, but i can't find the file.

thanks in advanced

Nobody know how i can change order?

Link to comment
Share on other sites

Nobody know how i can change order?

 

I think it's a case of reversing the array.

 

Try changing

foreach($this->cat_products as &$cat_product) $cat_product['quantity_discount'] = SpecificPrice::getQuantityDiscounts((int)$cat_product['id_product'], (int)Shop::getCurrentShop(), (int)self::$cookie->id_currency, $id_country, $id_group);

 

to

 

foreach($this->cat_products as &$cat_product) $cat_product['quantity_discount'] = array_reverse(SpecificPrice::getQuantityDiscounts((int)$cat_product['id_product'], (int)Shop::getCurrentShop(), (int)self::$cookie->id_currency, $id_country, $id_group),false);

 

Let me know if that works.

Link to comment
Share on other sites

Hi Damon,

 

This is great thanks, is there any way of being able to show the same information on a search results page?

 

Thanks

 

I think so,

 

You need to modify or override the Product class.

 

More specifically the getProductProperties method.

 

Before code: (Just before the end of the method)

 

self::$producPropertiesCache[$cacheKey] = $row;
return self::$producPropertiesCache[$cacheKey];

 

Add the following code

 

global $cookie, $cart;
$id_group = $cookie->id_customer ? (int)(Customer::getDefaultGroupId((int)($cookie->id_customer))) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
$id_country = (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
$row['quantity_discount'] = SpecificPrice::getQuantityDiscounts((int)$row['id_product'], (int)Shop::getCurrentShop(), (int)$cookie->id_currency, $id_country, $id_group);

 

So it looks like

 

 

global $cookie, $cart;
$id_group = $cookie->id_customer ? (int)(Customer::getDefaultGroupId((int)($cookie->id_customer))) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
$id_country = (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
$row['quantity_discount'] = SpecificPrice::getQuantityDiscounts((int)$row['id_product'], (int)Shop::getCurrentShop(), (int)$cookie->id_currency, $id_country, $id_group);

self::$producPropertiesCache[$cacheKey] = $row;
return self::$producPropertiesCache[$cacheKey];

Link to comment
Share on other sites

I think it's a case of reversing the array.

 

Try changing

foreach($this->cat_products as &$cat_product) $cat_product['quantity_discount'] = SpecificPrice::getQuantityDiscounts((int)$cat_product['id_product'], (int)Shop::getCurrentShop(), (int)self::$cookie->id_currency, $id_country, $id_group);

 

to

 

foreach($this->cat_products as &$cat_product) $cat_product['quantity_discount'] = array_reverse(SpecificPrice::getQuantityDiscounts((int)$cat_product['id_product'], (int)Shop::getCurrentShop(), (int)self::$cookie->id_currency, $id_country, $id_group),false);

 

Let me know if that works.

I'm trying to get in product.tpl also change the order, I'm seeing the class of SpecifictPrice.php but can not find where to change the order of the array, Will you know what kind I need to change?

Thanks in advance.

Link to comment
Share on other sites

It's not in any of the .tpl files, It's in the CategoryController file. See post #7 above - http://www.prestasho...post__p__721318

Yes i know, but this is for product-list.tpl and I mean to affect product.tpl page, well maybe I not explained very well, actually I'm not using the option to show the discounted product lists, I just want to reverse the order shown on the product page, something like the example images below.

 

ORIGINAL

 

qd01.jpg

 

 

THIS IS HOW I WOULD LIKE

 

qd02.jpg

Link to comment
Share on other sites

  • 3 weeks later...

Hi Damon

 

I don't understand why it doesn't work for me.

I override CategoryController.php just as you say, but for example

<pre>{$product.quantity_discount|@print_r}</pre>

return "1".

Any idea ?

 

PS: It's a 1.4.6.2 Prestashop.

Link to comment
Share on other sites

Sounds like it didn't set the array in the overriding controller. Have you tried instead of overriding applying the change directly to the CategoryController?

 

Backup the original controller and replace the productListAssign function with the one above. If that doesn't work then there must be a difference between the version you are using and the one I applied the change to.

 

 

Also, check your controller file is located in the correct place /overrides/controllers/

Link to comment
Share on other sites

Hi damondsizzle,

 

Your solution is correct if you do not have installed the module "blocklayered" because if you have installed the module "blocklayered" does not enter the "if" productListAssign() function:

 

if(!$hookExecuted) // The hook was not executed, standard working

 

 

Because before the "if" execute Hook run the module "blocklayered"

 

Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));

 

if I disable the module "blocklayered" does not work properly, as in product-list.tpl when I show:

 

<pre>{$product.quantity_discount|@print_r}</pre>

 

always print "1" why quantity_discount always exists, but not logical difference.

 

Excuse my English,

 

Marc

------

Link to comment
Share on other sites

  • 7 months later...

I've tried to implement the below, I've created a CategoryController.phpm with the code below in /override/controllers/

 

and in /themes/mytheme/product-list.tpl i put the example code in below, this shows nothing and when I call

 

<pre>{$product.quantity_discount|@print_r}</pre>

 

all that is show is "01"

 

I don't know why it's not working? I've attached the files I've uploaded

 

 

Create a new file under override/controllers named CategoryController.php. Enter the following.

 

 

<?php

 

/**

* Custom/Override functions for CategoryController.

*

*

* @author Damon Skelhorn - Sizzle Creative - <[email protected]>;

*

*/

 

class CategoryController extends CategoryControllerCore {

 

 

public function productListAssign()

{

$hookExecuted = false;

Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));

if(!$hookExecuted) // The hook was not executed, standard working

{

self::$smarty->assign('categoryNameComplement', '');

$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"

$this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay);

 

 

// variables used for the getQuantityDiscounts.

$id_customer = (isset(self::$cookie->id_customer) AND self::$cookie->id_customer) ? (int)(self::$cookie->id_customer) : 0;

$id_group = $id_customer ? (int)(Customer::getDefaultGroupId($id_customer)) : _PS_DEFAULT_CUSTOMER_GROUP_;

$id_country = (int)($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));

 

// Grab the quantity discounts for each product.

foreach($this->cat_products as &$cat_product) $cat_product['quantity_discount'] = SpecificPrice::getQuantityDiscounts((int)$cat_product['id_product'], (int)Shop::getCurrentShop(), (int)self::$cookie->id_currency, $id_country, $id_group);

 

}

else // Hook executed, use the override

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"

self::$smarty->assign('nb_products', (int)$this->nbProducts);

}

 

 

}

 

?>

 

Within the product-list.tpl under your theme folder.

 

Access the discounts via $product.quantity_discount array.

 

Example

 

 

{if $product.quantity_discount}

<p>

{l s="Bulk discount starting from"} {$product.quantity_discount[0].from_quantity} {l s="units"}

</p>

{/if}

 

To see what information you can use within the array

 

<pre>{$product.quantity_discount|@print_r}</pre>

CategoryController.php

Link to comment
Share on other sites

  • 2 months later...

Hi there.

I needed to get quantity discounts working in product-list.tpl

 

I got the above solution to work, thank you so much.

In my setup, I used it to produce:

 

$6.50

$5.00 for 3+

 

I added the override file as suggested and added this to my product-list.tpl:

 

<!-- quantity discount display-->
{if $product.quantity_discount}
<span class="price" style="display: inline;">
<br/>
[spam-filter]$product.price *(1-{$product.quantity_discount[0].reduction|floatval})}|convertAndFormatPrice}
{l s=' for'} {$product.quantity_discount[0].from_quantity|intval}{l s='+'}
{/if}
</span><br />{/if}

 

When I did a dump of the variable using

<pre>{$product.quantity_discount|@print_r}</pre>

I got:

Array

(

[0] => Array

(

[id_specific_price] => 7

[id_product] => 10

[id_shop] => 0

[id_currency] => 0

[id_country] => 0

[id_group] => 0

[price] => 0.000000

[from_quantity] => 3

[reduction] => 0.230770

[reduction_type] => percentage

[from] => 0000-00-00 00:00:00

[to] => 0000-00-00 00:00:00

[score] => 0

)

 

)

1

Again, thanks so much.

Using PS 1.4.6

Nik

 

Hi Anatole,

 

I just not getting this right, where did you input this command?

I`m get a blank page...

Help please.

 

Thanks

 

Ricardo

Link to comment
Share on other sites

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