Jump to content

Display quantity discount % in product-list


ply

Recommended Posts

so, you've got defined special price on product, right? for example - 10% value down.

Now you want to display "10%" on product page, rigth? not amount, just percentage reduction?
if so, this module can be helpful: https://mypresta.eu/modules/front-office-features/quantity-discounts-on-products-lists.html
it displays all available product quantity discounts on list of products (product-list.tpl)

  • Like 1
Link to comment
Share on other sites

try with this code:

{if $product->specificPrice AND $product->specificPrice.reduction_type == 'percentage'}{$product->specificPrice.reduction*100}%{/if}

 

 

this code shows special price percentage discount value.

Link to comment
Share on other sites

Hi there:-)

I have actually been through your code, both on the linked website and on your blog.

I actually asked a question on the blog also:-)

 

I just cant quite wrap my head around, how I modify your code to fit my scenario.

 

Got a suggestion?

Link to comment
Share on other sites

And I didn't respond to the comment? Must have forgot, sorry!

 

I would stop when retrieving the quantity dicount prices, and assigning that array directly to the product instead of only getting the lower price. In the template, I'd then copy the product.tpl quantity discount table and replace the variables

Link to comment
Share on other sites

Here is an example for 1.4, I did it some time ago

 

{if isset($product.qty_discounts) && $product.qty_discounts}
 <table class="std" style="font-size: 11px;margin-top: 3px;">
  <tr>
   <th style="text-align:left">{l s='Buy'}</th>
   {foreach from=$product.qty_discounts item=quantity_discount name=quantity_discounts}
	<th style="text-align:left">{$quantity_discount.from_quantity|intval}+
	</th>
   {/foreach}
  </tr>
  <tr>
   <td>{l s='Pay(each)'}</td>
   {foreach from=$product.qty_discounts item=quantity_discount name=quantity_discounts}
	<td>
	{if $quantity_discount.price != 0 OR $quantity_discount.reduction_type == 'amount'}
	 {convertPrice price=$quantity_discount.price}
	{else}
	 {math equation="a*b" a=$original_price b=$quantity_discount.reduction assign=reduction_amt}
	 {math equation="a-b" a=$original_price b=$reduction_amt assign=finalPrice}
	 {convertPrice price=$finalPrice}
	{/if}
	</td>
   {/foreach}
  </tr>
 </table>
{/if}

Link to comment
Share on other sites

Use the Force, Ply :D

 

 

Anyway that controller will never work. First there is an incomplete comment.

Secondly, you need to grab quantity discounts before checking if there's any :) An you need a method anyway

 

public function initContent()
{
   parent::initContent();

   if($this->cat_products) {

    $id_customer = (isset($this->context->customer) ? (int)$this->context->customer->id : 0);
    $id_group = (isset($this->context->customer) ? $this->context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_);
    $id_country = (int)$id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT');
    $id_currency = (int)$this->context->cookie->id_currency;
    $id_shop = $this->context->shop->id;

    foreach ($this->cat_products as $key => $product) {

	    $prices_array = array();

	    /* For each product, grab quantity discounts */
	    $quantity_discounts = SpecificPrice::getQuantityDiscounts($product['id_product'], $id_shop, $id_currency, $id_country, $id_group, null, true);

    }
   }
}

Link to comment
Share on other sites

Check if quantity discounts are assigned first:

			 /* Process quantity discounts to get the real price */

		    if ($quantity_discounts)
		    {
			    var_dump($quantity_discounts);

		    } // end if quantity discounts

 

Then simply assign them to the current product like $this->cat_products[$key]['quantity_discounts'] = $quantity_discounts

 

 

:)

Link to comment
Share on other sites

  • 3 months later...

My simply method:

 in classes/product.php after line 3695 add code:

$row['original_price'] = Tools::ps_round($row['price'], 2); 

In productlist.tpl i added this code:

