示例#1
0
 /**
  * Collect address subtotal
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
  * @param Address\Total $total
  * @return $this
  */
 public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     parent::collect($quote, $shippingAssignment, $total);
     $total->setTotalQty(0);
     $baseVirtualAmount = $virtualAmount = 0;
     $address = $shippingAssignment->getShipping()->getAddress();
     /**
      * Process address items
      */
     $items = $shippingAssignment->getItems();
     foreach ($items as $item) {
         if ($this->_initItem($address, $item) && $item->getQty() > 0) {
             /**
              * Separately calculate subtotal only for virtual products
              */
             if ($item->getProduct()->isVirtual()) {
                 $virtualAmount += $item->getRowTotal();
                 $baseVirtualAmount += $item->getBaseRowTotal();
             }
         } else {
             $this->_removeItem($address, $item);
         }
     }
     $total->setBaseVirtualAmount($baseVirtualAmount);
     $total->setVirtualAmount($virtualAmount);
     /**
      * Initialize grand totals
      */
     $this->quoteValidator->validateQuoteAmount($quote, $total->getSubtotal());
     $this->quoteValidator->validateQuoteAmount($quote, $total->getBaseSubtotal());
     return $this;
 }
示例#2
0
 /**
  * Collect Weee amounts for the quote / order
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
  * @param \Magento\Quote\Model\Quote\Address\Total $total
  * @return $this
  */
 public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     AbstractTotal::collect($quote, $shippingAssignment, $total);
     $this->_store = $quote->getStore();
     if (!$this->weeeData->isEnabled($this->_store)) {
         return $this;
     }
     $address = $shippingAssignment->getShipping()->getAddress();
     $items = $shippingAssignment->getItems();
     if (!count($items)) {
         return $this;
     }
     $this->weeeTotalExclTax = 0;
     $this->weeeBaseTotalExclTax = 0;
     foreach ($items as $item) {
         if ($item->getParentItem()) {
             continue;
         }
         $this->resetItemData($item);
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 $this->resetItemData($child);
                 $this->process($address, $total, $child);
             }
             $this->recalculateParent($item);
         } else {
             $this->process($address, $total, $item);
         }
     }
     $total->setWeeeCodeToItemMap($this->weeeCodeToItemMap);
     $total->setWeeeTotalExclTax($this->weeeTotalExclTax);
     $total->setWeeeBaseTotalExclTax($this->weeeBaseTotalExclTax);
     return $this;
 }
示例#3
0
 /**
  * Collect address subtotal
  *
  * @param Address $address
  * @return $this
  */
 public function collect(Address $address)
 {
     parent::collect($address);
     $address->setTotalQty(0);
     $baseVirtualAmount = $virtualAmount = 0;
     /**
      * Process address items
      */
     $items = $this->_getAddressItems($address);
     foreach ($items as $item) {
         if ($this->_initItem($address, $item) && $item->getQty() > 0) {
             /**
              * Separately calculate subtotal only for virtual products
              */
             if ($item->getProduct()->isVirtual()) {
                 $virtualAmount += $item->getRowTotal();
                 $baseVirtualAmount += $item->getBaseRowTotal();
             }
         } else {
             $this->_removeItem($address, $item);
         }
     }
     $address->setBaseVirtualAmount($baseVirtualAmount);
     $address->setVirtualAmount($virtualAmount);
     /**
      * Initialize grand totals
      */
     $this->quoteValidator->validateQuoteAmount($address->getQuote(), $address->getSubtotal());
     $this->quoteValidator->validateQuoteAmount($address->getQuote(), $address->getBaseSubtotal());
     return $this;
 }
