Home > Magento Tutorials > Get Lowest Tier Price

Get Lowest Tier Price

Posted on: 18th Aug 2010 By: Robert Kent 22 Comments

A few weeks ago we were scratching our heads in confusion on how to get the lowest tier-price from magento. If you take a look at your catalog>product>view>tierprices.phtml you will see why – why does such a complicated section of code even exist?

Anyway after a few failed attempts we were contacted this morning by Christiaan who asked us this question a few weeks ago on the magento forums. We took this as a challenge and set to work this very morning sorting it out.

After a few black coffees we finally figured it out…or at least got rid of the rubbish that was concealing it. We now have a little method to bring back the lowest tier price on a magento product view page!

Here is how you do it:
1. Create a file in your product>view folder called getlowest.phtml
Copy & paste the following into it:

<?php
/**
* @E-Commercewebdesign.co.uk
*/
$_product = $this->getProduct();
$_tierPrices = $this->getTierPrices();
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);

$_weeeTaxAmount = Mage::helper('weee')->getAmountForDisplay($_product);
if (Mage::helper('weee')->typeOfDisplay($_product, array(1,2,4))) {
$_weeeTaxAttributes = Mage::helper('weee')->getProductWeeeAttributesForDisplay($_product);
}

?>
<?php if (count($_tierPrices) > 0): ?>
<?php if ($this->getInGrouped()): ?>
<?php $_tierPrices = $this->getTierPrices($_product); ?>
<?php endif; ?>
<?php Mage::helper('weee')->processTierPrices($_product, $_tierPrices); ?>
<?php $i = 0; ?>
<?php $_tierPrices = array_reverse($_tierPrices); ?>
<?php foreach ($_tierPrices as $_price): ?>
<?php if($i==0){ ?>
<p style="font-weight:bold; font-size: 1em;">After tier pricing the lowest price you can have a Cowboy Hat is...
<span style="font-size:150%; text-decoration:underline;">
<?php echo $_price['formated_price']; ?>
</span>
<p>
<?php $i++; ?>
<?php } ?>
<?php endforeach ?>
<?php endif;?>

As you can see you can edit some words above to output whatever you like around this lowest price – could be on top of an image or simply surrounded by text like above.

2. Open your themes catalog.xml and paste in the following code:

<block type="catalog/product_view" name="getlowest" as="getlowest" template="catalog/product/view/getlowest.phtml" />

3. Call this function on your product>view.phtml

<?php echo $this->getChildHtml('getlowest') ?>

There you have it! This code will output the lowest price of your tier prices dynamically – and will also not show anything if tier-prices are not activated for the product.

Thanks for visiting our magento blog at ecommerce website design – home of the (newly styled!) magneto fox. Take Care.

