/** * @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); } }
/** * @param string $method * @param string $carrierCode * @param string $methodCode * @dataProvider saveDataProvider */ public function testSave($method, $carrierCode, $methodCode) { $shipping = $this->getMockForAbstractClass(ShippingInterface::class); $quote = $this->getMockForAbstractClass(CartInterface::class); $quoteId = 1; $address = $this->getMockForAbstractClass(AddressInterface::class); $quote->expects(static::exactly(2))->method('getId')->willReturn($quoteId); $shipping->expects(static::once())->method('getAddress')->willReturn($address); $this->shippingAddressManagement->expects(static::once())->method('assign')->with($quoteId, $address); $shipping->expects(static::exactly(2))->method('getMethod')->willReturn($method); $quote->expects(static::once())->method('getItemsCount')->willReturn(1); $this->shippingMethodManagement->expects(static::once())->method('apply')->with($quoteId, $carrierCode, $methodCode); $this->shippingProcessor->save($shipping, $quote); }
public function testSetMethod() { $cartId = 12; $carrierCode = 34; $methodCode = 56; $countryId = 1; $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue($countryId)); $this->shippingAddressMock->expects($this->once())->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); $this->shippingAddressMock->expects($this->once())->method('getShippingRateByCode')->will($this->returnValue(true)); $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnSelf()); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); $this->assertTrue($this->model->set($cartId, $carrierCode, $methodCode)); }
public function testSetMethod() { $cartId = 12; $carrierCode = 34; $methodCode = 56; $countryId = 1; $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); $billingAddressMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address', ['getCountryId', '__wakeup'], [], '', false); $this->quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($billingAddressMock)); $billingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(23)); $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue($countryId)); $this->shippingAddressMock->expects($this->once())->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); $this->shippingAddressMock->expects($this->once())->method('requestShippingRates')->will($this->returnValue(true)); $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnSelf()); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); $this->assertTrue($this->model->set($cartId, $carrierCode, $methodCode)); }
/** * @covers \Magento\Quote\Model\ShippingMethodManagement::estimateByExtendedAddress */ public function testEstimateByExtendedAddress() { $cartId = 1; $addressData = ['region' => 'California', 'region_id' => 23, 'country_id' => 1, 'postcode' => 90200]; $currencyCode = 'UAH'; $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->setMethods(['getData'])->getMock(); $this->quoteRepository->expects(static::once())->method('getActive')->with($cartId)->willReturn($this->quote); $this->quote->expects(static::once())->method('isVirtual')->willReturn(false); $this->quote->expects(static::once())->method('getItemsCount')->willReturn(1); $address->expects(static::once())->method('getData')->willReturn($addressData); $this->quote->expects(static::once())->method('getShippingAddress')->willReturn($this->shippingAddress); $this->shippingAddress->expects(static::once())->method('addData')->with($addressData)->willReturnSelf(); $this->shippingAddress->expects(static::once())->method('setCollectShippingRates')->with(true)->willReturnSelf(); $this->totalsCollector->expects(static::once())->method('collectAddressTotals')->with($this->quote, $this->shippingAddress)->willReturnSelf(); $rate = $this->getMockBuilder(Rate::class)->disableOriginalConstructor()->setMethods([])->getMock(); $methodObject = $this->getMockForAbstractClass(ShippingMethodInterface::class); $expectedRates = [$methodObject]; $this->shippingAddress->expects(static::once())->method('getGroupedAllShippingRates')->willReturn([[$rate]]); $this->quote->expects(static::once())->method('getQuoteCurrencyCode')->willReturn($currencyCode); $this->converter->expects(static::once())->method('modelToDataObject')->with($rate, $currencyCode)->willReturn($methodObject); $carriersRates = $this->model->estimateByExtendedAddress($cartId, $address); static::assertEquals($expectedRates, $carriersRates); }