/** * @param ShippingInterface $shipping * @param CartInterface $quote * @return void */ public function save(ShippingInterface $shipping, CartInterface $quote) { $this->shippingAddressManagement->assign($quote->getId(), $shipping->getAddress()); if (!empty($shipping->getMethod()) && $quote->getItemsCount() > 0) { $nameComponents = explode('_', $shipping->getMethod()); $carrierCode = array_shift($nameComponents); // carrier method code can contains more one name component $methodCode = implode('_', $nameComponents); $this->shippingMethodManagement->apply($quote->getId(), $carrierCode, $methodCode); } }
/** * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Unable to save address. Please, check input data. */ public function testSetAddressWithInabilityToSaveQuote() { $this->quoteAddressMock->expects($this->once())->method('collectTotals')->willReturnSelf(); $this->quoteAddressMock->expects($this->once())->method('save')->willThrowException(new \Exception('Unable to save address. Please, check input data.')); $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with('cart867')->will($this->returnValue($quoteMock)); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->quoteAddressMock); $this->validatorMock->expects($this->once())->method('validate')->with($this->quoteAddressMock)->will($this->returnValue(true)); $this->service->assign('cart867', $this->quoteAddressMock); }
/** * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Unable to save address. Please, check input data. */ public function testSetAddressWithInabilityToSaveQuote() { $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with('cart867')->will($this->returnValue($quoteMock)); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->validatorMock->expects($this->once())->method('validate')->with($this->quoteAddressMock)->will($this->returnValue(true)); $quoteMock->expects($this->once())->method('setShippingAddress')->with($this->quoteAddressMock); $quoteMock->expects($this->once())->method('setDataChanges')->with(true); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock)->willThrowException(new \Exception('Some DB Error')); $this->service->assign('cart867', $this->quoteAddressMock); }
/** * @expectedException \Magento\Framework\Exception\InputException */ public function testSetAddressWithViolationOfMinimumAmount() { $storeId = 12; $this->quoteAddressMock->expects($this->once())->method('save'); $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with('cart123')->will($this->returnValue($quoteMock)); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->quoteAddressMock); $quoteMock->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $this->totalsCollectorMock->expects($this->once())->method('collectAddressTotals')->with($quoteMock, $this->quoteAddressMock); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $this->service->assign('cart123', $this->quoteAddressMock); }