当前位置: 首页>>代码示例>>PHP>>正文


PHP Mage_Sales_Model_Quote_Address::getBaseShippingDiscountAmount方法代码示例

本文整理汇总了PHP中Mage_Sales_Model_Quote_Address::getBaseShippingDiscountAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Quote_Address::getBaseShippingDiscountAmount方法的具体用法?PHP Mage_Sales_Model_Quote_Address::getBaseShippingDiscountAmount怎么用?PHP Mage_Sales_Model_Quote_Address::getBaseShippingDiscountAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mage_Sales_Model_Quote_Address的用法示例。


在下文中一共展示了Mage_Sales_Model_Quote_Address::getBaseShippingDiscountAmount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _calculateShippingTax

 /**
  * Calculate tax for shipping amount
  * 
  * @param Mage_Sales_Model_Quote_Address $address
  * @param type $taxRateRequest
  */
 protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $discount = $address->getShippingDiscountAmount();
     $baseDiscount = $address->getBaseShippingDiscountAmount();
     $address->setShippingDiscountAmount($discount + $address->getCustomerrewardAmount());
     $address->setBaseShippingDiscountAmount($baseDiscount + $address->getBaseCustomerrewardAmount());
     parent::_calculateShippingTax($address, $taxRateRequest);
     $address->setShippingDiscountAmount($discount);
     $address->setBaseShippingDiscountAmount($baseDiscount);
     return $this;
 }
开发者ID:rajarshc,项目名称:Rooja,代码行数:17,代码来源:Tax.php

示例2: _calculateShippingTax

 /**
  * Calculate tax for shipping amount
  * 
  * @param Mage_Sales_Model_Quote_Address $address
  * @param type $taxRateRequest
  */
 protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $discount = $address->getShippingDiscountAmount();
     $baseDiscount = $address->getBaseShippingDiscountAmount();
     /* hainh add this for calculating discount base on incl or excl tax price 22-04-2014 */
     if (!$this->_discountIncludeTax()) {
         $address->setShippingDiscountAmount($discount + $address->getCustomerrewardAmount());
         $address->setBaseShippingDiscountAmount($baseDiscount + $address->getBaseCustomerrewardAmount());
     }
     parent::_calculateShippingTax($address, $taxRateRequest);
     $address->setShippingDiscountAmount($discount);
     $address->setBaseShippingDiscountAmount($baseDiscount);
     return $this;
 }
开发者ID:bigtailbear14,项目名称:rosstheme,代码行数:20,代码来源:Magestore_Affiliateplus_Model_Total_Address_Tax.php