示例#4
0
 /**
  * Collect Weee amounts for the quote / order
  *
  * @param   \Magento\Quote\Model\Quote\Address $address
  * @return  $this
  */
 public function collect(\Magento\Quote\Model\Quote\Address $address)
 {
     AbstractTotal::collect($address);
     $this->_store = $address->getQuote()->getStore();
     if (!$this->weeeData->isEnabled($this->_store)) {
         return $this;
     }
     $items = $this->_getAddressItems($address);
     if (!count($items)) {
         return $this;
     }
     $this->weeeTotalExclTax = 0;
     $this->weeeBaseTotalExclTax = 0;
     foreach ($items as $item) {
         if ($item->getParentItemId()) {
             continue;
         }
         $this->_resetItemData($item);
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 $this->_resetItemData($child);
                 $this->_process($address, $child);
             }
             $this->_recalculateParent($item);
         } else {
             $this->_process($address, $item);
         }
     }
     $address->setWeeeCodeToItemMap($this->weeeCodeToItemMap);
     $address->setWeeeTotalExclTax($this->weeeTotalExclTax);
     $address->setWeeeBaseTotalExclTax($this->weeeBaseTotalExclTax);
     return $this;
 }
 /**
  * Collect address discount amount
  *
  * @param \Magento\Quote\Model\Quote                          $quote
  * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
  * @param \Magento\Quote\Model\Quote\Address\Total            $total
  *
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     $address = $shippingAssignment->getShipping()->getAddress();
     if ($this->_getDiscountCondition($address, $shippingAssignment)) {
         parent::collect($quote, $shippingAssignment, $total);
         $balance = $this->_getDiscountAmount();
         $address->setDiscountCouponAmount($balance);
         $address->setBaseDiscountCouponAmount($balance);
         $total->setDiscountCouponDescription($this->getCode());
         $total->setDiscountCouponAmount($balance);
         $total->setBaseDiscountCouponAmount($balance);
     }
     $total->addTotalAmount($this->getCode(), $address->getDiscountCouponAmount());
     $total->addBaseTotalAmount($this->getCode(), $address->getBaseDiscountCouponAmount());
     return $this;
 }
示例#6
0
文件: Total.php 项目: nja78/magento2
 /**
  * Collect information about MSRP price enabled
  *
  * @param  \Magento\Quote\Model\Quote\Address $address
  * @return $this
  * @api
  */
 public function collect(\Magento\Quote\Model\Quote\Address $address)
 {
     parent::collect($address);
     $items = $this->_getAddressItems($address);
     if (!count($items)) {
         return $this;
     }
     $canApplyMsrp = false;
     foreach ($items as $item) {
         if (!$item->getParentItemId() && $this->msrpData->isShowBeforeOrderConfirm($item->getProductId()) && $this->msrpData->isMinimalPriceLessMsrp($item->getProductId())) {
             $canApplyMsrp = true;
             break;
         }
     }
     $address->setCanApplyMsrp($canApplyMsrp);
     return $this;
 }
示例#7
0
 /**
  * Collect information about free shipping for all address items
  *
  * @param   \Magento\Quote\Model\Quote\Address $address
  * @return  \Magento\OfflineShipping\Model\Quote\Freeshipping
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function collect(Address $address)
 {
     parent::collect($address);
     $quote = $address->getQuote();
     $store = $this->_storeManager->getStore($quote->getStoreId());
     $address->setFreeShipping(0);
     $items = $this->_getAddressItems($address);
     if (!count($items)) {
         return $this;
     }
     $this->_calculator->init($store->getWebsiteId(), $quote->getCustomerGroupId(), $quote->getCouponCode());
     $isAllFree = true;
     foreach ($items as $item) {
         if ($item->getNoDiscount()) {
             $isAllFree = false;
             $item->setFreeShipping(false);
         } else {
             /**
              * Child item discount we calculate for parent
              */
             if ($item->getParentItemId()) {
                 continue;
             }
             $this->_calculator->processFreeShipping($item);
             $isItemFree = (bool) $item->getFreeShipping();
             $isAllFree = $isAllFree && $isItemFree;
             if ($item->getHasChildren() && $item->isChildrenCalculated()) {
                 foreach ($item->getChildren() as $child) {
                     $this->_calculator->processFreeShipping($child);
                     /**
                      * Parent free shipping we apply to all children
                      */
                     if ($isItemFree) {
                         $child->setFreeShipping($isItemFree);
                     }
                 }
             }
         }
     }
     if ($isAllFree && !$address->getFreeShipping()) {
         $address->setFreeShipping(true);
     }
     return $this;
 }
