Esempio n. 1
0
 /**
  * Return discount item qty
  *
  * @param Mage_Sales_Model_Quote_Item_Abstract $item
  * @param Mage_SalesRule_Model_Rule $rule
  * @return int
  */
 protected function _getItemQty($item, $rule)
 {
     //@nelkaake: Magento 1.3 and lower doesnt have the item->getTotalQty attribute.
     if (Mage::helper('rewards/version')->isBaseMageVersionAtLeast('1.4')) {
         $qty = $item->getTotalQty();
     } else {
         $qty = $item->getQty();
         if ($item->getParentItem()) {
             $qty *= $item->getParentItem()->getQty();
         }
     }
     return $rule->getDiscountQty() ? min($qty, $rule->getDiscountQty()) : $qty;
 }
Esempio n. 2
0
 /**
  * Return discount item qty
  *
  * @param Mage_Sales_Model_Quote_Item_Abstract $item
  * @param Mage_SalesRule_Model_Rule $rule
  * @return int
  */
 protected function _getItemQty($item, $rule)
 {
     $qty = $item->getTotalQty();
     return $rule->getDiscountQty() ? min($qty, $rule->getDiscountQty()) : $qty;
 }
Esempio n. 3
0
 public function getItemRuleQty(Mage_Sales_Model_Quote_Item_Abstract $item, Mage_SalesRule_Model_Rule $rule)
 {
     return $rule->getDiscountQty() ? min($item->getTotalQty(), $rule->getDiscountQty()) : $item->getTotalQty();
 }
Esempio n. 4
0
 /**
  * Fire a legacy event to process this rule for this item
  *
  * @param Mage_SalesRule_Model_Rule            $rule
  * @param Mage_Sales_Model_Quote_Item_Abstract $item
  * @param Mage_Sales_Model_Quote_Address       $address
  *
  * @return bool
  */
 protected function fireLegacyEvent(Mage_SalesRule_Model_Rule $rule, Mage_Sales_Model_Quote_Item_Abstract $item, Mage_Sales_Model_Quote_Address $address)
 {
     // Prepare values for the event
     $quote = $address->getQuote();
     $qty = $rule->getDiscountQty() ? min($item->getTotalQty(), $rule->getDiscountQty()) : $item->getTotalQty();
     // Prepare result object
     $result = new Varien_Object(['discount_amount' => 0.0, 'base_discount_amount' => 0.0, 'applied' => false]);
     // Fire legacy event
     Mage::dispatchEvent('salesrule_validator_process', ['quote' => $quote, 'address' => $address, 'rule' => $rule, 'item' => $item, 'qty' => $qty, 'result' => $result]);
     // Save discount amounts
     $item->setDiscountAmount($item->getDiscountAmount() + $result->getData('discount_amount'));
     $item->setBaseDiscountAmount($item->getBaseDiscountAmount() + $result->getData('base_discount_amount'));
     // brain-dead check to see if a rule was applied
     return $result->getData('applied') || $result->getData('discount_amount') != 0.0;
 }