{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}<span class="price" style="display: inline;">{if !$priceDisplay}{convertPrice price=$product.price_tax_exc}{else} {(round((($product.price_tax_exc/$product.original_price)-1)*-100, 2))} {l s=' %'} {/if}</span>{l s=' reduction'}<br />{/if}
Edited by And63 (see edit history)
Link to comment
Share on other sites

in classes/product.php it looks like this then?

 

public function getTags($id_lang)
{
if (!$this->isFullyLoaded && is_null($this->tags))
$this->tags = Tag::getProductTags($this->id);
 
if (!($this->tags && key_exists($id_lang, $this->tags)))
return '';
 
$result = '';
foreach ($this->tags[$id_lang] as $tag_name)
$result .= $tag_name.', ';
$row['original_price'] = Tools::ps_round($row['price'], 2); 
return rtrim($result, ', ');
}
 
it does not work.
 
 
Nemo, I do not know how to turn on error reporting, but it looks like it does not know there is a discount?
Link to comment
Share on other sites

 

in classes/product.php it looks like this then?

 

public function getTags($id_lang)
{
if (!$this->isFullyLoaded && is_null($this->tags))
$this->tags = Tag::getProductTags($this->id);
 
if (!($this->tags && key_exists($id_lang, $this->tags)))
return '';
 
$result = '';
foreach ($this->tags[$id_lang] as $tag_name)
$result .= $tag_name.', ';
$row['original_price'] = Tools::ps_round($row['price'], 2); 
return rtrim($result, ', ');
}
 
it does not work.
 
 
Nemo, I do not know how to turn on error reporting, but it looks like it does not know there is a discount?

 

I add my code after line look this:

$row['attribute_price'] = (float)Product::getProductAttributePrice($row['id_product_attribute']);
Edited by And63 (see edit history)
Link to comment
Share on other sites

 

in classes/product.php it looks like this then?

 

public function getTags($id_lang)
{
if (!$this->isFullyLoaded && is_null($this->tags))
$this->tags = Tag::getProductTags($this->id);
 
if (!($this->tags && key_exists($id_lang, $this->tags)))
return '';
 
$result = '';
foreach ($this->tags[$id_lang] as $tag_name)
$result .= $tag_name.', ';
$row['original_price'] = Tools::ps_round($row['price'], 2); 
return rtrim($result, ', ');
}
 
it does not work.
 
 
Nemo, I do not know how to turn on error reporting, but it looks like it does not know there is a discount?

 

 

 

You can do as suggested in my signature ;)

Link to comment
Share on other sites

You can do as suggested in my signature ;)

First of all, sorry for my english.
In my personal opinion ps_product_group_reduction_cache table is unnecessary, which will take place in the database and slows down the shop. 1.4.4.1 The modification ps I used a different method. We know what customer group is the user know what is a discount on a particular product category.
What does this mean - in Table product_group_reduction_cache have 9292 records in the database. Once we know which kind of customer, as are discounts for the category of cereal and using the data in Table group_reduction - number of records 122 - is the difference?
 
Why would benefit from a reduction in the price for the group in the category for a specific product?
Just by to give the customer a discount for the product, depending on which group the customer belongs.
 
My solution is to other than original works by collecting rebates eight months and there was no error.
 
In order to relieve my database table is empty product_group_reduction_cache has 0 records.
 
In summary:
With the cookies we know to which group the client belongs.
We know what is category discount on products.
 
Why do we, then, individual discount on a particular product? - Which belongs to a particular category, which is in turn assigned a discount for a group? - All necessary data can be found in Table group_reduction
 
If you want to see if it works my solution - welcome http://www.fortec.pl, please register on the site - without it you will not get discounts - I'm assigning them :)
Link to comment
Share on other sites

I was a bit fast then.

 

When the product has a quantity discount, it shows the price without tax.

When the product does not have a quantity discount, it shows the price with tax.

 

It looks like the varable is changing how it is telling to show or not to show taxes.

 

any idea?

Edited by Fixfinn (see edit history)
Link to comment
Share on other sites

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