示例3: _calculateShippingTax

 /**
  * Tax caclulation for shipping price
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @param   Varien_Object $taxRateRequest
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $taxRateRequest->setProductClassId($this->_config->getShippingTaxClass($this->_store));
     $rate = $this->_calculator->getRate($taxRateRequest);
     $inclTax = $address->getIsShippingInclTax();
     $shipping = $address->getShippingTaxable();
     $baseShipping = $address->getBaseShippingTaxable();
     $rateKey = (string) $rate;
     $hiddenTax = null;
     $baseHiddenTax = null;
     switch ($this->_helper->getCalculationSequence($this->_store)) {
         case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL:
         case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
             $tax = $this->_calculator->calcTaxAmount($shipping, $rate, $inclTax, false);
             $baseTax = $this->_calculator->calcTaxAmount($baseShipping, $rate, $inclTax, false);
             break;
         case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL:
         case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL:
             $discountAmount = $address->getShippingDiscountAmount();
             $baseDiscountAmount = $address->getBaseShippingDiscountAmount();
             $tax = $this->_calculator->calcTaxAmount($shipping - $discountAmount, $rate, $inclTax, false);
             $baseTax = $this->_calculator->calcTaxAmount($baseShipping - $baseDiscountAmount, $rate, $inclTax, false);
             break;
     }
     if ($this->_config->getAlgorithm($this->_store) == Mage_Tax_Model_Calculation::CALC_TOTAL_BASE) {
         $tax = $this->_deltaRound($tax, $rate, $inclTax);
         $baseTax = $this->_deltaRound($baseTax, $rate, $inclTax, 'base');
     } else {
         $tax = $this->_calculator->round($tax);
         $baseTax = $this->_calculator->round($baseTax);
     }
     if ($inclTax && !empty($discountAmount)) {
         $hiddenTax = $this->_calculator->calcTaxAmount($discountAmount, $rate, $inclTax, false);
         $baseHiddenTax = $this->_calculator->calcTaxAmount($baseDiscountAmount, $rate, $inclTax, false);
         $this->_hiddenTaxes[] = array('rate_key' => $rateKey, 'value' => $hiddenTax, 'base_value' => $baseHiddenTax, 'incl_tax' => $inclTax);
     }
     $this->_addAmount(max(0, $tax));
     $this->_addBaseAmount(max(0, $baseTax));
     $address->setShippingTaxAmount(max(0, $tax));
     $address->setBaseShippingTaxAmount(max(0, $baseTax));
     $applied = $this->_calculator->getAppliedRates($taxRateRequest);
     $this->_saveAppliedTaxes($address, $applied, $tax, $baseTax, $rate);
     return $this;
 }
开发者ID:redesignMob,项目名称:extensii,代码行数:51,代码来源:Tax.php

示例4: applyShipping

 public function applyShipping(Mage_Sales_Model_Quote_Address $address)
 {
     $shippingAmount = $address->getShippingAmountForDiscount();
     if ($shippingAmount !== null) {
         $baseShippingAmount = $address->getBaseShippingAmountForDiscount();
     } else {
         $shippingAmount = $address->getShippingAmount();
         $baseShippingAmount = $address->getBaseShippingAmount();
     }
     $points_apply = (int) Mage::helper('rewardpoints/event')->getCreditPoints();
     $this->_quote = $quote = $address->getQuote();
     $customer = $quote->getCustomer();
     $customerId = $customer->getId();
     if ($points_apply > 0 && $customerId != null) {
         $points_apply = Mage::helper('rewardpoints/data')->convertMoneyToPoints(Mage::getSingleton('rewardpoints/session')->getDiscountleft());
         $points_apply_amount = Mage::getSingleton('rewardpoints/session')->getDiscountleft();
         if (!$this->_discount) {
             $reward_model = Mage::getModel('rewardpoints/stats');
             if ($points_apply > $reward_model->getPointsCurrent($customerId, Mage::app()->getStore()->getId())) {
                 return false;
             } else {
                 $discounts = $points_apply_amount;
             }
             if (Mage::getSingleton('rewardpoints/session')->getDiscountleft() && (!Mage::getSingleton('rewardpoints/session')->getShippingChecked() && $discounts > 0) || Mage::getSingleton('rewardpoints/session')->getProductChecked() == 0) {
                 Mage::getSingleton('rewardpoints/session')->setShippingChecked(0);
                 Mage::getSingleton('rewardpoints/session')->setDiscountleft($points_apply_amount);
                 $this->_discount = $discounts;
                 $this->_couponCode = $points_apply;
             } else {
                 $this->_discount = Mage::getSingleton('rewardpoints/session')->getDiscountleft();
                 $this->_couponCode = $points_apply;
             }
         }
         $discountAmount = 0;
         $baseDiscountAmount = 0;
         ////////////////////////////
         $discountAmount = min($shippingAmount - $address->getShippingDiscountAmount(), $quote->getStore()->convertPrice($this->_discount));
         $baseDiscountAmount = min($baseShippingAmount - $address->getBaseShippingDiscountAmount(), $this->_discount);
         //$discountAmount = Mage::helper('rewardpoints/data')->ratePointCorrection($discountAmount);
         //$baseDiscountAmount = Mage::helper('rewardpoints/data')->ratePointCorrection($baseDiscountAmount);
         Mage::getSingleton('rewardpoints/session')->setShippingChecked(1);
         $quote_id = Mage::helper('checkout/cart')->getCart()->getQuote()->getId();
         Mage::getSingleton('rewardpoints/session')->setDiscountleft(Mage::getSingleton('rewardpoints/session')->getDiscountleft() - $baseDiscountAmount);
         $discountAmount = min($discountAmount + $address->getShippingDiscountAmount(), $shippingAmount);
         $baseDiscountAmount = min($baseDiscountAmount + $address->getBaseShippingDiscountAmount(), $baseShippingAmount);
         $address->setShippingDiscountAmount($discountAmount);
         $address->setBaseShippingDiscountAmount($baseDiscountAmount);
     }
 }
开发者ID:ntnhan220488,项目名称:ggm,代码行数:49,代码来源:Discount.php

示例5: handle

 /**
  * @param Mage_Sales_Model_Quote_Address         $address
  * @param Mage_SalesRule_Model_Rule              $rule
  * @param Mage_Sales_Model_Quote_Item_Abstract[] $allItems
  * @param Mage_Sales_Model_Quote_Item_Abstract[] $validItems
  *
  * @return bool
  */
 public function handle(Mage_Sales_Model_Quote_Address $address, Mage_SalesRule_Model_Rule $rule, array $allItems, array $validItems)
 {
     // Skip invalid rule actions
     if ($rule->getSimpleAction() !== Mage_SalesRule_Model_Rule::CART_FIXED_ACTION) {
         return false;
     }
     // Skip if there are no valid items and it's not applied to shipping
     if (!count($validItems) && !$rule->getApplyToShipping()) {
         return false;
     }
     // Define a few helpful variables
     $helper = $this->getHelper();
     $quote = $address->getQuote();
     $store = $quote->getStore();
     // Total available discount amounts
     $baseDiscountAmount = $helper->round($rule->getDiscountAmount(), $quote->getBaseCurrencyCode());
     $discountAmount = $helper->round($store->convertPrice($baseDiscountAmount), $quote->getQuoteCurrencyCode());
     // Skip zero discounts
     if ($discountAmount <= 0.0) {
         return false;
     }
     $applied = false;
     // Pre-calculate the totals for all valid items
     $ruleTotalItemsPrice = 0;
     $ruleTotalBaseItemsPrice = 0;
     $itemPrices = [];
     foreach ($validItems as $item) {
         // Get max quantity (min or rule max qty or item qty)
         $qty = $helper->getItemRuleQty($item, $rule);
         // Skip zero quantity
         if ($qty <= 0.0) {
             continue;
         }
         // Get unit price
         $itemPrice = $helper->getItemPrice($item);
         $itemBasePrice = $helper->getItemBasePrice($item);
         // Get row price
         $itemRowPrice = $itemPrice * $item->getTotalQty();
         $itemBaseRowPrice = $itemBasePrice * $item->getTotalQty();
         // Get discountable price
         $itemDiscountablePrice = $itemPrice * $qty;
         $itemBaseDiscountablePrice = $itemBasePrice * $qty;
         // Save price data for later
         $itemPrices[$item->getId()] = [$itemPrice, $itemBasePrice, $itemRowPrice, $itemBaseRowPrice, $itemDiscountablePrice, $itemBaseDiscountablePrice];
         // Add row prices to running totals
         $ruleTotalItemsPrice += $itemDiscountablePrice;
         $ruleTotalBaseItemsPrice += $itemBaseDiscountablePrice;
     }
     $startDiscountAmount = $discountAmount;
     $startBaseDiscountAmount = $baseDiscountAmount;
     foreach ($validItems as $item) {
         // Skip the skipped items
         if (!isset($itemPrices[$item->getId()])) {
             continue;
         }
         // Flag indicating the rule was applied
         $applied = true;
         // Extract the pre-calculate price data
         list($itemPrice, $itemBasePrice, $itemRowPrice, $itemBaseRowPrice, $itemDiscountablePrice, $itemBaseDiscountablePrice) = $itemPrices[$item->getId()];
         // Calculate remaining row amount
         $itemRemainingRowPrice = max($itemRowPrice - $item->getDiscountAmount(), 0);
         $itemRemainingBaseRowPrice = max($itemBaseRowPrice - $item->getBaseDiscountAmount(), 0);
         // Calculate price factor
         $priceFactor = $itemDiscountablePrice / $ruleTotalItemsPrice;
         $basePriceFactor = $itemBaseDiscountablePrice / $ruleTotalBaseItemsPrice;
         // Calculate (and round) the item discount amount
         $itemDiscountAmount = $helper->round($startDiscountAmount * $priceFactor, $quote->getQuoteCurrencyCode());
         $itemBaseDiscountAmount = $helper->round($startBaseDiscountAmount * $basePriceFactor, $quote->getBaseCurrencyCode());
         // Ensure discount does not exceed the remaining discount, max item discount, or remaining row price
         $itemDiscountAmount = max(min($itemDiscountAmount, $discountAmount, $itemDiscountablePrice, $itemRemainingRowPrice), 0.0);
         $itemBaseDiscountAmount = max(min($itemBaseDiscountAmount, $baseDiscountAmount, $itemBaseDiscountablePrice, $itemRemainingBaseRowPrice), 0.0);
         // Update the item discount
         $item->setDiscountAmount($item->getDiscountAmount() + $itemDiscountAmount);
         $item->setBaseDiscountAmount($item->getBaseDiscountAmount() + $itemBaseDiscountAmount);
         // This is a bit wonky, but needed for taxes
         $item->setOriginalDiscountAmount($item->getOriginalDiscountAmount() + $itemDiscountAmount);
         $item->setBaseOriginalDiscountAmount($item->getBaseOriginalDiscountAmount() + $itemBaseDiscountAmount);
         // Subtract from the total remaining discount amount
         $discountAmount -= $itemDiscountAmount;
         $baseDiscountAmount -= $itemBaseDiscountAmount;
     }
     if ($rule->getApplyToShipping()) {
         $shippingAmount = $address->getShippingAmountForDiscount();
         $baseShippingAmount = $address->getBaseShippingAmountForDiscount();
         if ($shippingAmount === null || $baseShippingAmount === null) {
             $shippingAmount = $address->getShippingAmount();
             $baseShippingAmount = $address->getBaseShippingAmount();
         }
         $shippingAmount -= $address->getShippingDiscountAmount();
         $baseShippingAmount -= $address->getBaseShippingDiscountAmount();
         $shippingDiscountAmount = max(min($discountAmount, $shippingAmount), 0.0);
         $shippingBaseDiscountAmount = max(min($baseDiscountAmount, $baseShippingAmount), 0.0);
//.........这里部分代码省略.........
开发者ID:aoepeople,项目名称:aoe_salesrule,代码行数:101,代码来源:CartFixed.php

示例6: _calculateShippingTax

 /**
  * Calculate tax for shipping amount
  * 
  * @param Mage_Sales_Model_Quote_Address $address
  * @param type $taxRateRequest
  */
 protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $discount = $address->getShippingDiscountAmount();
     $baseDiscount = $address->getBaseShippingDiscountAmount();
     $taxRateRequest->setProductClassId($this->_config->getShippingTaxClass($this->_store));
     if ($address->getIsShippingInclTax()) {
         $address->setMagestoreDiscountTaxForShipping($this->_calculator->calcTaxAmount($address->getMagestoreDiscountForShipping(), $this->_calculator->getRate($taxRateRequest), false, false));
         $address->setMagestoreBaseDiscountTaxForShipping($this->_calculator->calcTaxAmount($address->getMagestoreBaseDiscountForShipping(), $this->_calculator->getRate($taxRateRequest), false, false));
     }
     $address->setShippingDiscountAmount($discount + $address->getMagestoreDiscountForShipping() + $address->getMagestoreDiscountTaxForShipping());
     $address->setBaseShippingDiscountAmount($baseDiscount + $address->getMagestoreBaseDiscountForShipping() + $address->getMagestoreBaseDiscountTaxForShipping());
     parent::_calculateShippingTax($address, $taxRateRequest);
     if ($address->getIsShippingInclTax() && $address->getMagestoreDiscountTaxForShipping() > 0) {
         $length = count($this->_hiddenTaxes);
         if ($this->_hiddenTaxes[$length - 1]['value'] > 0) {
             $this->_hiddenTaxes[$length - 1]['value'] = $this->_hiddenTaxes[$length - 1]['value'] - $address->getMagestoreDiscountTaxForShipping();
             $this->_hiddenTaxes[$length - 1]['base_value'] = $this->_hiddenTaxes[$length - 1]['base_value'] - $address->getMagestoreBaseDiscountTaxForShipping();
         }
         //fix 1.4
         if ($address->getShippingHiddenTaxAmount()) {
             $address->setShippingHiddenTaxAmount($address->getShippingHiddenTaxAmount() - $address->getMagestoreDiscountTaxForShipping());
             $address->setBaseShippingHiddenTaxAmount($address->getBaseShippingHiddenTaxAmount() - $address->getMagestoreBaseDiscountTaxForShipping());
         }
     }
     $address->setShippingDiscountAmount($discount);
     $address->setBaseShippingDiscountAmount($baseDiscount);
     return $this;
 }
开发者ID:kanotest15,项目名称:cbmagento,代码行数:34,代码来源:Tax.php

示例7: _addShipping

 /**
  * Adds shipping cost to request as item
  *
  * @param Mage_Sales_Model_Quote_Address $address
  * @return int
  */
 protected function _addShipping($address)
 {
     $lineNumber = $this->_getNewLineCode();
     $storeId = $address->getQuote()->getStore()->getId();
     $taxClass = Mage::helper('tax')->getShippingTaxClass($storeId);
     $shippingAmount = max(0.0, (double) $address->getBaseShippingAmount());
     if ($this->_getTaxDataHelper()->applyTaxAfterDiscount($storeId)) {
         $shippingAmount -= (double) $address->getBaseShippingDiscountAmount();
     }
     $line = $this->_getNewDocumentRequestLineObject();
     $line->setLineCode($lineNumber);
     $shippingSku = $this->_getConfigHelper()->getShippingSku($storeId);
     $line->setItemCode($shippingSku ?: self::DEFAULT_SHIPPING_ITEMS_SKU);
     $line->setItemDescription(self::DEFAULT_SHIPPING_ITEMS_DESCRIPTION);
     $line->setAvalaraGoodsAndServicesType($taxClass);
     $line->setNumberOfItems(1);
     $line->setlineAmount($shippingAmount);
     $discounted = (double) $address->getBaseShippingDiscountAmount() && $this->_getTaxDataHelper()->applyTaxAfterDiscount($storeId) ? 'true' : 'false';
     $line->setDiscounted($discounted);
     if ($this->_getTaxDataHelper()->shippingPriceIncludesTax($storeId)) {
         $line->setTaxIncluded('true');
     }
     $this->_lines[$lineNumber] = $line;
     $this->_setLinesToRequest();
     $this->_lineToLineId[$lineNumber] = $shippingSku;
     return $lineNumber;
 }
开发者ID:onepica,项目名称:avatax,代码行数:33,代码来源:Estimate.php

示例8: _calculateShippingTax

 /**
  * Tax caclulation for shipping price
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @param   Varien_Object $taxRateRequest
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $store = $address->getQuote()->getStore();
     $shippingTaxClass = $this->_config->getShippingTaxClass($store);
     $shippingAmount = $address->getShippingAmount();
     $baseShippingAmount = $address->getBaseShippingAmount();
     $shippingDiscountAmount = $address->getShippingDiscountAmount();
     $baseShippingDiscountAmount = $address->getBaseShippingDiscountAmount();
     /**
      * Subtract discount before calculate tax amount
      */
     if ($this->_config->applyTaxAfterDiscount($store)) {
         $calcAmount = $shippingAmount - $shippingDiscountAmount;
         $baseCalcAmount = $baseShippingAmount - $baseShippingDiscountAmount;
     } else {
         $calcAmount = $shippingAmount;
         $baseCalcAmount = $baseShippingAmount;
     }
     $shippingTax = 0;
     $shippingBaseTax = 0;
     if ($shippingTaxClass) {
         $taxRateRequest->setProductClassId($shippingTaxClass);
         $rate = $this->_calculator->getRate($taxRateRequest);
         if ($rate) {
             if ($this->_config->shippingPriceIncludesTax($store) && $this->_areTaxRequestsSimilar) {
                 $shippingTax = $this->_calculator->calcTaxAmount($calcAmount, $rate, true, false);
                 $shippingBaseTax = $this->_calculator->calcTaxAmount($baseCalcAmount, $rate, true, false);
                 $shippingAmount -= $shippingTax;
                 $baseShippingAmount -= $shippingBaseTax;
             } else {
                 $shippingTax = $this->_calculator->calcTaxAmount($calcAmount, $rate, false, false);
                 $shippingBaseTax = $this->_calculator->calcTaxAmount($baseCalcAmount, $rate, false, false);
             }
             $rateKey = (string) $rate;
             if (isset($this->_roundingDeltas[$rateKey])) {
                 $shippingTax += $this->_roundingDeltas[$rateKey];
             }
             if (isset($this->_baseRoundingDeltas[$rateKey])) {
                 $shippingBaseTax += $this->_baseRoundingDeltas[$rateKey];
             }
             $shippingTax = $this->_calculator->round($shippingTax);
             $shippingBaseTax = $this->_calculator->round($shippingBaseTax);
             $address->setTotalAmount('shipping', $shippingAmount);
             $address->setBaseTotalAmount('shipping', $baseShippingAmount);
             /**
              * Provide additional attributes for apply discount on price include tax
              */
             if ($this->_config->discountTax($store)) {
                 $address->setShippingAmountForDiscount($shippingAmount + $shippingTax);
                 $address->setBaseShippingAmountForDiscount($baseShippingAmount + $shippingBaseTax);
             }
             $this->_addAmount($shippingTax);
             $this->_addBaseAmount($shippingBaseTax);
             $applied = $this->_calculator->getAppliedRates($taxRateRequest);
             $this->_saveAppliedTaxes($address, $applied, $shippingTax, $shippingBaseTax, $rate);
         }
     }
     $address->setShippingTaxAmount($shippingTax);
     $address->setBaseShippingTaxAmount($shippingBaseTax);
     return $this;
 }