示例#8
0
 public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     parent::collect($quote, $shippingAssignment, $total);
     $writer = new \Zend\Log\Writer\Stream('D:\\testing1.log');
     $logger = new \Zend\Log\Logger();
     $logger->addWriter($writer);
     //$logger->info($this->_request->getParams());
     $sdcntVal = 0;
     //$logger->info($_SERVER['HTTP_REFERER']);
     /* if(!empty($_SERVER['HTTP_REFERER'])){
            //$logger->info(parse_url($_SERVER['HTTP_REFERER'])['query']);
            $referer = $_SERVER['HTTP_REFERER'];
            $parse_url = parse_url($referer);
            $logger->info($parse_url);
            if(array_key_exists('query',$parse_url)){
                $sdcntVal = $parse_url['query'];                
                $sdcntVal = substr($sdcntVal, 6);
                $logger->info('52 '.$sdcntVal);
            }         
        }*/
     //$this->_catalogSession->setShoppreeDiscount('25');
     $logger->info($this->_checkoutSession->getShoppreeDiscount());
     //$logger->info($_COOKIE);
     $myVal = $this->_checkoutSession->getShoppreeDiscount();
     if (!isset($myVal)) {
         $logger->info("Shoppree Discount is not set!");
     } else {
         $sdcntVal = floatval($myVal);
         $logger->info('Shoppree Discount val in collect is = ' . $sdcntVal);
     }
     $exist_amount = 0;
     //$quote->getFee();
     //$fee = -50;
     $fee = -floatval($sdcntVal);
     $balance = $fee - $exist_amount;
     $total->setTotalAmount('fee', $balance);
     $total->setBaseTotalAmount('fee', $balance);
     $total->setFee($balance);
     $total->setBaseFee($balance);
     $total->setGrandTotal($total->getGrandTotal() + $balance);
     $total->setBaseGrandTotal($total->getBaseGrandTotal() + $balance);
     return $this;
 }
示例#9
0
 public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     parent::collect($quote, $shippingAssignment, $total);
     if (!count($shippingAssignment->getItems())) {
         return $this;
     }
     $enabled = $this->helperData->isModuleEnabled();
     $minimumOrderAmount = $this->helperData->getMinimumOrderAmount();
     $subtotal = $total->getTotalAmount('subtotal');
     if ($enabled && $minimumOrderAmount <= $subtotal) {
         $fee = $quote->getFee();
         $total->setTotalAmount('fee', $fee);
         $total->setBaseTotalAmount('fee', $fee);
         $total->setFee($fee);
         $total->setBaseFee($fee);
         $quote->setFee($fee);
         $quote->setBaseFee($fee);
         $total->setGrandTotal($total->getGrandTotal() + $fee);
         $total->setBaseGrandTotal($total->getBaseGrandTotal() + $fee);
     }
     return $this;
 }
