/** * 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); }
/** * Sends any order and pending messages to the display * @param TBT_Rewards_Model_Sales_Order $order */ protected function _dispatchTransferMsgs($order) { $earned_points_string = Mage::getModel('rewards/points')->set($order->getTotalEarnedPoints()); $redeemed_points_string = Mage::getModel('rewards/points')->set($order->getTotalSpentPoints()); if ($order->hasPointsEarning()) { if ($this->_getRewardsSession()->isAdminMode()) { Mage::getSingleton('core/session')->addSuccess(Mage::helper('rewards')->__('%s were approved for the order.', $earned_points_string)); } } return $this; }
/** * Fetches the order model * * @return TBT_Rewards_Model_Sales_Order */ public function getOrder() { //@nelkaake -c 14/12/10: $order = null; $parent = $this->getParentBlock(); if ($parent) { $order = $parent->getOrder(); } elseif ($this->getData('order')) { $order = $this->getData('order'); } else { return null; } if (!$order) { $order = Mage::registry('current_order'); } if (!$order instanceof TBT_Rewards_Model_Sales_Order) { $order = TBT_Rewards_Model_Sales_Order::wrap($order); } return $order; }
/** * Fetches the regular and base discount amounts due to * catalog redemption rules. * TODO: perhaps this should be moved to a helper (along with TBT_Rewards_Model_Sales_Order_Total_Abstract) but * I'm not sure which helper would be best for it. * @param TBT_Rewards_Model_Sales_Order $order */ protected function getAccumulatedDiscounts($order) { //@nelkaake -a 17/02/11: if the rewards discount amount field is not found // use the legacy code to find the discount aqmount using the row total if (!$order->getRewardsDiscountAmount()) { return 0; //$this->_getDiscountsByRowTotalInclTax($order); } $acc_diff = $order->getRewardsDiscountAmount(); // + $order->getRewardsDiscountTaxAmount(); $acc_diff = $order->getStore()->roundPrice($acc_diff); $acc_diff_base = $order->getRewardsBaseDiscountAmount(); $acc_diff_base = $order->getStore()->roundPrice($acc_diff_base); // @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); }
/** * Sends any order and pending messages to the display * @param TBT_Rewards_Model_Sales_Order $order */ protected function _processAdminPendingMsgs($order) { $earned_points_string = Mage::getModel('rewards/points')->set($order->getTotalEarnedPoints()); $redeemed_points_string = Mage::getModel('rewards/points')->set($order->getTotalSpentPoints()); if (!$this->_getRewardsSession()->isAdminMode()) { return $this; } if ($order->hasPointsEarning() && !$order->hasPointsSpending()) { $this->_dispatchSuccess(Mage::helper('rewards')->__('The customer was credited %s for the order.', $earned_points_string)); } elseif (!$order->hasPointsEarning() && $order->hasPointsSpending()) { $this->_dispatchSuccess(Mage::helper('rewards')->__('The customer was deducted %s for the order.', $redeemed_points_string)); } elseif ($order->hasPointsEarning() && $order->hasPointsSpending()) { $this->_dispatchSuccess(Mage::helper('rewards')->__('The customer was credited %s and deducted %s for the order.', $earned_points_string, $redeemed_points_string)); } else { // no points earned or spent } if ($order->isInitialTransferStatus(TBT_Rewards_Model_Transfer_Status::STATUS_PENDING_EVENT)) { $this->_dispatchSuccess(Mage::helper('rewards')->__("The customer's earned points are currently pending the completion of the order. They will be able to spend their points after order process is complete.")); } elseif ($order->isInitialTransferStatus(TBT_Rewards_Model_Transfer_Status::STATUS_PENDING_APPROVAL)) { $this->_dispatchSuccess(Mage::helper('rewards')->__("The customer's earned points are currently on hold. The customer will not be able to spend their points until an administator approves the transaction(s).")); } else { // points were likely approved, so no extra message is needed. } return $this; }
/** * * Writes rewards data from the quote model into the order model * @param TBT_Rewards_Model_Sales_Quote $quote * @param TBT_Rewards_Model_Sales_Order $order */ public function copyQuoteRewardsDataToOrder($quote, $order) { $order->setRewardsDiscountAmount($quote->getRewardsDiscountAmount()); $order->setRewardsDiscountTaxAmount($quote->getRewardsDiscountTaxAmount()); $order->setRewardsBaseDiscountAmount($quote->getRewardsBaseDiscountAmount()); $order->setRewardsBaseDiscountTaxAmount($quote->getRewardsBaseDiscountTaxAmount()); return $this; }
/** * Triggered when customer model is created * * @param TBT_Rewards_Model_Customer $customer * @return TBT_Rewards_Model_Customer_Listener */ public function onNewCustomerCreate(&$customer) { Mage::helper('rewards')->notice("Triggered customer registration listener to generate order cart points in TBT_Rewards_Model_Observer_Sales_Order_Place_After."); $this->order->prepareCartPointsTransfers(); return $this; }