Do you want to show tier prices in your product list or product view?
The function
The function we need to use is:
$this->getTierPrices($_product);
Code language: PHP (php)
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.
<?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 language: HTML, XML (xml)
Graeme Lawton
When trying this on 1.4.1 on the listings page I get a blank array back even when the product has tiered pricing.
quicoto
Hey Graeme,
Try to print this:
print_r($this->getTierPrices($_product));
Let’s see what it gets π
Notice i’m using the formated_price_incl_tax
Regards
Graeme Lawton
Wow quick response, thanks! To get the formatted price on 1.4.1 I think you need to use getFormattedTierPrice() as follows.
<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> ) )
On the single view this is returned (and it works fine):
<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> ) )
quicoto
Can you get including / excluding TAX with that function?
Graeme Lawton
I don’t know, I assumed the formatted_price key would display either with or without tax price depending on the back end setting.
quicoto
Oh right π
Thanks for sharing it Graeme π
Regards
Worm
Maybe i’m wrong but this code, doesn’t display ALL tier prices ? (only the lowest price)
quicoto
It should display all.
I tryied with 2 tier prices and no problem.
Regards.
Worm
Ok I’ve try this code (in the list.phtml)
<?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 */ ?>
But it’s not showing tierprice.
I’ve try this code :
print_r($this->getTierPrices($_product));
But i’ve a blank array.
when i try to use:
<?php echo $_product->getResource()->getAttribute('tier_price')->getFrontend()->getValue($_product); ?>
I’ve the the lowest price.
For information i’m under 1.4.0.1
Thanks for help !
Regards.
Worm
To use :
<?php echo $_product->getResource()->getAttribute('tier_price')->getFrontend()->getValue($_product); ?>
quicoto
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:
<?php echo $_product->getResource()->getAttribute('tier_prices')->getFrontend()->getValue($_product); ?>
I added a “s” just give it a try. My code use getTierPrices (plural).
If you find any solution please post.
Regards.
Worm
In fact i’m trying you code in list.phtml and it’s showing tierprice .
Worm
Sorry it’s NOT showing tierprice
John
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?
quicoto
Hi John,
I’m not sure… Did you tried to print this?
$this->getTierPrices($_product);
Worm
Finally i’m using the code below in my list.phtml
<?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'], ' Γ $_ppr['website_price'],2, null, "), ' β¬ par ', '<span style="text-transform:lowercase;">', $_product->getResource()->getAttribute('at_bille_conditionnement')->getFrontend()->getValue($_product),'. </span></span><br>'; } } ?>
Graeme Lawton
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.
quicoto
Would be great to know how to do it π
Regards
Graeme Lawton
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:
public function getPrices() { $prices = array( array( 'price_qty' => 1, 'price' => $this->getProduct()->getPrice() ) ); $prices = array_merge($prices, $this->getProduct()->getTierPrice()); return $prices; }
John
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
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),'. '; } } ?>
Worm
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 :
<?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>'; } } ?>
John
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
<?php /** * @category design * @package base_default * @copyright Copyright (c) 2010 Magento Inc. (<a href="http://www.magentocommerce.com" rel="nofollow ugc">http://www.magentocommerce.com</a>) * @license <a href="http://opensource.org/licenses/afl-3.0.php" rel="nofollow ugc">http://opensource.org/licenses/afl-3.0.php</a> 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; ?>
Worm
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.
VildUlv
Worm, thanks for your help.
shubh
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$
Rick
Looks like you just want to customize the output.
Have you tried to print what the tier_prices return and build your own table ?
David Manners
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.
David Manners
Sorry was being a bit of a fool. The first product in my search results did not have tiered pricing.
Rufat
Hello!
Bug is here:
app\code\core\Mage\Catalog\Block\Product\Abstract.php
You should replace function getTierPriceHtml with this:
public function getTierPriceHtml($product = null) { if (is_null($product)) { $product = $this->getProduct(); } return $this->_getPriceBlock($product->getTypeId()) ->setTemplate($this->getTierPriceTemplate()) ->setProduct($product) ->setInGrouped($product->isGrouped()) ->toHtml(); }
here was mistake: ->setInGrouped($this->getProduct()->isGrouped())
it replaced with:
->setInGrouped($product->isGrouped())
tuba
Thank you for the tutorial, however seems not working on 1.6.
Rick
I haven’t tried with the 1.6
They may have changed something.
Does it show any error?
Regards
tuba
only prints blank: array()
no errors
Rick
Just to make sure, double check the product has tier prices.
Then try:
print_r($this->getTierPrices($_product));
Regards
Enrique Piatti
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:
$_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'; }
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:
$_productCollection=$this->getLoadedProductCollection(); $_productCollection->addTierPriceData(); // this is new
Rick
Thanks for the clarification Enrique! π
Steve
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?
Rakesh Patel
for display low price only with currency and floating format.
currency($_product->getResource()->getAttribute('tier_price')->getFrontend()->getValue($_product),true,false); ?>
Thanks,
Rakesh Patel
Rick
Cheers π
Anthony
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?
Justin Snyder
Any ideas how to show the tier pricing in magento 2.0?
Rick
No idea I’m afraid. I’ve been away from Magento development for a long time.