示例#10
0
 /**
  * Collect totals information about shipping
  *
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function collect(\Magento\Quote\Model\Quote\Address $address)
 {
     parent::collect($address);
     $address->setWeight(0);
     $address->setFreeMethodWeight(0);
     $this->_setAmount(0)->_setBaseAmount(0);
     $items = $this->_getAddressItems($address);
     if (!count($items)) {
         return $this;
     }
     $method = $address->getShippingMethod();
     $freeAddress = $address->getFreeShipping();
     $addressWeight = $address->getWeight();
     $freeMethodWeight = $address->getFreeMethodWeight();
     $addressQty = 0;
     foreach ($items as $item) {
         /**
          * Skip if this item is virtual
          */
         if ($item->getProduct()->isVirtual()) {
             continue;
         }
         /**
          * Children weight we calculate for parent
          */
         if ($item->getParentItem()) {
             continue;
         }
         if ($item->getHasChildren() && $item->isShipSeparately()) {
             foreach ($item->getChildren() as $child) {
                 if ($child->getProduct()->isVirtual()) {
                     continue;
                 }
                 $addressQty += $child->getTotalQty();
                 if (!$item->getProduct()->getWeightType()) {
                     $itemWeight = $child->getWeight();
                     $itemQty = $child->getTotalQty();
                     $rowWeight = $itemWeight * $itemQty;
                     $addressWeight += $rowWeight;
                     if ($freeAddress || $child->getFreeShipping() === true) {
                         $rowWeight = 0;
                     } elseif (is_numeric($child->getFreeShipping())) {
                         $freeQty = $child->getFreeShipping();
                         if ($itemQty > $freeQty) {
                             $rowWeight = $itemWeight * ($itemQty - $freeQty);
                         } else {
                             $rowWeight = 0;
                         }
                     }
                     $freeMethodWeight += $rowWeight;
                     $item->setRowWeight($rowWeight);
                 }
             }
             if ($item->getProduct()->getWeightType()) {
                 $itemWeight = $item->getWeight();
                 $rowWeight = $itemWeight * $item->getQty();
                 $addressWeight += $rowWeight;
                 if ($freeAddress || $item->getFreeShipping() === true) {
                     $rowWeight = 0;
                 } elseif (is_numeric($item->getFreeShipping())) {
                     $freeQty = $item->getFreeShipping();
                     if ($item->getQty() > $freeQty) {
                         $rowWeight = $itemWeight * ($item->getQty() - $freeQty);
                     } else {
                         $rowWeight = 0;
                     }
                 }
                 $freeMethodWeight += $rowWeight;
                 $item->setRowWeight($rowWeight);
             }
         } else {
             if (!$item->getProduct()->isVirtual()) {
                 $addressQty += $item->getQty();
             }
             $itemWeight = $item->getWeight();
             $rowWeight = $itemWeight * $item->getQty();
             $addressWeight += $rowWeight;
             if ($freeAddress || $item->getFreeShipping() === true) {
                 $rowWeight = 0;
             } elseif (is_numeric($item->getFreeShipping())) {
                 $freeQty = $item->getFreeShipping();
                 if ($item->getQty() > $freeQty) {
                     $rowWeight = $itemWeight * ($item->getQty() - $freeQty);
                 } else {
                     $rowWeight = 0;
                 }
             }
             $freeMethodWeight += $rowWeight;
             $item->setRowWeight($rowWeight);
         }
     }
     if (isset($addressQty)) {
         $address->setItemQty($addressQty);
     }
     $address->setWeight($addressWeight);
     $address->setFreeMethodWeight($freeMethodWeight);
     $address->collectShippingRates();
     $this->_setAmount(0)->_setBaseAmount(0);
     if ($method) {
         foreach ($address->getAllShippingRates() as $rate) {
             if ($rate->getCode() == $method) {
                 $amountPrice = $this->priceCurrency->convert($rate->getPrice(), $address->getQuote()->getStore());
                 $this->_setAmount($amountPrice);
                 $this->_setBaseAmount($rate->getPrice());
                 $shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
                 $address->setShippingDescription(trim($shippingDescription, ' -'));
                 break;
             }
         }
     }
     return $this;
 }
