Jump to content

How to display discounted price on home page?


Recommended Posts

Hi,

 

I have a problem here. The prices of my items change according to different volumes. For example, the original price of an item is £10.  If you buy one, it is £10; if you buy 2 ~4, it is £9; if you buy 5+, it is £8.  I want to show the lowest price (£8 in this example) on home page and product list page. But I don't know which file I should edit and how to.

 

Here is my website: http://www.phonepartsdirect.co.uk/.  I am using default theme, on 1.6.1.9 version.

 

Any help will be very much appreciated.

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

Hi,

 

Can you add the price to the actual product image?

Hi, did you mean adding the discounted price (the lowest one) to the product image? If that's what you meant, then every time I adjust prices, I will have to change all the product images? No it's not a good idea.  I just want it to get the lowest price for every product and display it on home page and product list page.  I know product-list.tpl is the file to edit, but I don't how to coded it.  I want something like this website: mengtor.uk.  The prices displayed on it's homepage are the lowest ones.

Link to comment
Share on other sites

Hi,

 

I have a problem here. The prices of my items change according to different volumes. For example, the original price of an item is £10.  If you buy one, it is £10; if you buy 2 ~4, it is £9; if you buy 5+, it is £8.  I want to show the lowest price (£8 in this example) on home page and product list page. But I don't know which file I should edit and how to.

 

Here is my website: http://www.phonepartsdirect.co.uk/.  I am using default theme, on 1.6.1.9 version.

 

Any help will be very much appreciated.

 

To display on home page, you need to add in product-list.tpl file

As you want to show lowest price on home page you can call product object in product-list.tpl file

Take reference from product.tpl file and go to around 430 line.


