/** * get max points can used to spend for a quote * * @param Varien_Object $rule * @param Mage_Sales_Model_Quote $quote * @return int */ public function getRuleMaxPointsForQuote($rule, $quote) { $cacheKey = "rule_max_points_for_quote:{$rule->getId()}"; if ($this->hasCache($cacheKey)) { return $this->getCache($cacheKey); } if ($rule->getId() == 'rate') { if ($rule->getBaseRate() && $rule->getPointsSpended()) { $quoteTotal = $this->getQuoteBaseTotal($quote); //Hai.Tran 13/11/2013 add limit spend theo quote total //Tinh max point cho max total $maxPrice = $rule->getMaxPriceSpendedValue() > 0 ? $rule->getMaxPriceSpendedValue() : 0; if ($rule->getMaxPriceSpendedType() == 'by_price') { $maxPriceSpend = $maxPrice; } elseif ($rule->getMaxPriceSpendedType() == 'by_percent') { $maxPriceSpend = $quoteTotal * $maxPrice / 100; } else { $maxPriceSpend = 0; } if ($quoteTotal > $maxPriceSpend && $maxPriceSpend > 0) { $quoteTotal = $maxPriceSpend; } //End Hai.Tran 13/11/2013 add limit spend theo quote total $maxPoints = ceil(($quoteTotal - $this->getCheckedRuleDiscount()) / $rule->getBaseRate()) * $rule->getPointsSpended(); if ($maxPerOrder = $this->getMaxPointsPerOrder($quote->getStoreId())) { $maxPerOrder -= $this->getPointItemSpent(); $maxPerOrder -= $this->getCheckedRulePoint(); if ($maxPerOrder > 0) { $maxPoints = min($maxPoints, $maxPerOrder); $maxPoints = floor($maxPoints / $rule->getPointsSpended()) * $rule->getPointsSpended(); } else { $maxPoints = 0; } } $this->saveCache($cacheKey, $maxPoints); } } else { $container = new Varien_Object(array('rule_max_points' => 0)); Mage::dispatchEvent('rewardpoints_calculation_spending_rule_max_points', array('rule' => $rule, 'quote' => $quote, 'container' => $container)); $this->saveCache($cacheKey, $container->getRuleMaxPoints()); } if (!$this->hasCache($cacheKey)) { $this->saveCache($cacheKey, 0); } return $this->getCache($cacheKey); }