/**
  * {@inheritDoc}
  */
 public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
 {
     /** @var \Magento\Quote\Api\Data\CartItemInterface[] $items */
     if (!count($items)) {
         return false;
     }
     $addressFreeShipping = true;
     $store = $this->storeManager->getStore($quote->getStoreId());
     $this->calculator->init($store->getWebsiteId(), $quote->getCustomerGroupId(), $quote->getCouponCode());
     /** @var \Magento\Quote\Api\Data\CartItemInterface $item */
     foreach ($items as $item) {
         if ($item->getNoDiscount()) {
             $addressFreeShipping = false;
             $item->setFreeShipping(false);
             continue;
         }
         /** Child item discount we calculate for parent */
         if ($item->getParentItemId()) {
             continue;
         }
         $this->calculator->processFreeShipping($item);
         $itemFreeShipping = (bool) $item->getFreeShipping();
         $addressFreeShipping = $addressFreeShipping && $itemFreeShipping;
         /** Parent free shipping we apply to all children*/
         $this->applyToChildren($item, $itemFreeShipping);
     }
     return $addressFreeShipping;
 }
Example #2
0
 /**
  * Merge quotes
  *
  * @param   Quote $quote
  * @return $this
  */
 public function merge(Quote $quote)
 {
     $this->_eventManager->dispatch($this->_eventPrefix . '_merge_before', [$this->_eventObject => $this, 'source' => $quote]);
     foreach ($quote->getAllVisibleItems() as $item) {
         $found = false;
         foreach ($this->getAllItems() as $quoteItem) {
             if ($quoteItem->compare($item)) {
                 $quoteItem->setQty($quoteItem->getQty() + $item->getQty());
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $newItem = clone $item;
             $this->addItem($newItem);
             if ($item->getHasChildren()) {
                 foreach ($item->getChildren() as $child) {
                     $newChild = clone $child;
                     $newChild->setParentItem($newItem);
                     $this->addItem($newChild);
                 }
             }
         }
     }
     /**
      * Init shipping and billing address if quote is new
      */
     if (!$this->getId()) {
         $this->getShippingAddress();
         $this->getBillingAddress();
     }
     if ($quote->getCouponCode()) {
         $this->setCouponCode($quote->getCouponCode());
     }
     $this->_eventManager->dispatch($this->_eventPrefix . '_merge_after', [$this->_eventObject => $this, 'source' => $quote]);
     return $this;
 }