示例#11
0
 /**
  * Collect address discount amount
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
  * @param \Magento\Quote\Model\Quote\Address\Total $total
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     parent::collect($quote, $shippingAssignment, $total);
     $store = $this->storeManager->getStore($quote->getStoreId());
     $address = $shippingAssignment->getShipping()->getAddress();
     $this->calculator->reset($address);
     $items = $shippingAssignment->getItems();
     if (!count($items)) {
         return $this;
     }
     $eventArgs = ['website_id' => $store->getWebsiteId(), 'customer_group_id' => $quote->getCustomerGroupId(), 'coupon_code' => $quote->getCouponCode()];
     $this->calculator->init($store->getWebsiteId(), $quote->getCustomerGroupId(), $quote->getCouponCode());
     $this->calculator->initTotals($items, $address);
     $address->setDiscountDescription([]);
     $items = $this->calculator->sortItemsByPriority($items);
     /** @var \Magento\Quote\Model\Quote\Item $item */
     foreach ($items as $item) {
         if ($item->getNoDiscount() || !$this->calculator->canApplyDiscount($item)) {
             $item->setDiscountAmount(0);
             $item->setBaseDiscountAmount(0);
             // ensure my children are zeroed out
             if ($item->getHasChildren() && $item->isChildrenCalculated()) {
                 foreach ($item->getChildren() as $child) {
                     $child->setDiscountAmount(0);
                     $child->setBaseDiscountAmount(0);
                 }
             }
             continue;
         }
         // to determine the child item discount, we calculate the parent
         if ($item->getParentItem()) {
             continue;
         }
         $eventArgs['item'] = $item;
         $this->eventManager->dispatch('sales_quote_address_discount_item', $eventArgs);
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             $this->calculator->process($item);
             $this->distributeDiscount($item);
             foreach ($item->getChildren() as $child) {
                 $eventArgs['item'] = $child;
                 $this->eventManager->dispatch('sales_quote_address_discount_item', $eventArgs);
                 $this->aggregateItemDiscount($child, $total);
             }
         } else {
             $this->calculator->process($item);
             $this->aggregateItemDiscount($item, $total);
         }
     }
     /** Process shipping amount discount */
     $address->setShippingDiscountAmount(0);
     $address->setBaseShippingDiscountAmount(0);
     if ($address->getShippingAmount()) {
         $this->calculator->processShippingAmount($address);
         $total->addTotalAmount($this->getCode(), -$address->getShippingDiscountAmount());
         $total->addBaseTotalAmount($this->getCode(), -$address->getBaseShippingDiscountAmount());
     }
     $this->calculator->prepareDescription($address);
     $total->setDiscountDescription($address->getDiscountDescription());
     $total->setSubtotalWithDiscount($total->getSubtotal() + $total->getDiscountAmount());
     $total->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $total->getBaseDiscountAmount());
     return $this;
 }
 public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     parent::collect($quote, $shippingAssignment, $total);
     /* get fresh grands from calculating totals */
     $grandBase = $total->getData(\Magento\Quote\Api\Data\TotalsInterface::KEY_BASE_GRAND_TOTAL);
     $grand = $total->getData(\Magento\Quote\Api\Data\TotalsInterface::KEY_GRAND_TOTAL);
     if ($grandBase == 0) {
         /* this is billing address, compose result */
         $total->setBaseTotalAmount(self::CODE, 0);
         $total->setTotalAmount(self::CODE, 0);
     } else {
         $isPartialEnabled = $this->hlpConfig->getWalletPartialEnabled();
         if ($isPartialEnabled) {
             $quoteId = $quote->getId();
             /** @var \Praxigento\Wallet\Data\Entity\Partial\Quote $partialDataSaved */
             $partialDataSaved = $this->repoPartialQuote->getById($quoteId);
             /**
              * Check quote for partial payment switcher.
              * See \Praxigento\Wallet\Observer\SalesQuotePaymentImportDataBefore
              */
             $usePartial = $quote->getData(self::ATTR_QUOTE_SWITCH_PARTIAL_PAYMENT);
             if (!is_null($usePartial)) {
                 /* there is switcher in the quote,  */
                 if ($usePartial) {
                     /* switcher is on - we need to recalculate amounts */
                     /* get max. percent to pay partially */
                     $percent = $this->hlpConfig->getWalletPartialPercent();
                     /* calculate values */
                     $partial = $this->hlpPriceCurrency->round($grand * $percent);
                     $partialBase = $this->hlpPriceCurrency->round($grandBase * $percent);
                     /* re-save partial if they are different */
                     if ($partialDataSaved) {
                         /* get saved partial totals */
                         $partialSavedBase = $partialDataSaved->getBasePartialAmount();
                         $partialSaved = $partialDataSaved->getPartialAmount();
                         if ($partialSavedBase != $partialBase || $partialSaved != $partial) {
                             /* re-save quote partial in registry */
                             $partialDataSaved->setBasePartialAmount($partialBase);
                             $partialDataSaved->setPartialAmount($partial);
                             $this->repoPartialQuote->updateById($quoteId, $partialDataSaved);
                         }
                     } else {
                         /* create new record in the registry */
                         $partialDataSaved = new \Praxigento\Wallet\Data\Entity\Partial\Quote();
                         $partialDataSaved->setQuoteRef($quoteId);
                         $partialDataSaved->setBasePartialAmount($partialBase);
                         $partialDataSaved->setPartialAmount($partial);
                         $this->repoPartialQuote->create($partialDataSaved);
                     }
                     /* reset totals in quote and compose result */
                     $quote->setData(self::CODE_BASE_TOTAL, $partialBase);
                     $quote->setData(self::CODE_TOTAL, $partial);
                     $total->setBaseTotalAmount(self::CODE, $partialBase);
                     $total->setTotalAmount(self::CODE, $partial);
                 } else {
                     /* switcher is off - clean up saved quote if exist */
                     if ($partialDataSaved) {
                         $this->repoPartialQuote->deleteById($quoteId);
                     }
                     /* reset totals in quote and compose result */
                     $quote->setData(self::CODE_BASE_TOTAL, 0);
                     $quote->setData(self::CODE_TOTAL, 0);
                     $total->setBaseTotalAmount(self::CODE, 0);
                     $total->setTotalAmount(self::CODE, 0);
                 }
             } else {
                 /* use quote saved totals if exist */
                 if ($partialDataSaved) {
                     /* there are saved data for the quote */
                     /* get max. percent to pay partially */
                     $percent = $this->hlpConfig->getWalletPartialPercent();
                     /* calculate values */
                     $partialBase = $this->hlpPriceCurrency->round($grandBase * $percent);
                     $partial = $this->hlpPriceCurrency->round($grand * $percent);
                     /* get saved partial totals */
                     $partialSavedBase = $partialDataSaved->getBasePartialAmount();
                     $partialSaved = $partialDataSaved->getPartialAmount();
                     if ($partialSavedBase != $partialBase || $partialSaved != $partial) {
                         /* re-save quote partial in registry */
                         $partialDataSaved->setBasePartialAmount($partialBase);
                         $partialDataSaved->setPartialAmount($partial);
                         $this->repoPartialQuote->updateById($quoteId, $partialDataSaved);
                     }
                     /* reset totals in quote and compose result */
                     $quote->setData(self::CODE_BASE_TOTAL, $partialBase);
                     $quote->setData(self::CODE_TOTAL, $partial);
                     $total->setBaseTotalAmount(self::CODE, $partialBase);
                     $total->setTotalAmount(self::CODE, $partial);
                 } else {
                     /* partial payment does not used */
                     /* reset totals in quote and compose result */
                     $quote->setData(self::CODE_BASE_TOTAL, 0);
                     $quote->setData(self::CODE_TOTAL, 0);
                     $total->setBaseTotalAmount(self::CODE, 0);
                     $total->setTotalAmount(self::CODE, 0);
                 }
             }
         }
     }
     return $this;
 }
