Jump to content

[SOLVED] to activate $quantity_discounts in product-list.tpl


luca.lb

Recommended Posts

Hello,
I need to use a variable $quantity_discounts in product-list.tpl
actualy this variable not work in product-list.tpl, but also in product.tpl

that change should be done?



no one answers? Magento community is more prepared and available
Link to comment
Share on other sites

Hello,
I need to use a variable $quantity_discounts in product-list.tpl
actualy this variable not work in product-list.tpl, but also in product.tpl

that change should be done?

I want to see the quantity discounts when you see the products in the categories and when you do a search

Link to comment
Share on other sites

You aren't getting any responses because it is difficult to do. You need to modify every file that calls product-list.tpl (category.php, search.php, best-sales.php) and write code like this before the $smarty->display:

$quantity_discounts = array();

foreach ($products as $product)
{
   $quantity_discounts[$product['id_product']] = QuantityDiscount::getQuantityDiscounts(intval($product->id), $product->getPriceWithoutReduct());
}

$smarty->assign('quantity_discounts', $quantity_discounts);



Then inside the foreach loop in product-list.tpl, you can access the appropriate quantity discount using code like:

{foreach from=$quantity_discounts key=id_product item=quantity_discount}
   {if $product.id_product == $id_product}
       {foreach from=$quantity_discount item=$discount}
           {$quantity_discount.quantity|intval}: {if $quantity_discount.id_discount_type|intval == 1}{$quantity_discount.value|floatval}%{else}{convertPrice price=$quantity_discount.value|floatval}{/if}
       {/foreach}
   {/if}
{/foreach}



I don't have time to test this code, so you'll have to do that yourself.

Link to comment
Share on other sites

the array is empty.
I've print the array in category PHP with print_r function.




foreach ($products as $product)
{
   $quantity_discounts[$product['id_product']] = QuantityDiscount::getQuantityDiscounts(intval($product->id), $product->getPriceWithoutReduct());
}
print_r($quantity_discounts);




The result is:

Array ( )

Link to comment
Share on other sites

Now that I've got time to have a better look at the code, I see it is more difficult than that because each file uses a different variable name. In category.php, you need to use:

foreach ($cat_products as $product)
{
   $quantity_discounts[$product['id_product']] = QuantityDiscount::getQuantityDiscounts(intval($product->id), $product->getPriceWithoutReduct());
}



In search.php, you need to use:

foreach ($search['result'] as $product)
{
   $quantity_discounts[$product['id_product']] = QuantityDiscount::getQuantityDiscounts(intval($product->id), $product->getPriceWithoutReduct());
}



and in best-sales.php, you need to use:

$products = ProductSale::getBestSales(intval($cookie->id_lang), intval($p) - 1, intval($n), $orderBy, $orderWay);

foreach ($products as $product)
{
   $quantity_discounts[$product['id_product']] = QuantityDiscount::getQuantityDiscounts(intval($product->id), $product->getPriceWithoutReduct());
}



and replace the $smarty->assign with the following to save a query:

$smarty->assign(array(
   'products' => $products,
   'nbProducts' => $nbProducts));

Link to comment
Share on other sites

i've tested on category.php

$cat_products is a correct array with the product informations, but this code not work

$quantity_discounts[$product['id_product']] = QuantityDiscount::getQuantityDiscounts(intval($product->id), $product->getPriceWithoutReduct());

Link to comment
Share on other sites

You're right. I rushed that code. Now I see that category.php doesn't have a product object you can use. Try using the following instead:

$productObj = new Product($product['id_product']);
$quantity_discounts[$product->id] = QuantityDiscount::getQuantityDiscounts(intval($productObj->id), $product->getPriceWithoutReduct());

Link to comment
Share on other sites

I was hoping you'd see what I was doing and figure it out how to fix it yourself. Anyway, I noticed a couple of errors in the code I posted. Try the following instead:

$productObj = new Product($product['id_product']);
$quantity_discounts[$productObj->id] = QuantityDiscount::getQuantityDiscounts(intval($productObj->id), $productObj->getPriceWithoutReduct());

Link to comment
Share on other sites

finally working on!
the coregory.php correct code is:

foreach ($cat_products as $product)
{
$productObj = new Product($product['id_product']);
$quantity_discounts[$productObj->id] = QuantityDiscount::getQuantityDiscounts(intval($productObj->id), $productObj->getPriceWithoutReduct()); 
}

$smarty->assign('quantity_discounts', $quantity_discounts); 



in product-list.php is


          {foreach from=$quantity_discounts key=id_product item=quantity_discount}
           {if $product.id_product == $id_product}
                   {foreach from=$quantity_discount item=discount}
                   da {$discount.quantity|intval}pz : {$discount.value|floatval} € 

                   {/foreach}
           {/if}
       {/foreach}



thanks!

Link to comment
Share on other sites

  • 3 months later...

Hi,
could you please describe in more detail what should I change to show discounted price in product list?
We sell products for base price of $1.50, but we offer quantity discounts down to $1.00 . Customers are redirected from our ads to product lists, and see prices of $1.50 .
I would be very grateful if you could help me solving this.

Link to comment
Share on other sites

  • 1 month later...

I believe this would be more efficient for the smarty code:

>
{if $quantity_discounts[$product.id_product]}
           <!-- quantity discount -->
</pre>
<ul>
               {foreach from=$quantity_discounts[$product.id_product] item='quantity_discount' name='quantity_discounts'}

                       Buy {$quantity_discount.quantity|intval}+ : 
                       {if $quantity_discount.id_discount_type|intval == 1}
                           {$quantity_discount.value|floatval}%
                       {else}
                           {
                               convertPrice price=$product.price-$quantity_discount.value
                           } each
                       {/if}

               {/foreach}
</ul>
<br>           {/if



Instead of looping through every single quantity discount, you just loop through the ones for the product you are on, and only if that product has quantity discount to show. My output is different but that's up to you. This will print out something like: Buy 100+ : £1.04 each. Thanks for the php Rocky, that helped me quite a bit.

Link to comment
Share on other sites

  • 2 weeks later...
  • 10 months later...
  • 4 weeks later...
  • 2 weeks later...

Hey Rocky,

Whats the code for showing the Quantity discount in Ascending order like this:

50 Discount Price: $2.70
100 Discount Price: $1.88
250 Discount Price: $1.35
500 Discount Price: $1.20
1000 Discount Price: $1.15

I am using Presto-changeo Quantity Discounts module on PS1.4.
Thanks.

Link to comment
Share on other sites

  • 1 month later...

I am bumping this one too for prestashop 1.4.4

 

The problem is that when i add the following to the category.php

 

$smarty->assign('quantity_discounts', $quantity_discounts);

 

i get blank page. Is that in a correct format for PS v.1.4.4?

 

Help would be appreciated. I am also willing to pay 10 bucks to a person who will help me implement this.

Link to comment
Share on other sites

  • 4 months later...

Hi Rocky or anyone else who is listening...

Can you assist me is getting the array $quantity_discounts working in product-list.tpl

I have it working in product.tpl in this way:

 

{if $quantity_discounts}
{foreach from=$quantity_discounts item='quantity_discount' name='quantity_discounts'}
<p class="price"><span class="our_price_display" id="our_price_display">

{$quantity_discount.quantity|intval} or more for [spam-filter]$productPrice *(100-{$quantity_discount.real_value|floatval})/100}|convertAndFormatPrice} each


</span></p>
{/foreach}

The variable $quantity_discount.quantity and .real_value are not set.

 

Thanks, nik

Link to comment
Share on other sites

  • 3 years 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...