Beispiel #1
0
 /**
  * @dataProvider fetchDataProvider
  */
 public function testFetch($shippingAmount, $shippingDescription, $expectedTotal)
 {
     $address = $this->getMock('Magento\\Sales\\Model\\Quote\\Address', array('getShippingAmount', 'getShippingDescription', 'addTotal', '__wakeup'), array(), '', false);
     $address->expects($this->once())->method('getShippingAmount')->will($this->returnValue($shippingAmount));
     $address->expects($this->once())->method('getShippingDescription')->will($this->returnValue($shippingDescription));
     $address->expects($this->once())->method('addTotal')->with($this->equalTo($expectedTotal))->will($this->returnSelf());
     $this->assertEquals($this->shippingModel, $this->shippingModel->fetch($address));
 }
Beispiel #2
0
 /**
  * Collect shipping amount individually for each item
  *
  * @param \Magento\Sales\Model\Quote\Address $address
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Quote\Address $address)
 {
     $items = $address->getAllNominalItems();
     if (!count($items)) {
         return $this;
     }
     // estimate quote with all address items to get their row weights
     $this->_shouldGetAllItems = true;
     parent::collect($address);
     $address->setCollectShippingRates(true);
     $this->_shouldGetAllItems = false;
     // now $items contains row weight information
     // collect shipping rates for each item individually
     foreach ($items as $item) {
         if (!$item->getProduct()->isVirtual()) {
             $address->requestShippingRates($item);
             $baseAmount = $item->getBaseShippingAmount();
             if ($baseAmount) {
                 $item->setShippingAmount($address->getQuote()->getStore()->convertPrice($baseAmount, false));
             }
         }
     }
     return $this;
 }