public function testProcessFreeShipping()
 {
     $addressMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->getMock();
     $item = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', ['getAddress', '__wakeup'], [], '', false);
     $item->expects($this->once())->method('getAddress')->will($this->returnValue($addressMock));
     $this->_model->expects($this->once())->method('_getRules')->with($addressMock)->will($this->returnValue([]));
     $this->assertInstanceOf('Magento\\OfflineShipping\\Model\\SalesRule\\Calculator', $this->_model->processFreeShipping($item));
     return true;
 }
 /**
  * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
  * @param bool $isFreeShipping
  * @return void
  */
 protected function applyToChildren(\Magento\Quote\Model\Quote\Item\AbstractItem $item, $isFreeShipping)
 {
     if ($item->getHasChildren() && $item->isChildrenCalculated()) {
         foreach ($item->getChildren() as $child) {
             $this->calculator->processFreeShipping($child);
             if ($isFreeShipping) {
                 $child->setFreeShipping($isFreeShipping);
             }
         }
     }
 }
Exemple #3
0
 /**
  * Collect information about free shipping for all address items
  *
  * @param   \Magento\Sales\Model\Quote\Address $address
  * @return  \Magento\OfflineShipping\Model\Quote\Freeshipping
  */
 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;
 }