Jump to content

Show discount in percent on product_list


Recommended Posts

Hi Max,

 

probably something like this: (Put code somewhere appropriately inside the {foreach from=$products.....} block)

			{if $product.price_without_reduction neq $product.price}
				{if $product.specific_prices}
					<div class="reduction_corner">
						{assign var='pro_specific_prices' value=$product.specific_prices}
						<span class="reduction_corner_text">
							{if $pro_specific_prices.reduction_type eq 'percentage' && ($pro_specific_prices.from eq $pro_specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $pro_specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $pro_specific_prices.from))}
								-{$pro_specific_prices.reduction * 100|floatval}%
							{/if}
						</span>
						<span class="reduction_corner_price_text">
							{if $pro_specific_prices.reduction_type neq 'percentage' && ($pro_specific_prices.from eq $pro_specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $pro_specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $pro_specific_prices.from))}
								-{number_format($pro_specific_prices.reduction, 0 , ',' , ' ')},-     {* !!!PAs, no decimals and symbol in reduction amount *}
							{/if}
						</span>
					</div>
				{/if}
			{/if}

(Added for non-percentage as well, to be complete). 

 

My 2 cents,

pascal

 

(N.B. Code once made to add a funny reduction-corner in the top-left of the product, so that's where the 'corner' div/span names come from :-)  )

  • Like 2
Link to comment
Share on other sites

  • 4 months later...

Hi Max,

 

probably something like this: (Put code somewhere appropriately inside the {foreach from=$products.....} block)

			{if $product.price_without_reduction neq $product.price}
				{if $product.specific_prices}
					<div class="reduction_corner">
						{assign var='pro_specific_prices' value=$product.specific_prices}
						<span class="reduction_corner_text">
							{if $pro_specific_prices.reduction_type eq 'percentage' && ($pro_specific_prices.from eq $pro_specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $pro_specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $pro_specific_prices.from))}
								-{$pro_specific_prices.reduction * 100|floatval}%
							{/if}
						</span>
						<span class="reduction_corner_price_text">
							{if $pro_specific_prices.reduction_type neq 'percentage' && ($pro_specific_prices.from eq $pro_specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $pro_specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $pro_specific_prices.from))}
								-{number_format($pro_specific_prices.reduction, 0 , ',' , ' ')},-     {* !!!PAs, no decimals and symbol in reduction amount *}
							{/if}
						</span>
					</div>
				{/if}
			{/if}

(Added for non-percentage as well, to be complete). 

 

My 2 cents,

pascal

 

(N.B. Code once made to add a funny reduction-corner in the top-left of the product, so that's where the 'corner' div/span names come from :-)  )

This worked smoothly for me on 1.5.6.2

Thanks for sharing

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...

This code shows the difference between the full price and the discounted price, not the percentage, any ideas?

 

prestashop 1.6.1.4

 

if need show % on product_list

{if $product.specific_prices.reduction_type == 'percentage'}
<span class="price-percent-reduction">-{$product.specific_prices.reduction * 100}%</span>
{/if}
Link to comment
Share on other sites

×
×
  • Create New...