22 Responses to “ Get Lowest Tier Price ”

  1. Christiaan
    #1 | 18th August 2010

    Thanks Robert! You’d just put me in the right direction using this post. Have it working right now!

  2. Jason
    #2 | 23rd August 2010

    Thanks you very much for this awesome piece of code. you published on the same day that I needed it, hence my deep appreciation.

    one question: there is a function called getDisplayMinimalPrice() in app\code\core\Mage\Catalog\Block\Product\Price.php, do you have any idea what this does? does it interfere with your code at all?

    anyway, thanks for the great help.

  3. Robert Kent
    #3 | 24th August 2010

    Hi Jason,

    It wouldn’t interfere with the code I don’t think – it’s just hit and miss whether that will show on the product view page – you should give it a go though and if it works nicely I’ll add to this post for the benefit of others.

    Cheers,

    Rob

  4. Jason
    #4 | 24th August 2010

    I have actually managed to put this function into the Product class itself.

    in X:\htdocs\magento2\app\design\frontend\default\magesupport\template\catalog\product, add this function:

    public function getLowestPrice($_product)
    {
    $prices = new Mage_Bundle_Block_Catalog_Product_View();
    $_tierPrices = $prices->getTierPrices($_product);
    $count = $_product->getTierPriceCount();

    if ($count > 0):
    $i = 0;
    $_tierPrices = array_reverse($_tierPrices);

    foreach ($_tierPrices as $_price):
    if($i==0){
    return $_product->getFormatedTierPrice($_price);
    $i++;
    }
    endforeach;
    endif;
    }

    after this, you can retrieve lowest tier price anywhere by simply calling

    $_product = $this->getProduct();
    $_product->getLowestPrice($_product);

    im immature in Magento programming. it may not be the most efficient way but i found it neater to put all the logic in one place, whic can be called anywhere else.

  5. Jason
    #5 | 24th August 2010

    correction to my previous post!

    the function should be added in this file:

    app\code\core\Mage\Catalog\Model\Product.php

    just replace that in my original post plz. cheers

    Jason

  6. Chris
    #6 | 1st September 2010

    This works perfect on the product view, but what about the product listing? There the tierprice array contains only the normal single price. Any idea?

  7. Brigitte
    #7 | 3rd January 2011

    Hi Robert,

    I´m scratching my head too, in confusion on how to get the lowest price (minimal price) on my product page. But the absolut minimal price for exemple, a product have tier-price and option price too (T-shirt white cheaper as black). In the front of the price I need “as low as”. In Germany is this a “It must be” if you understand what I mean. I´m dispairing. Can you help??

  8. Alex
    #8 | 22nd March 2011

    Can this code be modified to suit my needs ?
    What i am trying to do is make some kind of new function or modify function inside price.phtml file so when a ” As low as ” price exists
    the regular price will be hidden , when there is no As low as then regular price is displayed

    thank you

  9. Mike
    #9 | 24th March 2011

    Great code but i’m after something a little simpler! I have 1.4.2.0 on the modern theme, and all i want is for the lowest tier price to replace the standard price in the grid/list pages, am i missing some option in magento config pages???? Mike :)

  10. Christian
    #10 | 3rd June 2011

    Hi,

    I have the same problem with grouped products. Can anyone tell me how I can this get worked for grouped products? I want to output the pirce of the grouped product with the lowest price. Christian

  11. Wout
    #11 | 25th August 2011

    Hi,

    At what line in the files mentioned at step 2 and 3 should the codes in step 2 and 3 be placed?

  12. Shafraz
    #12 | 1st September 2011

    Hi Wout,

    Did you find a solution to your question…?

    Please share with me too as i don’t get this to work :(

  13. Brigitte
    #13 | 1st September 2011

    Hi Robert,

    how can I add “from” in the price-box ??

  14. Brigitte
    #14 | 4th September 2011

    How to Get Lowest Tier Price in product view at magento 1.6.0?

  15. Wout
    #15 | 5th September 2011

    Hi Shafraz,

    Until now I didn’t succeed nor received any response from the e-commercewebdesign.co.uk team sofar.
    You can read any (succesfull) update here!

  16. Shafraz
    #16 | 6th September 2011

    Hi Wout,

    This worked me with following steps.

    Step 1
    save the getlowest.phtml file in app/design/frontend/yourtheme/default/template/catalog/product/view/getlowest.phtml

    Step 2
    in app/design/frontend/yourtheme/default/layout/catalog.xml find the comment “” and include the block into content area.

    <reference name="content">
    <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
    .
    .
    .
    <block type="catalog/product_view" name="getlowest" as="getlowest" template="catalog/product/view/getlowest.phtml" />
    .
    .
    </reference>
    

    Step 3
    goto app/design/frontend/yourtheme/default/template/catalog/product/view.phtml and include the following lines

    <?php echo $this->getTierPriceHtml() ?>
    <?php echo $this->getChildHtml('getlowest'); // our lowest tier price block?>
    <?php echo $this->getChildHtml('extrahint') ?>
    

    hope you can understand this and will help you.

  17. Wout
    #17 | 7th September 2011

    @Shafraz: thanks got it working in that way!

    Next question: I now both have the productprice and lowest tierprice showing up whereas I would like the lowest tierprice to be shown instead of the productprice?

    As in the image at the beginning of this article with the hat and tierprices, I still have a productprice before the tierprices.

    Any clue how to achieve this?

  18. Shafraz
    #18 | 7th September 2011

    @Wout: i guess if you comment out following line of code, you can hide the base price.

    I havn’t tried it though.

    <?php echo $this->getChildHtml('product_type_data') ?>
    

    if not worked try googling in magento forum. I am sure a working solution should be there.

  19. Paul
    #19 | 15th September 2011

    Id like to show the lowest price on the Category listing page (list.phtml). Any ideas?

  20. Jacob
    #20 | 9th November 2011

    Likewise. has anyone managed to display the lowest price on the category listing page? (list.phtml)

  21. Preston
    #21 | 11th November 2011

    I am also looking to extend this to the category listings.

  22. leiric
    #22 | 24th November 2011

    I’m kinda surprised that no-one suggested replacing this:

    <?php $i = 0; ?>
    <?php $_tierPrices = array_reverse($_tierPrices); ?>
    <?php foreach ($_tierPrices as $_price): ?>
    <?php if($i==0){ ?>
    <p style="font-weight:bold; font-size: 1em;">After tier pricing the lowest price you can have a Cowboy Hat is...
    <span style="font-size:150%; text-decoration:underline;">
    <?php echo $_price['formated_price']; ?>
    </span>
    <p>
    <?php $i++; ?>
    <?php } ?>
    <?php endforeach ?>
    

    With this:

    <?php $_lowestTier = array_pop($_tierPrices); ?>
    <p style="font-weight:bold; font-size: 1em;">After tier pricing the lowest price you can have a Cowboy Hat is...
    <span style="font-size:150%; text-decoration:underline;">
    <?php echo $_lowestTier['formated_price']; ?>
    </span>
    <p>
    

    array_pop() should do the same as reversing the array then looping through it to find only the first element by a counter variable comparison.

Post A Comment

Your comments:
Enclose code snippets within the appropriate tags: [php][/php]   [js][/js]   [xml][/xml]   [css][/css]   [html][/html]
E.g: [php]<?php echo "hello world"; ?>[/php]

Search Blog

Archives

For the record...

Views & opinions in this blog are those of the individual and do not necessarily reflect those of E-commerce Web Design or the Creare Group.