
Untitled
By: a guest on
Jul 20th, 2012 | syntax:
None | size: 1.29 KB | hits: 8 | expires: Never
<?php
class Probiotic_TierPrice_Helper_Data extends Mage_Core_Helper_Abstract
{
public function showTiers($item)
{
$html = '';
$itemId = $item->getProductId();
if($special = $item->getProduct()->getSpecialPrice()){//need to determine final price
$price = $special;
}
else
{
$price = $item->getPrice();
}
$tier_prices = Mage::getModel("catalog/product")->load($itemId)->getData('tier_price');
if (!empty($tier_prices)) {
foreach ($tier_prices as $tier_price) {
// not gonna market to employee or wholesale for volume discounts any time soon
if ($tier_price['cust_group'] == 1 || $tier_price['all_groups'] == 1) {
//only show relevant tier prices
if ($item->getQty() < $tier_price['price_qty'] && $price > $tier_price['price'] ) {
$new_qty = $tier_price['price_qty'] - $item->getQty(); //add this many to get discount
$optimal_price = ($price * $tier_price['price_qty']) - ($tier_price['price_qty'] * $tier_price['price']);
$html .= "<a href = 'add?product=" . $itemId . "&qty=" . $new_qty . "'>Add " . $new_qty . " more " . $item->getName() . " and save " . Mage::helper('checkout')->formatPrice(abs($optimal_price)) . " </a>";
}
}
}
}
return "<div class='cart-tierprices'>{$html}</div>";
}
}