Пример #1
0
 /**
  * If the row total + tax does not equal the row_total_incl_tax, we know that we 
  * can use the row_total_incl_tax field to get the rewards catalog discount amount total.
  * @deprecated getAccumulatedDiscounts uses the data stored in the Order that is much more accurate instead.
  * @param TBT_Rewards_Model_Sales_Order $order
  */
 protected function _getDiscountsByRowTotalInclTax($order)
 {
     $items = $order->getAllItems();
     $acc_diff = 0;
     $acc_diff_base = 0;
     if (!is_array($items)) {
         $items = array($items);
     }
     foreach ($items as $item) {
         if (!$item->getOrderId() || !$item->getId()) {
             continue;
         }
         //@nelkaake -a 17/02/11: If the row total + tax does not equal the row_total_incl_tax, we know that we
         // can use the row_total_incl_tax field to get the rewards catalog discount amount total.
         if ($item->getRowTotalInclTax() == $item->getTaxAmount() + $item->getRowTotal()) {
             // row total plus tax and row total including tax are the same so we can't use this field
             // to get the catalog redemption amount.
             continue;
         }
         $regular_row_total = $item->getRowTotalInclTax() - $item->getTaxAmount();
         $row_total = $item->getRowTotal();
         $acc_diff += $regular_row_total - $row_total;
     }
     $acc_diff = $order->getStore()->roundPrice($acc_diff);
     $acc_diff_base = Mage::helper('rewards/price')->getReversedCurrencyPrice($acc_diff);
     // @nelkaake to deal with a bug in PHP that allows negative zero amounts after rounding.
     if ($acc_diff == -0) {
         $acc_diff = 0;
     }
     if ($acc_diff_base == -0) {
         $acc_diff_base = 0;
     }
     return array($acc_diff, $acc_diff_base);
 }
Пример #2
0
 /**
  * 
  * @param TBT_Rewards_Model_Observer_Sales_Carttransfers $cart_transfers
  * @param TBT_Rewards_Model_Sales_Order $order
  * @throws Mage_Core_Exception
  */
 protected function _processCartRedemptionRules($cart_transfers, $order)
 {
     foreach ($cart_transfers->getRedemptionRuleIds() as $rule_id) {
         $points = null;
         // Get the points amount
         try {
             $points = $this->_getRewardsSession()->calculateCartPoints($rule_id, $order->getAllItems(), true);
         } catch (Exception $e) {
             die($e->getMessage());
         }
         // If no point samount was retrieved, continue on to the next redemption
         if (is_array($points)) {
             continue;
         }
         // Try to transfer points to the customer
         try {
             $is_transfer_successful = Mage::helper('rewards/transfer')->transferOrderPoints($points['amount'], $points['currency'], $order->getId(), $rule_id);
         } catch (Exception $ex) {
             throw new Mage_Core_Exception($ex->getMessage());
         }
     }
     return $this;
 }