开发者ID:hunnybohara,项目名称:magento-chinese-localization,代码行数:68,代码来源:Tax.php

示例9: handle

 /**
  * @param Mage_Sales_Model_Quote_Address         $address
  * @param Mage_SalesRule_Model_Rule              $rule
  * @param Mage_Sales_Model_Quote_Item_Abstract[] $allItems
  * @param Mage_Sales_Model_Quote_Item_Abstract[] $validItems
  *
  * @return bool
  */
 public function handle(Mage_Sales_Model_Quote_Address $address, Mage_SalesRule_Model_Rule $rule, array $allItems, array $validItems)
 {
     // Skip invalid rule actions
     if ($rule->getSimpleAction() !== Mage_SalesRule_Model_Rule::BY_FIXED_ACTION) {
         return false;
     }
     // Skip if there are no valid items and it's not applied to shipping
     if (!count($validItems) && !$rule->getApplyToShipping()) {
         return false;
     }
     // Define a few helpful variables
     $helper = $this->getHelper();
     $quote = $address->getQuote();
     $store = $quote->getStore();
     // Discount amount
     $baseDiscountAmount = $helper->round($rule->getDiscountAmount(), $quote->getBaseCurrencyCode());
     $discountAmount = $helper->round($store->convertPrice($baseDiscountAmount), $quote->getQuoteCurrencyCode());
     // Skip zero discounts
     if ($discountAmount <= 0.0) {
         return false;
     }
     // Get the discount step size
     $step = max(floatval($rule->getDiscountStep()), 0.0);
     $applied = false;
     foreach ($validItems as $item) {
         // Get max quantity
         $qty = $helper->getItemRuleQty($item, $rule);
         // Apply discount step size limitation
         if ($step > 0.0) {
             $qty = floor($qty / $step) * $step;
         }
         // Skip zero quantities
         if ($qty <= 0.0) {
             continue;
         }
         $applied = true;
         // Calculate discount amounts
         $discountAmount = $discountAmount * $qty;
         $baseDiscountAmount = $baseDiscountAmount * $qty;
         $originalDiscountAmount = $discountAmount * $qty;
         $baseOriginalDiscountAmount = $baseDiscountAmount * $qty;
         // Round the discount amounts
         $discountAmount = $helper->round($discountAmount, $address->getQuote()->getQuoteCurrencyCode());
         $baseDiscountAmount = $helper->round($baseDiscountAmount, $address->getQuote()->getBaseCurrencyCode());
         $originalDiscountAmount = $helper->round($originalDiscountAmount, $address->getQuote()->getQuoteCurrencyCode());
         $baseOriginalDiscountAmount = $helper->round($baseOriginalDiscountAmount, $address->getQuote()->getBaseCurrencyCode());
         // Update the item discounts
         $item->setDiscountAmount($item->getDiscountAmount() + $discountAmount);
         $item->setBaseDiscountAmount($item->getBaseDiscountAmount() + $baseDiscountAmount);
         $item->setOriginalDiscountAmount($item->getOriginalDiscountAmount() + $originalDiscountAmount);
         $item->setBaseOriginalDiscountAmount($item->getBaseOriginalDiscountAmount() + $baseOriginalDiscountAmount);
     }
     if ($rule->getApplyToShipping()) {
         $shippingAmount = $address->getShippingAmountForDiscount();
         $baseShippingAmount = $address->getBaseShippingAmountForDiscount();
         if ($shippingAmount === null || $baseShippingAmount === null) {
             $shippingAmount = $address->getShippingAmount();
             $baseShippingAmount = $address->getBaseShippingAmount();
         }
         $shippingAmount -= $address->getShippingDiscountAmount();
         $baseShippingAmount -= $address->getBaseShippingDiscountAmount();
         $shippingDiscountAmount = min(max($discountAmount, 0.0), $shippingAmount);
         $shippingBaseDiscountAmount = min(max($baseDiscountAmount, 0.0), $baseShippingAmount);
         $address->setShippingDiscountAmount($address->getShippingDiscountAmount() + $shippingDiscountAmount);
         $address->setBaseShippingDiscountAmount($address->getBaseShippingDiscountAmount() + $shippingBaseDiscountAmount);
         $applied = true;
     }
     return $applied;
 }
