Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. class Probiotic_TierPrice_Helper_Data extends Mage_Core_Helper_Abstract
  3. {
  4.     public function showTiers($item)
  5.     {
  6.         $html = '';
  7.                 $itemId = $item->getProductId();
  8.                 if($special = $item->getProduct()->getSpecialPrice()){//need to determine final price
  9.                         $price = $special;
  10.                 }
  11.                 else
  12.                 {
  13.                         $price = $item->getPrice();
  14.                 }
  15.                 $tier_prices = Mage::getModel("catalog/product")->load($itemId)->getData('tier_price');
  16.                 if (!empty($tier_prices)) {
  17.                         foreach ($tier_prices as $tier_price) {
  18.                                 // not gonna market to employee or wholesale for volume discounts any time soon
  19.                                 if ($tier_price['cust_group'] == 1 || $tier_price['all_groups'] == 1) {
  20.                                         //only show relevant tier prices
  21.                                         if ($item->getQty() < $tier_price['price_qty'] && $price > $tier_price['price'] ) {
  22.                                                 $new_qty = $tier_price['price_qty'] - $item->getQty(); //add this many to get discount
  23.                                                 $optimal_price = ($price * $tier_price['price_qty']) - ($tier_price['price_qty'] * $tier_price['price']);
  24.                                                 $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>";
  25.                                         }
  26.                                 }
  27.                         }
  28.                 }
  29.         return "<div class='cart-tierprices'>{$html}</div>";
  30.     }
  31. }