Thursday, May 16, 2013

Magento - Get tier price with mini price display / Tier Lowest Price Display

Magento get tier price with minimum price display


<?php
$product_tier_prices = $this->getTierPrices($_product);
if(count($product_tier_prices) > 0){
$product_tier_prices = (object)$product_tier_prices;
$product_price = array();
foreach($product_tier_prices as $key=>$value){
$value = (object)$value;
$product_price[] = $value->price;
}
echo 'As low as: '.Mage::helper('core')->currency(min($product_price),true,false);
}
?>


  Method 2

 

 

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.

 

By PHP with 4 comments

4 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/9xt8x1

Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
magento development company in bangalore 

Magento and Xero are great clouds and when they work together you can realize their true potential.
Magento to Xero Integration

Post a Comment

    • Popular
    • Categories
    • Archives