{foreach from=$quantity_discounts item='quantity_discount' name='quantity_discounts'}
{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
{$realDiscountPrice=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
{else}
{$realDiscountPrice=$productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
{/if}
<tr id="quantityDiscount_{$quantity_discount.id_product_attribute}" class="quantityDiscount_{$quantity_discount.id_product_attribute}" data-real-discount-value="{convertPrice price = $realDiscountPrice}" data-discount-type="{$quantity_discount.reduction_type}" data-discount="{$quantity_discount.real_value|floatval}" data-discount-quantity="{$quantity_discount.quantity|intval}">
<td>
{$quantity_discount.quantity|intval}
</td>
<td>
{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
{if $display_discount_price}
{if $quantity_discount.reduction_tax == 0 && !$quantity_discount.price}
{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction_with_tax)|floatval}
{else}
{convertPrice price=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
{/if}
{else}
{convertPrice price=$quantity_discount.real_value|floatval}
{/if}
{else}
{if $display_discount_price}
{if $quantity_discount.reduction_tax == 0}
{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction_with_tax)|floatval}
{else}
{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
{/if}
{else}
{$quantity_discount.real_value|floatval}%
{/if}
{/if}
</td>
<td>
<span>{l s='Up to'}</span>
{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
{$discountPrice=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
{else}
{$discountPrice=$productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
{/if}
{$discountPrice=$discountPrice * $quantity_discount.quantity}
{$qtyProductPrice=$productPriceWithoutReduction|floatval * $quantity_discount.quantity}
{convertPrice price=$qtyProductPrice - $discountPrice}
</td>
</tr>
{/foreach}
 

You also need to get bulk discount data from ProductController file and assign $quantity_discounts to your respective template file (new products, best seller, featured etc).

$quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true, (int)$this->context->customer->id);
        foreach ($quantity_discounts as &$quantity_discount) {
            if ($quantity_discount['id_product_attribute']) {
                $combination = new Combination((int)$quantity_discount['id_product_attribute']);
                $attributes = $combination->getAttributesName((int)$this->context->language->id);
                foreach ($attributes as $attribute) {
                    $quantity_discount['attributes'] = $attribute['name'].' - ';
                }
                $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - ');
            }
            if ((int)$quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') {
                $quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency);
            }
        }

Hope this helps you a lot.

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

To display on home page, you need to add in product-list.tpl file

As you want to show lowest price on home page you can call product object in product-list.tpl file

Take reference from product.tpl file and go to around 430 line.

{foreach from=$quantity_discounts item='quantity_discount' name='quantity_discounts'}
{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
{$realDiscountPrice=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
{else}
{$realDiscountPrice=$productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
{/if}
<tr id="quantityDiscount_{$quantity_discount.id_product_attribute}" class="quantityDiscount_{$quantity_discount.id_product_attribute}" data-real-discount-value="{convertPrice price = $realDiscountPrice}" data-discount-type="{$quantity_discount.reduction_type}" data-discount="{$quantity_discount.real_value|floatval}" data-discount-quantity="{$quantity_discount.quantity|intval}">
<td>
{$quantity_discount.quantity|intval}
</td>
<td>
{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
{if $display_discount_price}
{if $quantity_discount.reduction_tax == 0 && !$quantity_discount.price}
{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction_with_tax)|floatval}
{else}
{convertPrice price=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
{/if}
{else}
{convertPrice price=$quantity_discount.real_value|floatval}
{/if}
{else}
{if $display_discount_price}
{if $quantity_discount.reduction_tax == 0}
{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction_with_tax)|floatval}
{else}
{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
{/if}
{else}
{$quantity_discount.real_value|floatval}%
{/if}
{/if}
</td>
<td>
<span>{l s='Up to'}</span>
{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
{$discountPrice=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
{else}
{$discountPrice=$productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
{/if}
{$discountPrice=$discountPrice * $quantity_discount.quantity}
{$qtyProductPrice=$productPriceWithoutReduction|floatval * $quantity_discount.quantity}
{convertPrice price=$qtyProductPrice - $discountPrice}
</td>
</tr>
{/foreach}
 

You also need to get bulk discount data from ProductController file and assign $quantity_discounts to your respective template file (new products, best seller, featured etc).

$quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true, (int)$this->context->customer->id);
        foreach ($quantity_discounts as &$quantity_discount) {
            if ($quantity_discount['id_product_attribute']) {
                $combination = new Combination((int)$quantity_discount['id_product_attribute']);
                $attributes = $combination->getAttributesName((int)$this->context->language->id);
                foreach ($attributes as $attribute) {
                    $quantity_discount['attributes'] = $attribute['name'].' - ';
                }
                $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - ');
            }
            if ((int)$quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') {
                $quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency);
            }
        }

Hope this helps you a lot.

Hi archSandy, many thanks for your help. Do I need to add bulk discount data from ProductController to product-list.tpl? Similarly, do I need to add the quantity discount project from product.tpl to other templates (new products, best sellers, etc.)?

Link to comment
Share on other sites

Hi archSandy, many thanks for your help. Do I need to add bulk discount data from ProductController to product-list.tpl? Similarly, do I need to add the quantity discount project from product.tpl to other templates (new products, best sellers, etc.)?

Yes both codes you need to add.

Then you can change display format as per your need in tpl files.

Link to comment
Share on other sites

Yes both codes you need to add.

Then you can change display format as per your need in tpl files.

Hi archSandy, many thanks. I just added both codes to product-list.tpl, unfortunately, it doesn't work. :(

After I added the codes, the home page looks like this (please see the attached picture). the source codes from productcontroller.php were just displayed on the homepage. And it has no effect on the price. Do you have any suggestions?

post-741283-0-70093500-1479944587_thumb.png

Link to comment
Share on other sites

May be you are wrong doing.

Follow these steps:

Likewise bulk price table is showing on product page you need to get that code from product.php (this code assign to tpl file) and product.tpl (assigned code will get display )

Now comes to your point, you need to show on home page so need to change blocknewproducts.php , blockbestsellers.php in their module.

 

Things are litte bit tough if you know Smarty and Php very well.

Thanks

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

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