/** * @param ShippingAssignmentInterface $shippingAssignment * @param CartInterface $quote * @return void * @throws InputException */ public function save(CartInterface $quote, ShippingAssignmentInterface $shippingAssignment) { /** @var \Magento\Quote\Model\Quote $quote */ foreach ($shippingAssignment->getItems() as $item) { if (!$quote->getItemById($item->getItemId())) { $this->cartItemPersister->save($quote, $item); } } $this->shippingProcessor->save($shippingAssignment->getShipping(), $quote); }
/** * @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); }
/** * Test saving shipping assignments with deleted cart items * * @covers \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor::save */ public function testSaveWithDeletedCartItems() { $shippingAssignment = $this->getMockForAbstractClass(ShippingAssignmentInterface::class); $shipping = $this->getMockForAbstractClass(ShippingInterface::class); $quoteId = 1; $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); $quoteItem = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)->disableOriginalConstructor()->getMock(); $quoteItem->expects(static::once())->method('isDeleted')->willReturn(true); $quoteItem->expects(static::once())->method('getItemId')->willReturn($quoteId); $quote->expects(static::once())->method('getItemById')->with($quoteId)->willReturn(null); $shippingAssignment->expects(static::once())->method('getItems')->willReturn([$quoteItem]); $shippingAssignment->expects(static::once())->method('getShipping')->willReturn($shipping); $this->cartItemPersister->expects(static::never())->method('save'); $this->shippingProcessor->expects(static::once())->method('save')->with($shipping, $quote); $this->shippingAssignmentProcessor->save($quote, $shippingAssignment); }