开发者ID:aoepeople,项目名称:aoe_salesrule,代码行数:77,代码来源:ByFixed.php

示例10: handle

 /**
  * @param Mage_Sales_Model_Quote_Address         $address
  * @param Mage_SalesRule_Model_Rule              $rule
  * @param Mage_Sales_Model_Quote_Item_Abstract[] $allItems
  * @param Mage_Sales_Model_Quote_Item_Abstract[] $validItems
  *
  * @return bool
  */
 public function handle(Mage_Sales_Model_Quote_Address $address, Mage_SalesRule_Model_Rule $rule, array $allItems, array $validItems)
 {
     // Skip invalid rule actions
     if ($rule->getSimpleAction() !== Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION) {
         return false;
     }
     // Skip if there are no valid items and it's not applied to shipping
     if (!count($validItems) && !$rule->getApplyToShipping()) {
         return false;
     }
     // Define a few helpful variables
     $helper = $this->getHelper();
     $quote = $address->getQuote();
     $store = $quote->getStore();
     // Get discount percent
     $discountPercent = max(min($rule->getDiscountAmount(), 100.0), 0.0);
     $discountMultiplier = $discountPercent / 100;
     // Skip zero discounts
     if ($discountPercent <= 0.0) {
         return false;
     }
     // Get the discount step size
     $step = max(floatval($rule->getDiscountStep()), 0.0);
     $applied = false;
     foreach ($validItems as $item) {
         // Get max quantity
         $qty = $helper->getItemRuleQty($item, $rule);
         // Apply discount step size limitation
         if ($step > 0.0) {
             $qty = floor($qty / $step) * $step;
         }
         // Skip zero quantities
         if ($qty <= 0.0) {
             continue;
         }
         $applied = true;
         // Get row prices
         $itemRowPrice = $helper->getItemPrice($item) * $qty;
         $itemBaseRowPrice = $helper->getItemBasePrice($item) * $qty;
         $itemOriginalRowPrice = $helper->getItemOriginalPrice($item) * $qty;
         $itemBaseOriginalRowPrice = $helper->getItemBaseOriginalPrice($item) * $qty;
         // Calculate discount amounts
         $discountAmount = ($itemRowPrice - $item->getDiscountAmount()) * $discountMultiplier;
         $baseDiscountAmount = ($itemBaseRowPrice - $item->getBaseDiscountAmount()) * $discountMultiplier;
         $originalDiscountAmount = ($itemOriginalRowPrice - $item->getOriginalDiscountAmount()) * $discountMultiplier;
         $baseOriginalDiscountAmount = ($itemBaseOriginalRowPrice - $item->getBaseOriginalDiscountAmount()) * $discountMultiplier;
         // Round the discount amounts
         $discountAmount = $helper->round($discountAmount, $address->getQuote()->getQuoteCurrencyCode());
         $baseDiscountAmount = $helper->round($baseDiscountAmount, $address->getQuote()->getBaseCurrencyCode());
         $originalDiscountAmount = $helper->round($originalDiscountAmount, $address->getQuote()->getQuoteCurrencyCode());
         $baseOriginalDiscountAmount = $helper->round($baseOriginalDiscountAmount, $address->getQuote()->getBaseCurrencyCode());
         // Update the item discounts
         $item->setDiscountAmount($item->getDiscountAmount() + $discountAmount);
         $item->setBaseDiscountAmount($item->getBaseDiscountAmount() + $baseDiscountAmount);
         $item->setOriginalDiscountAmount($item->getOriginalDiscountAmount() + $originalDiscountAmount);
         $item->setBaseOriginalDiscountAmount($item->getBaseOriginalDiscountAmount() + $baseOriginalDiscountAmount);
         // Update the item percent discount value
         $discountPercent = min(100, $item->getDiscountPercent() + $discountPercent);
         $item->setDiscountPercent($discountPercent);
     }
     if ($rule->getApplyToShipping()) {
         $shippingAmount = $address->getShippingAmountForDiscount();
         $baseShippingAmount = $address->getBaseShippingAmountForDiscount();
         if ($shippingAmount === null || $baseShippingAmount === null) {
             $shippingAmount = $address->getShippingAmount();
             $baseShippingAmount = $address->getBaseShippingAmount();
         }
         // Subtract existing discounts
         $shippingAmount -= $address->getShippingDiscountAmount();
         $baseShippingAmount -= $address->getBaseShippingDiscountAmount();
         // Calculate and round discounts
         $shippingDiscountAmount = $helper->round($shippingAmount * $discountMultiplier, $address->getQuote()->getQuoteCurrencyCode());
         $shippingBaseDiscountAmount = $helper->round($baseShippingAmount * $discountMultiplier, $address->getQuote()->getBaseCurrencyCode());
         // Make sure the discount isn't more that the remaining amount
         $shippingDiscountAmount = min(max($shippingDiscountAmount, 0.0), $shippingAmount);
         $shippingBaseDiscountAmount = min(max($shippingBaseDiscountAmount, 0.0), $baseShippingAmount);
         // Store discounts
         $address->setShippingDiscountAmount($address->getShippingDiscountAmount() + $shippingDiscountAmount);
         $address->setBaseShippingDiscountAmount($address->getBaseShippingDiscountAmount() + $shippingBaseDiscountAmount);
         $applied = true;
     }
     return $applied;
 }
