Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function setShippingMethods($methods)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'setShippingMethods');
     if (!$pluginInfo) {
         return parent::setShippingMethods($methods);
     } else {
         return $this->___callPlugins('setShippingMethods', func_get_args(), $pluginInfo);
     }
 }
Exemplo n.º 2
0
 public function testSetShippingMethods()
 {
     $methodsArray = [1 => 'flatrate_flatrate', 2 => 'tablerate_bestway'];
     $addressId = 1;
     $addressMock = $this->getMock(\Magento\Quote\Model\Quote\Address::class, ['getId', 'setShippingMethod'], [], '', false);
     $extensionAttributesMock = $this->getMock(\Magento\Quote\Api\Data\CartExtension::class, ['setShippingAssignments'], [], '', false);
     $shippingAssignmentMock = $this->getMock(\Magento\Quote\Model\ShippingAssignment::class, ['getShipping', 'setShipping'], [], '', false);
     $shippingMock = $this->getMock(\Magento\Quote\Model\Shipping::class, ['setMethod'], [], '', false);
     $addressMock->expects($this->once())->method('getId')->willReturn($addressId);
     $this->quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([$addressMock]);
     $addressMock->expects($this->once())->method('setShippingMethod')->with($methodsArray[$addressId]);
     //mock for prepareShippingAssignment
     $this->quoteMock->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributesMock);
     $this->shippingAssignmentProcessorMock->expects($this->once())->method('create')->with($this->quoteMock)->willReturn($shippingAssignmentMock);
     $shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
     $shippingMock->expects($this->once())->method('setMethod')->with(null)->willReturnSelf();
     $shippingAssignmentMock->expects($this->once())->method('setShipping')->with($shippingMock);
     $extensionAttributesMock->expects($this->once())->method('setShippingAssignments')->with([$shippingAssignmentMock])->willReturnSelf();
     $this->quoteMock->expects($this->once())->method('setExtensionAttributes')->with($extensionAttributesMock);
     //save mock
     $this->quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf();
     $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
     $this->model->setShippingMethods($methodsArray);
 }