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


PHP Data::shippingPriceIncludesTax方法代码示例

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


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

示例1: collect

 /**
  * @param \Magento\Sales\Model\Quote\Address $address
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Quote\Address $address)
 {
     $store = $address->getQuote()->getStore();
     $address->setTaxAmount(0);
     $address->setBaseTaxAmount(0);
     $address->setAppliedTaxes(array());
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $custTaxClassId = $address->getQuote()->getCustomerTaxClassId();
     $taxCalculationModel = $this->_calculation;
     /* @var $taxCalculationModel \Magento\Tax\Model\Calculation */
     $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store);
     foreach ($items as $item) {
         /**
          * Child item's tax we calculate for parent
          */
         if ($item->getParentItemId()) {
             continue;
         }
         /**
          * We calculate parent tax amount as sum of children's tax amounts
          */
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 $discountBefore = $item->getDiscountAmount();
                 $baseDiscountBefore = $item->getBaseDiscountAmount();
                 $rate = $taxCalculationModel->getRate($request->setProductClassId($child->getProduct()->getTaxClassId()));
                 $child->setTaxPercent($rate);
                 $child->calcTaxAmount();
                 if ($discountBefore != $item->getDiscountAmount()) {
                     $address->setDiscountAmount($address->getDiscountAmount() + ($item->getDiscountAmount() - $discountBefore));
                     $address->setBaseDiscountAmount($address->getBaseDiscountAmount() + ($item->getBaseDiscountAmount() - $baseDiscountBefore));
                     $address->setGrandTotal($address->getGrandTotal() - ($item->getDiscountAmount() - $discountBefore));
                     $address->setBaseGrandTotal($address->getBaseGrandTotal() - ($item->getBaseDiscountAmount() - $baseDiscountBefore));
                 }
                 $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $child->getTaxAmount(), $child->getBaseTaxAmount(), $rate);
             }
             $itemTaxAmount = $item->getTaxAmount() + $item->getDiscountTaxCompensation();
             $address->setTaxAmount($address->getTaxAmount() + $itemTaxAmount);
             $itemBaseTaxAmount = $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensation();
             $address->setBaseTaxAmount($address->getBaseTaxAmount() + $itemBaseTaxAmount);
         } else {
             $discountBefore = $item->getDiscountAmount();
             $baseDiscountBefore = $item->getBaseDiscountAmount();
             $rate = $taxCalculationModel->getRate($request->setProductClassId($item->getProduct()->getTaxClassId()));
             $item->setTaxPercent($rate);
             $item->calcTaxAmount();
             if ($discountBefore != $item->getDiscountAmount()) {
                 $address->setDiscountAmount($address->getDiscountAmount() + ($item->getDiscountAmount() - $discountBefore));
                 $address->setBaseDiscountAmount($address->getBaseDiscountAmount() + ($item->getBaseDiscountAmount() - $baseDiscountBefore));
                 $address->setGrandTotal($address->getGrandTotal() - ($item->getDiscountAmount() - $discountBefore));
                 $address->setBaseGrandTotal($address->getBaseGrandTotal() - ($item->getBaseDiscountAmount() - $baseDiscountBefore));
             }
             $itemTaxAmount = $item->getTaxAmount() + $item->getDiscountTaxCompensation();
             $address->setTaxAmount($address->getTaxAmount() + $itemTaxAmount);
             $itemBaseTaxAmount = $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensation();
             $address->setBaseTaxAmount($address->getBaseTaxAmount() + $itemBaseTaxAmount);
             $applied = $taxCalculationModel->getAppliedRates($request);
             $this->_saveAppliedTaxes($address, $applied, $item->getTaxAmount(), $item->getBaseTaxAmount(), $rate);
         }
     }
     $shippingTaxClass = $this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
     $shippingTax = 0;
     $shippingBaseTax = 0;
     if ($shippingTaxClass) {
         $rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass));
         if ($rate) {
             if (!$this->_taxData->shippingPriceIncludesTax()) {
                 $shippingTax = $address->getShippingAmount() * $rate / 100;
                 $shippingBaseTax = $address->getBaseShippingAmount() * $rate / 100;
             } else {
                 $shippingTax = $address->getShippingTaxAmount();
                 $shippingBaseTax = $address->getBaseShippingTaxAmount();
             }
             $shippingTax = $this->priceCurrency->round($shippingTax);
             $shippingBaseTax = $this->priceCurrency->round($shippingBaseTax);
             $address->setTaxAmount($address->getTaxAmount() + $shippingTax);
             $address->setBaseTaxAmount($address->getBaseTaxAmount() + $shippingBaseTax);
             $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $shippingTax, $shippingBaseTax, $rate);
         }
     }
     if (!$this->_taxData->shippingPriceIncludesTax()) {
         $address->setShippingTaxAmount($shippingTax);
         $address->setBaseShippingTaxAmount($shippingBaseTax);
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getTaxAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseTaxAmount());
     return $this;
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:95,代码来源:Tax.php


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