开发者ID:aoepeople,项目名称:aoe_salesrule,代码行数:91,代码来源:ByPercent.php

示例11: _prepareDiscountCreditForAmount

 public function _prepareDiscountCreditForAmount(Mage_Sales_Model_Quote_Address $address, $rate, $baseCustomercreditForShipping)
 {
     // Update discount for each item
     $helper = Mage::helper('customercredit');
     foreach ($address->getAllItems() as $item) {
         if ($item->getParentItemId()) {
             continue;
         }
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 if (!$child->isDeleted() && $child->getProduct()->getTypeId() != 'customercredit') {
                     $baseItemPrice = $child->getBaseRowTotal() + $child->getBaseTaxAmount() - $child->getBaseDiscountAmount() - $child->getMagestoreBaseDiscount();
                     $itemBaseDiscount = $baseItemPrice * $rate;
                     $itemDiscount = Mage::app()->getStore()->convertPrice($itemBaseDiscount);
                     $child->setMagestoreBaseDiscount($child->getMagestoreBaseDiscount() + $itemBaseDiscount);
                     $child->setBaseCustomercreditDiscount($itemBaseDiscount)->setCustomercreditDiscount($itemDiscount);
                 }
             }
         } else {
             if ($item->getProduct()) {
                 if (!$item->isDeleted() && $item->getProduct()->getTypeId() != 'customercredit') {
                     $baseItemPrice = $item->getBaseRowTotal() + $item->getBaseTaxAmount() - $item->getBaseDiscountAmount() - $item->getMagestoreBaseDiscount();
                     $itemBaseDiscount = $baseItemPrice * $rate;
                     $itemDiscount = Mage::app()->getStore()->convertPrice($itemBaseDiscount);
                     $item->setMagestoreBaseDiscount($item->getMagestoreBaseDiscount() + $itemBaseDiscount);
                     $item->setBaseCustomercreditDiscount($itemBaseDiscount)->setCustomercreditDiscount($itemDiscount);
                 }
             }
         }
     }
     if ($helper->getSpendConfig('shipping') && $baseCustomercreditForShipping) {
         $baseShippingPrice = $address->getBaseShippingAmount() + $address->getBaseShippingTaxAmount() - $address->getBaseShippingDiscountAmount() - $address->getMagestoreBaseDiscountForShipping();
         $baseShippingDiscount = min($baseShippingPrice, $baseCustomercreditForShipping);
         $shippingDiscount = Mage::app()->getStore()->convertPrice($baseShippingDiscount);
         $address->setMagestoreBaseDiscountForShipping($address->getMagestoreBaseDiscountForShipping() + $baseShippingDiscount);
         $address->setBaseCustomercreditDiscountForShipping($baseShippingDiscount);
         $address->setCustomercreditDiscountForShipping($shippingDiscount);
     }
     return $this;
 }
开发者ID:javik223,项目名称:Evron-Magento,代码行数:40,代码来源:Discount.php


注:本文中的Mage_Sales_Model_Quote_Address::getBaseShippingDiscountAmount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。