- March 2021
- February 2021
- October 2020
- June 2020
- May 2020
- October 2019
- June 2019
- September 2018
- May 2018
- December 2017
- April 2017
- June 2016
- February 2016
- November 2015
- January 2015
- August 2014
- July 2014
- May 2014
- March 2014
- February 2014
- January 2014
- November 2013
- August 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- December 2012
- November 2012
- September 2012
- June 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- September 2011
- July 2011
- June 2011
- May 2011
- March 2011
- January 2011
- October 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- September 2009
- July 2009
- June 2009
- May 2009
- March 2009
- September 2008
- April 2008
- December 2007
- June 2007
- June 2005
- September 2004
- May 2002
- October 2001
- August 2001
2011-09-14: Magento: Quantity corresponding to minimum price tier
When displaying a product summary for a product with tiered pricing, Magento shows the user how much they can save by showing the minimum price (including tax). Especially with the way the string "As low as" is translated to other languages, this can be confusing and you might want to show the quantity of the product the customer needs to buy to get it at the displayed minimum price. Unfortunately, while Magento has the getMinimalPrice method to retrieve the lowest tier price, it doesn't have a convenient function to retrieve the corresponding tier quantity.
Finding quantity corresponding to minimal price tier
I wanted to add the quantity to the pricing display in app/design/frontend/default/template/template/catalog/product/price.phtml. It's quite a horrendous file where it's tough to find stuff, but search for the string "as low as" and you'll find the right place. You would think you could retrieve the pricing tiers by calling the $this->getTierPrices method with the current product (available as $_product) as parameter. This always returns an empty array, in my experience. Instead, we have to take the roundabout way of re-retrieving the product collection and retrieving the pricing tiers for each product in it. Here's how:
<?php
//Assume sensible defaults
$tier_qty = 1;
$tier_prices = array ();
//Retrieve the product collection
$collection = Mage::getModel ('catalog/product')
->getCollection ()
->addAttributeToSelect ('*')
->addAttributeToFilter ('status', 1)
->addAttributeToFilter ('sku', $_product->getSku ())
->load ();
//Store the tier prices
foreach ($collection as $p)
{
$tier_prices = array_merge ($tier_prices, $this->getTierPrices ($p));
}
if (count ($tier_prices))
{
//Find the one that matches the minimal price
$ref = floatval ($_minimalPriceValue);
foreach ($tier_prices as $p)
{
//Floating point comparison -- use epsilon of 1 hundredth of a cent
if (abs ($p ['price'] - $ref) < 0.0001)
{
//Found it, so stop looking
$tier_qty = $p ['price_qty'];
break;
}
}
}
//use $tier_qty as you see fit
?>
Comments
I suggest another way that extends default Magento Tier Price function by allowing admins to define tier prices as a percentage.
That is using a Magento extension called Percentage Tier Price, you can check it out: https://goo.gl/brXSLX
Post a comment