getCart()->getQuote()->getTotals(); $tax = 0; if (isset($totalPrices['tax'])){ $tax_val = $totalPrices['tax']; $tax = $tax_val->getData('value'); } $subtotalPrice = $totalPrices['subtotal']; $order_details = $subtotalPrice->getData('value') + $tax; //$grandTotal = $totalPrices['grand_total']; //$grandTotal = $grandTotal->getData('value'); //$order_details = Mage::helper('checkout/cart')->getCart()->getSubtotal(); if (Mage::getStoreConfig('rewardpoints/default/math_method', Mage::app()->getStore()->getId()) == 1){ $cart_amount = round($order_details); } else { $cart_amount = floor($order_details); } $maxpoints = min(Mage::helper('rewardpoints/data')->convertMoneyToPoints($cart_amount), $points); //return $points; return $maxpoints; } public function apply(Mage_Sales_Model_Quote_Item_Abstract $item) { $points_apply = (int) Mage::helper('rewardpoints/event')->getCreditPoints(); $this->_quote = $quote = $item->getQuote(); $customer = $quote->getCustomer(); $customerId = $customer->getId(); $cart_count_items = Mage::helper('checkout/cart')->getSummaryCount(); if ($points_apply > 0 && $customerId != null){ $test_points = $this->checkMaxPointsToApply($points_apply); if ($points_apply > $test_points){ $points_apply = $test_points; Mage::helper('rewardpoints/event')->setCreditPoints($points_apply); } $points_apply_amount = Mage::helper('rewardpoints/data')->convertPointsToMoney($points_apply); $address = $this->_getAddress($item); if (!$this->_discount){ if ($points_apply > Mage::getModel('rewardpoints/account')->load($customerId)->getPointsCurrent()){ return false; } else { $discounts = $points_apply_amount; //$discounts = Mage::getModel('rewardpoints/account')->load($customerId)->getPointsCurrent(); } if ((Mage::getSingleton('customer/session')->getProductChecked() >= Mage::helper('checkout/cart')->getSummaryCount() && $discounts > 0) || !Mage::getSingleton('customer/session')->getProductChecked() || Mage::getSingleton('customer/session')->getProductChecked() == 0){ Mage::getSingleton('customer/session')->setProductChecked(0); //Mage::getSingleton('customer/session')->setDiscountleft($points_apply); Mage::getSingleton('customer/session')->setDiscountleft($points_apply_amount); $this->_discount = $discounts; $this->_couponCode = $points_apply; } else { $this->_discount = Mage::getSingleton('customer/session')->getDiscountleft(); $this->_couponCode =$points_apply; } } $discountAmount = 0; $baseDiscountAmount = 0; $discountAmount = min($item->getRowTotal() - $item->getDiscountAmount(), $quote->getStore()->convertPrice($this->_discount)); $baseDiscountAmount = min($item->getBaseRowTotal() - $item->getBaseDiscountAmount(), $this->_discount); Mage::getSingleton('customer/session')->setProductChecked(Mage::getSingleton('customer/session')->getProductChecked() + $item->getQty()); $quote_id = Mage::helper('checkout/cart')->getCart()->getQuote()->getId(); Mage::getSingleton('customer/session')->setDiscountleft(Mage::getSingleton('customer/session')->getDiscountleft() - $baseDiscountAmount); $discountAmount = min($discountAmount + $item->getDiscountAmount(), $item->getRowTotal()); $baseDiscountAmount = min($baseDiscountAmount + $item->getBaseDiscountAmount(), $item->getBaseRowTotal()); /* $address->setShippingDiscountAmount($discountAmount); $address->setBaseShippingDiscountAmount($baseDiscountAmount); */ /*$discountAmount = $quote->getStore()->roundPrice($discountAmount); $baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);*/ $item->setDiscountAmount($discountAmount); $item->setBaseDiscountAmount($baseDiscountAmount); /*$item->setDiscountAmount($discountAmount); $item->setBaseDiscountAmount($baseDiscountAmount); $item->setRowTotalWithDiscount($item->getRowTotal()); $item->setBaseRowTotalWithDiscount($item->getRowTotal()); */ $couponCode = explode(', ', $address->getCouponCode()); $couponCode[] = $this->_couponCode.' credit points'; $couponCode = array_unique(array_filter($couponCode)); $address->setCouponCode(implode(', ', $couponCode)); } } /** * Get current active quote instance * * @return Mage_Sales_Model_Quote */ protected function _getQuote() { return $this->_getCart()->getQuote(); } /** * Retrieve shopping cart model object * * @return Mage_Checkout_Model_Cart */ protected function _getCart() { return Mage::getSingleton('checkout/cart'); } /** * Get address object which can be used for discount calculation * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return Mage_Sales_Model_Quote_Address */ protected function _getAddress(Mage_Sales_Model_Quote_Item_Abstract $item) { if ($item instanceof Mage_Sales_Model_Quote_Address_Item) { $address = $item->getAddress(); } elseif ($item->getQuote()->isVirtual()) { $address = $item->getQuote()->getBillingAddress(); } else { $address = $item->getQuote()->getShippingAddress(); } return $address; } } ?>