Example #1
0
 /**
  * Generates an array map of cart redemption actions so that a proper point sstring can be created.
  *
  * @param TBT_Rewards_Model_Salesrule_Rule $salesrule
  * @param Mage_Checkout_Model_Cart $cart
  * @return array
  */
 public function getQuickCartRedemEntry($salesrule, $cart = null)
 {
     if ($cart == null) {
         $cart = Mage::getSingleton('rewards/session')->getQuote();
     }
     $val = array();
     $points = Mage::getSingleton('rewards/session')->calculateCartPoints($salesrule->getId(), $cart->getAllItems(), true, true);
     $val = $points;
     $val['name'] = $salesrule->getName();
     if ($salesrule->getSimpleFreeShipping()) {
         $val['action_str'] = Mage::helper('rewards')->__("Free Shipping");
     } else {
         $discount_amount = Mage::helper('rewards/transfer')->calculateCartDiscounts($salesrule->getId(), $cart->getAllItems(), null, true);
         $discount_amount = $discount_amount < 0 ? -1 * $discount_amount : $discount_amount;
         //@nelkaake Added on Wednesday May 5, 2010:
         //@nelkaake Changed on Wednesday May 5, 2010:
         if (strpos($salesrule->getSimpleAction(), "percent") !== false) {
             $percent = round($discount_amount);
             if (Mage::getSingleton('rewards/salesrule_actions')->isDeductByAmountSpentAction($salesrule->getPointsAction())) {
                 $percent = round($salesrule->getDiscountAmount());
             }
             $discount_amount_str = Mage::helper('rewards')->__('%s%%', $percent);
         } else {
             //@nelkaake Added on Sunday May 30, 2010:
             $discount_amount = Mage::app()->getStore()->convertPrice($discount_amount);
             $discount_amount = Mage::app()->getStore()->roundPrice($discount_amount);
             $discount_amount_str = Mage::app()->getStore()->formatPrice($discount_amount);
         }
         $val['action_str'] = Mage::helper('rewards')->__("%s Off", $discount_amount_str);
     }
     $points_amt = $points['amount'] < 0 ? $points['amount'] * -1 : $points['amount'];
     $val['points_cost'] = (string) Mage::getModel('rewards/points')->set($points['currency'], $points_amt);
     $val['is_coupon'] = $salesrule->getCouponCode();
     $val['is_coupon'] = !empty($val['is_coupon']);
     $val['is_dbps'] = $salesrule->getPointsAction() == 'discount_by_points_spent';
     if (Mage::helper('rewards/version')->isMageVersionAtLeast('1.4')) {
         $val['caption'] = $salesrule->getStoreLabel();
     }
     return $val;
 }