示例#13
0
 /**
  * Collect Weee taxes amount and prepare items prices for taxation and discount
  *
  * @param   \Magento\Quote\Model\Quote\Address $address
  * @return  $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function collect(\Magento\Quote\Model\Quote\Address $address)
 {
     \Magento\Quote\Model\Quote\Address\Total\AbstractTotal::collect($address);
     $this->_store = $address->getQuote()->getStore();
     if (!$this->weeeData->isEnabled($this->_store)) {
         return $this;
     }
     $items = $this->_getAddressItems($address);
     if (!count($items)) {
         return $this;
     }
     //If Weee is not taxable, then the 'weee' collector has accumulated the non-taxable total values
     if (!$this->weeeData->isTaxable($this->_store)) {
         //Because Weee is not taxable:  Weee excluding tax == Weee including tax
         $weeeTotal = $address->getWeeeTotalExclTax();
         $weeeBaseTotal = $address->getWeeeBaseTotalExclTax();
         //Add to appropriate 'subtotal' or 'weee' accumulators
         $this->processTotalAmount($address, $weeeTotal, $weeeBaseTotal, $weeeTotal, $weeeBaseTotal);
         return $this;
     }
     $weeeCodeToItemMap = $address->getWeeeCodeToItemMap();
     $extraTaxableDetails = $address->getExtraTaxableDetails();
     if (isset($extraTaxableDetails[self::ITEM_TYPE])) {
         foreach ($extraTaxableDetails[self::ITEM_TYPE] as $itemCode => $weeeAttributesTaxDetails) {
             $weeeCode = $weeeAttributesTaxDetails[0]['code'];
             $item = $weeeCodeToItemMap[$weeeCode];
             $this->weeeData->setApplied($item, []);
             $productTaxes = [];
             $totalValueInclTax = 0;
             $baseTotalValueInclTax = 0;
             $totalRowValueInclTax = 0;
             $baseTotalRowValueInclTax = 0;
             $totalValueExclTax = 0;
             $baseTotalValueExclTax = 0;
             $totalRowValueExclTax = 0;
             $baseTotalRowValueExclTax = 0;
             //Process each weee attribute of an item
             foreach ($weeeAttributesTaxDetails as $weeeTaxDetails) {
                 $weeeCode = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_CODE];
                 $attributeCode = explode('-', $weeeCode)[1];
                 $valueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_PRICE_EXCL_TAX];
                 $baseValueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_BASE_PRICE_EXCL_TAX];
                 $valueInclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_PRICE_INCL_TAX];
                 $baseValueInclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_BASE_PRICE_INCL_TAX];
                 $rowValueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_ROW_TOTAL];
                 $baseRowValueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_BASE_ROW_TOTAL];
                 $rowValueInclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_ROW_TOTAL_INCL_TAX];
                 $baseRowValueInclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_BASE_ROW_TOTAL_INCL_TAX];
                 $totalValueInclTax += $valueInclTax;
                 $baseTotalValueInclTax += $baseValueInclTax;
                 $totalRowValueInclTax += $rowValueInclTax;
                 $baseTotalRowValueInclTax += $baseRowValueInclTax;
                 $totalValueExclTax += $valueExclTax;
                 $baseTotalValueExclTax += $baseValueExclTax;
                 $totalRowValueExclTax += $rowValueExclTax;
                 $baseTotalRowValueExclTax += $baseRowValueExclTax;
                 $productTaxes[] = ['title' => $attributeCode, 'base_amount' => $baseValueExclTax, 'amount' => $valueExclTax, 'row_amount' => $rowValueExclTax, 'base_row_amount' => $baseRowValueExclTax, 'base_amount_incl_tax' => $baseValueInclTax, 'amount_incl_tax' => $valueInclTax, 'row_amount_incl_tax' => $rowValueInclTax, 'base_row_amount_incl_tax' => $baseRowValueInclTax];
             }
             $item->setWeeeTaxAppliedAmount($totalValueExclTax)->setBaseWeeeTaxAppliedAmount($baseTotalValueExclTax)->setWeeeTaxAppliedRowAmount($totalRowValueExclTax)->setBaseWeeeTaxAppliedRowAmnt($baseTotalRowValueExclTax);
             $item->setWeeeTaxAppliedAmountInclTax($totalValueInclTax)->setBaseWeeeTaxAppliedAmountInclTax($baseTotalValueInclTax)->setWeeeTaxAppliedRowAmountInclTax($totalRowValueInclTax)->setBaseWeeeTaxAppliedRowAmntInclTax($baseTotalRowValueInclTax);
             $this->processTotalAmount($address, $totalRowValueExclTax, $baseTotalRowValueExclTax, $totalRowValueInclTax, $baseTotalRowValueInclTax);
             $this->weeeData->setApplied($item, array_merge($this->weeeData->getApplied($item), $productTaxes));
         }
     }
     return $this;
 }
示例#14
0
 /**
  * Collect Weee taxes amount and prepare items prices for taxation and discount
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface|\Magento\Quote\Model\Quote\Address $shippingAssignment
  * @param \Magento\Quote\Model\Quote\Address\Total $total
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     \Magento\Quote\Model\Quote\Address\Total\AbstractTotal::collect($quote, $shippingAssignment, $total);
     $this->_store = $quote->getStore();
     if (!$this->weeeData->isEnabled($this->_store)) {
         return $this;
     }
     $items = $shippingAssignment->getItems();
     if (!count($items)) {
         return $this;
     }
     //If Weee is not taxable, then the 'weee' collector has accumulated the non-taxable total values
     if (!$this->weeeData->isTaxable($this->_store)) {
         //Because Weee is not taxable:  Weee excluding tax == Weee including tax
         $weeeTotal = $total->getWeeeTotalExclTax();
         $weeeBaseTotal = $total->getWeeeBaseTotalExclTax();
         //Add to appropriate 'subtotal' or 'weee' accumulators
         $this->processTotalAmount($total, $weeeTotal, $weeeBaseTotal, $weeeTotal, $weeeBaseTotal);
         return $this;
     }
     $extraTaxableDetails = $total->getExtraTaxableDetails();
     if (isset($extraTaxableDetails[self::ITEM_TYPE])) {
         //Get mapping from weeeCode to item
         $weeeCodeToItemMap = $total->getWeeeCodeToItemMap();
         //Create mapping from item to weeeCode
         $itemToWeeeCodeMap = $this->createItemToWeeeCodeMapping($weeeCodeToItemMap);
         //Create mapping from weeeCode to weeeTaxDetails
         $weeeCodeToWeeeTaxDetailsMap = [];
         foreach ($extraTaxableDetails[self::ITEM_TYPE] as $weeeAttributesTaxDetails) {
             foreach ($weeeAttributesTaxDetails as $weeeTaxDetails) {
                 $weeeCode = $weeeTaxDetails['code'];
                 $weeeCodeToWeeeTaxDetailsMap[$weeeCode] = $weeeTaxDetails;
             }
         }
         //Process each item that has taxable weee
         foreach ($itemToWeeeCodeMap as $mapping) {
             $item = $mapping['item'];
             $this->weeeData->setApplied($item, []);
             $productTaxes = [];
             $totalValueInclTax = 0;
             $baseTotalValueInclTax = 0;
             $totalRowValueInclTax = 0;
             $baseTotalRowValueInclTax = 0;
             $totalValueExclTax = 0;
             $baseTotalValueExclTax = 0;
             $totalRowValueExclTax = 0;
             $baseTotalRowValueExclTax = 0;
             //Process each taxed weee attribute of an item
             foreach ($mapping['weeeCodes'] as $weeeCode) {
                 if (!array_key_exists($weeeCode, $weeeCodeToWeeeTaxDetailsMap)) {
                     //Need to ensure that everyone is in sync for which weee code to process
                     continue;
                 }
                 $weeeTaxDetails = $weeeCodeToWeeeTaxDetailsMap[$weeeCode];
                 $attributeCode = explode('-', $weeeCode)[1];
                 $valueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_PRICE_EXCL_TAX];
                 $baseValueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_BASE_PRICE_EXCL_TAX];
                 $valueInclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_PRICE_INCL_TAX];
                 $baseValueInclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_BASE_PRICE_INCL_TAX];
                 $rowValueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_ROW_TOTAL];
                 $baseRowValueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_BASE_ROW_TOTAL];
                 $rowValueInclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_ROW_TOTAL_INCL_TAX];
                 $baseRowValueInclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_BASE_ROW_TOTAL_INCL_TAX];
                 $totalValueInclTax += $valueInclTax;
                 $baseTotalValueInclTax += $baseValueInclTax;
                 $totalRowValueInclTax += $rowValueInclTax;
                 $baseTotalRowValueInclTax += $baseRowValueInclTax;
                 $totalValueExclTax += $valueExclTax;
                 $baseTotalValueExclTax += $baseValueExclTax;
                 $totalRowValueExclTax += $rowValueExclTax;
                 $baseTotalRowValueExclTax += $baseRowValueExclTax;
                 $productTaxes[] = ['title' => $attributeCode, 'base_amount' => $baseValueExclTax, 'amount' => $valueExclTax, 'row_amount' => $rowValueExclTax, 'base_row_amount' => $baseRowValueExclTax, 'base_amount_incl_tax' => $baseValueInclTax, 'amount_incl_tax' => $valueInclTax, 'row_amount_incl_tax' => $rowValueInclTax, 'base_row_amount_incl_tax' => $baseRowValueInclTax];
             }
             $item->setWeeeTaxAppliedAmount($totalValueExclTax)->setBaseWeeeTaxAppliedAmount($baseTotalValueExclTax)->setWeeeTaxAppliedRowAmount($totalRowValueExclTax)->setBaseWeeeTaxAppliedRowAmnt($baseTotalRowValueExclTax);
             $item->setWeeeTaxAppliedAmountInclTax($totalValueInclTax)->setBaseWeeeTaxAppliedAmountInclTax($baseTotalValueInclTax)->setWeeeTaxAppliedRowAmountInclTax($totalRowValueInclTax)->setBaseWeeeTaxAppliedRowAmntInclTax($baseTotalRowValueInclTax);
             $this->processTotalAmount($total, $totalRowValueExclTax, $baseTotalRowValueExclTax, $totalRowValueInclTax, $baseTotalRowValueInclTax);
             $this->weeeData->setApplied($item, array_merge($this->weeeData->getApplied($item), $productTaxes));
         }
     }
     return $this;
 }