How to show Tier prices Magento

Do you want to show tier prices in your product list or product view?

The function

The function we need to use is:

Version

I’ve tested my code in a Magento 1.3 version.

Code

You should paste this close to where the main price os printed.

Please notice the formated_price_incl_tax you may change this if you’re using excluding tax.

41 comments
  • When trying this on 1.4.1 on the listings page I get a blank array back even when the product has tiered pricing.

    • Hey Graeme,

      Try to print this:

      [code]print_r($this->getTierPrices($_product));[/code]

      Let’s see what it gets πŸ˜‰

      Notice i’m using the formated_price_incl_tax

      Regards

      • Wow quick response, thanks! To get the formatted price on 1.4.1 I think you need to use getFormattedTierPrice() as follows.

        [code]
        <xmp><?php print_r($_product->getFormatedTierPrice()); ?></xmp>

        Array
        (
        [0] => Array
        (
        [price] => 1.6400
        [website_price] => 1.6400
        [price_qty] => 1
        [cust_group] => 32000
        [formated_price] => <span class="price">Β£1.64</span>
        )

        )

        [/code]

        On the single view this is returned (and it works fine):
        [code]
        <xmp><?php print_r($_product->getFormatedTierPrice()); ?></xmp>

        Array
        (
        [0] => Array
        (
        [price_id] => 3
        [website_id] => 0
        [all_groups] => 1
        [cust_group] => 32000
        [price_qty] => 3.0000
        [price] => 1.2000
        [website_price] => 1.2000
        [formated_price] => <span class="price">Β£1.20</span>
        )

        [1] => Array
        (
        [price_id] => 4
        [website_id] => 0
        [all_groups] => 1
        [cust_group] => 32000
        [price_qty] => 5.0000
        [price] => 1.0100
        [website_price] => 1.0100
        [formated_price] => <span class="price">Β£1.01</span>
        )

        )
        [/code]

      • Can you get including / excluding TAX with that function?

  • I don’t know, I assumed the formatted_price key would display either with or without tax price depending on the back end setting.

  • Maybe i’m wrong but this code, doesn’t display ALL tier prices ? (only the lowest price)

  • Ok I’ve try this code (in the list.phtml)

    [code]<?php
    /* get the data */
    $my_tier_rocks = $this->getTierPrices($_product);
    if (!empty($my_tier_rocks)){
    $my_tier_rocks = $this->getTierPrices($_product);

    // Notice you may not be using formated_price_incl_tax but other field.
    $my_tier_rocks = $my_tier_rocks[0][‘formated_price_incl_tax’];
    ?>
    <? /* let’s print the data */ ?>
    <? /* Use the HTML you want just notice the $my_tier_rocks var */ ?>
    <span class="my_tier price-including-tax">
    <span class="label"><?php echo $this->__(‘As low as:’) ?></span>
    <span class="price"><?=$my_tier_rocks?></span>
    </span>

    <? } /*end showing tier prices */ ?>[/code]

    But it’s not showing tierprice.

    I’ve try this code :
    [code] print_r($this->getTierPrices($_product));[/code]

    But i’ve a blank array.

    when i try to use:
    [code]<?php echo $_product->getResource()->getAttribute(‘tier_price’)->getFrontend()->getValue($_product); ?>[/code]

    I’ve the the lowest price.

    For information i’m under 1.4.0.1

    Thanks for help !
    Regards.

    • To use :
      [code]<?php echo $_product->getResource()->getAttribute(‘tier_price’)->getFrontend()->getValue($_product); ?> [/code]

    • Weird πŸ˜•

      If using the second code you pasted and using the $_product var returns data means $_product is not empty.

      I’m a little bit lost and don’t know what to tell you πŸ™

      If you use:

      [code]<?php echo $_product->getResource()->getAttribute(‘tier_prices’)->getFrontend()->getValue($_product); ?>[/code]

      I added a “s” just give it a try. My code use getTierPrices (plural).

      If you find any solution please post.

      Regards.

  • In fact i’m trying you code in list.phtml and it’s showing tierprice .

  • Thanks for the code but: how can I get the entire “table” of tier prices to appear per product on category pages and not just the lowest?

  • Finally i’m using the code below in my list.phtml
    [code]
    <?php
    $_productCollection1 = Mage::getModel(‘catalog/product’)->getCollection()
    ->addAttributeToSelect(‘*’)
    ->addAttributeToFilter(‘status’, 1)
    ->addAttributeToFilter(‘sku’,$this->htmlEscape($_product->getSku()))
    ->load();
    foreach ($_productCollection1 as $_product1){
    $_tierPrices= $this->getTierPrices($_product1);
    foreach ($_tierPrices as $_ppr){
    echo ‘<span style="font-size:9px;">Achetez en ‘,$_ppr[‘price_qty’], ‘ Γ  ‘, number_format($_ppr[‘website_price’],2, null, ”), ‘ € par ‘, ‘<span style="text-transform:lowercase;">’, $_product->getResource()->getAttribute(‘at_bille_conditionnement’)->getFrontend()->getValue($_product),’. </span></span><br>’;
    }
    }
    ?>
    [/code]

  • Sorry, In the end, I ended up writing a custom module to do the price display in all locations. It looks up the product and pulls all he prices in, in an isolated fashion.

    I’ll tidy it up and make it public at some point, but I’m using it all over this site to display prices and it appears to be working okay.

    • Would be great to know how to do it πŸ˜‰

      Regards

    • As I said, I’ll clean it up and publish it.

      But the basics are if you grab a copy of the product direct from the catalog/product model you can do this in a custom block:

      [code]
      public function getPrices() {

      $prices = array(
      array(
      ‘price_qty’ => 1,
      ‘price’ => $this->getProduct()->getPrice()
      )
      );

      $prices = array_merge($prices, $this->getProduct()->getTierPrice());

      return $prices;
      }
      [/code]

  • Hey guys – thanks for the quick responses.
    Below is the code I’m using, but I only get the first tier price.
    Any ideas?
    Here’s the page I’m trying to get them on
    http://softpouch.core101dev.com/pouches/closeout-pouches.html
    [code]
    getCollection()
    ->addAttributeToSelect(‘*’)
    ->addAttributeToFilter(‘status’, 1)
    ->addAttributeToFilter(‘sku’,$this->htmlEscape($_product->getSku()))
    ->load();
    foreach ($_productCollection1 as $_product1){
    $_tierPrices= $this->getTierPrices($_product1);
    foreach ($_tierPrices as $_ppr){
    echo ”,$_ppr[‘price_qty’], ‘ for ‘, number_format($_ppr[‘website_price’],2, null, ”), ‘ each ‘, ”, $_product->getResource()->getAttribute(‘at_bille_conditionnement’)->getFrontend()->getValue($_product),’. ‘;
    }
    }
    ?>[/code]

    • Sorry in my last they’re was an personal attribut !
      You must delete this :
      $_product->getResource()->getAttribute(‘at_bille_conditionnement’)->getFrontend()->getValue($_product)

      Try this :
      [code]
      <?php
      $_productCollection1 = Mage::getModel(‘catalog/product’)->getCollection()
      ->addAttributeToSelect(‘*’)
      ->addAttributeToFilter(‘status’, 1)
      ->addAttributeToFilter(‘sku’,$this->htmlEscape($_product->getSku()))
      ->load();
      foreach ($_productCollection1 as $_product1){
      $_tierPrices= $this->getTierPrices($_product1);
      foreach ($_tierPrices as $_ppr){
      echo $_ppr[‘price_qty’], ‘ for ‘, number_format($_ppr[‘website_price’],2, null, ”),’ each<br>’;
      }
      }
      ?>
      [/code]

  • Worm, thanks SO much for your help.
    One last thing please.
    I’m only getting the tiered prices table for the first product,
    all others in list are blank.
    Here is my list.phtml file
    [code]
    <?php
    /**
    * @category design
    * @package base_default
    * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
    * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
    */
    ?>
    <?php
    /**
    * Product list template
    *
    * @see Mage_Catalog_Block_Product_List
    */
    ?>
    <?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper(‘catalog/output’);
    ?>
    <?php if(!$_productCollection->count()): ?>
    <p class="note-msg"><?php echo $this->__(‘There are no products matching the selection.’) ?></p>
    <?php else: ?>
    <div class="category-products">
    <?php echo $this->getToolbarHtml() ?>
    <?php // List mode ?>
    <?php if($this->getMode()!=’grid’): ?>
    <?php $_iterator = 0; ?>
    <ol class="products-list" id="products-list">
    <?php foreach ($_productCollection as $_product): ?>
    <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
    <?php // Product Image ?>
    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, ‘small_image’), null, true) ?>" class="product-image"><img src="<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, ‘small_image’), null, true) ?>" /></a>
    <?php // Product description ?>
    <div class="product-shop" >
    <table border="1" cellpadding="0" cellspacing="0" width="100%">
    <tr valign="top">
    <td align="left">
    <div class="f-fix">
    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), ‘name’) ?></a></h2>
    <?php if($_product->getRatingSummary()): ?>
    <?php echo $this->getReviewsSummaryHtml($_product) ?>
    <?php endif; ?>
    <?php echo $this->getPriceHtml($_product, true) ?>
    <?php if($_product->isSaleable()): ?>
    <p><button type="button" title="<?php echo $this->__(‘Add to Cart’) ?>" class="button btn-cart" onclick="setLocation(‘<?php echo $this->getAddToCartUrl($_product) ?>’)"><span><span><?php echo $this->__(‘Add to Cart’) ?></span></span></button></p>
    <?php else: ?>
    <p class="availability out-of-stock"><span><?php echo $this->__(‘Out of stock’) ?></span></p>
    <?php endif; ?>
    <div class="desc std">
    <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), ‘short_description’) ?>
    <!–<a href="<?php //echo $_product->getProductUrl() ?>" title="<?php //echo $this->stripTags($_product->getName(), null, true) ?>" class="link-more"><?php //echo $this->__(‘Learn More’) ?></a>//–>
    </div>
    <!–
    <ul class="add-to-links">
    <?php //if ($this->helper(‘wishlist’)->isAllow()) : ?>
    <li><a href="<?php //echo $this->helper(‘wishlist’)->getAddUrl($_product) ?>" class="link-wishlist"><?php //echo $this->__(‘Add to Wishlist’) ?></a></li>
    <?php //endif; ?>
    <?php //if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
    <li><span class="separator">|</span> <a href="<?php //echo $_compareUrl ?>" class="link-compare"><?php //echo $this->__(‘Add to Compare’) ?></a></li>
    <?php //endif; ?>
    </ul>
    //–>
    </div>

    </td>
    <td width="50%">
    <!– tier prices //–>

    <?php //echo $this->getTierPriceHtml($_product) ?>

    <?php

    $_productCollection1 = Mage::getModel(‘catalog/product’)->getCollection()
    ->addAttributeToSelect(‘*’)
    ->addAttributeToFilter(‘status’, 1)
    ->addAttributeToFilter(‘sku’,$this->htmlEscape($_product->getSku()))
    ->load();
    foreach ($_productCollection1 as $_product1){
    $_tierPrices= $this->getTierPrices($_product1);
    foreach ($_tierPrices as $_ppr){
    echo $_ppr[‘price_qty’], ‘ for ‘, number_format($_ppr[‘website_price’],2, null, ”),’ each<br>’;
    }
    }

    ?>

    <!– /tier prices //–>

    </td>
    </tr>

    </table>
    </div>
    </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList(‘products-list’, ‘none-recursive’)</script>

    <?php else: ?>

    <?php // Grid Mode ?>

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
    <?php if ($i++%$_columnCount==0): ?>
    <ul class="products-grid">
    <?php endif ?>
    <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, ‘small_image’), null, true) ?>" class="product-image"><img src="<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, ‘small_image’), null, true) ?>" /></a>
    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), ‘name’) ?></a></h2>
    <?php if($_product->getRatingSummary()): ?>
    <?php echo $this->getReviewsSummaryHtml($_product, ‘short’) ?>
    <?php endif; ?>
    <?php echo $this->getPriceHtml($_product, true) ?>
    <div class="actions">
    <?php if($_product->isSaleable()): ?>
    <button type="button" title="<?php echo $this->__(‘Add to Cart’) ?>" class="button btn-cart" onclick="setLocation(‘<?php echo $this->getAddToCartUrl($_product) ?>’)"><span><span><?php echo $this->__(‘Add to Cart’) ?></span></span></button>
    <?php else: ?>
    <p class="availability out-of-stock"><span><?php echo $this->__(‘Out of stock’) ?></span></p>
    <?php endif; ?>
    <ul class="add-to-links">
    <?php if ($this->helper(‘wishlist’)->isAllow()) : ?>
    <li><a href="<?php echo $this->helper(‘wishlist’)->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__(‘Add to Wishlist’) ?></a></li>
    <?php endif; ?>
    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
    <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__(‘Add to Compare’) ?></a></li>
    <?php endif; ?>
    </ul>
    </div>
    </li>
    <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
    </ul>
    <?php endif ?>
    <?php endforeach ?>
    <script type="text/javascript">decorateGeneric($$(‘ul.products-grid’), [‘odd’,’even’,’first’,’last’])</script>
    <?php endif; ?>

    <div class="toolbar-bottom">
    <?php echo $this->getToolbarHtml() ?>
    </div>
    </div>
    <?php endif; ?>

    [/code]

  • Hi John,
    Are you sure they are some tierprices in your other product ? because when i’m looking the 2 last products they are no tier prices.
    An another way, in the second product (new group …) maybe it’s not a simple product.

  • hi friends

    I want to display Tier price on product list page in such a way the product are in tabular form and there quantity and price mention in front of these product………..

    Any help or idea for these here is example below

    Products Qty Price

    ABC 50 100$

    XYZ 100 50$

  • Hi,

    I am looking to show all the tier price options for a product on the search results page. I have tried getTierPrices (which returns an empty array). I have also tried loading the price model and getting it that way but that only seems to load one.

    I also tired getTierPriceHtml but that caused a fatal error: “Call to a member function isGrouped() on a non-object in”.

    Any help would be great thanks.

    • Sorry was being a bit of a fool. The first product in my search results did not have tiered pricing.

    • Hello!

      Bug is here:
      app\code\core\Mage\Catalog\Block\Product\Abstract.php

      You should replace function getTierPriceHtml with this:

      [code]
      public function getTierPriceHtml($product = null)
      {
      if (is_null($product)) {
      $product = $this-&gt;getProduct();
      }
      return $this-&gt;_getPriceBlock($product-&gt;getTypeId())
      -&gt;setTemplate($this-&gt;getTierPriceTemplate())
      -&gt;setProduct($product)
      -&gt;setInGrouped($product-&gt;isGrouped())
      -&gt;toHtml();
      }

      [/code]
      here was mistake: ->setInGrouped($this->getProduct()->isGrouped())

      it replaced with:
      ->setInGrouped($product->isGrouped())

  • Thank you for the tutorial, however seems not working on 1.6.

  • only prints blank: array()
    no errors

  • This doesn’t work in the new versions of magento, because the tier prices are not loaded in the collection when you are listing products. The solution provided by @Worm works but it’s really really inefficient, because it makes a new SQL query for every product and retrieving everything. And also is a bit confusing because he’s is using a collection for only one product and filtering by “sku” and other things, this is the correct way of doing the same:

    [code]
    $_product1 = Mage::getModel( ‘catalog/product’ )->load( $_product->getId() );
    $_tierPrices = $this->getTierPrices( $_product1 );
    foreach ($_tierPrices as $_ppr)
    {
    echo $_ppr[‘price_qty’], ‘ for ‘, number_format( $_ppr[‘website_price’], 2, null, ” ), ‘ each’;
    }
    [/code]

    But how I said, that’s really ineeficient and unnecessary.
    The best and simple solution is just executing “addTierPriceData” on the current collection before trying to read the tier prices.

    For example:
    catalog/product/list.phtml:
    [code]
    $_productCollection=$this->getLoadedProductCollection();
    $_productCollection->addTierPriceData(); // this is new
    [/code]

  • Hi Enrique,

    I tried adding $_productCollection->addTierPriceData(); // this is new after line 35.
    But it still isn’t showing.

    I only have one tier price filled in Magento 1.6.

    The problem is I only get “as low as” which basically doesn’t say much for customers viewing the page.

    How can I show more?

  • for display low price only with currency and floating format.

    Thanks,
    Rakesh Patel

  • I need a table with all the prices from the tier price and qty on top on the products page in magento 1.7.0.2.

    I am new to this and you would think a e-commerce system would make this easy. Any thoughts?

  • Any ideas how to show the tier pricing in magento 2.0?

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*