/** * 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); }
/** * @param CartInterface $quote * @return CartInterface */ public function load(CartInterface $quote) { if (!$quote->getIsActive()) { return $quote; } /** @var \Magento\Quote\Model\Quote $quote */ $quote->setItems($quote->getAllVisibleItems()); $shippingAssignments = []; if (!$quote->isVirtual() && $quote->getItemsQty() > 0) { $shippingAssignments[] = $this->shippingAssignmentProcessor->create($quote); } $cartExtension = $quote->getExtensionAttributes(); if ($cartExtension === null) { $cartExtension = $this->cartExtensionFactory->create(); } $cartExtension->setShippingAssignments($shippingAssignments); $quote->setExtensionAttributes($cartExtension); return $quote; }
/** * @param CartInterface $quote * @param ShippingAssignmentInterface $shippingAssignment * @return void */ public function save(CartInterface $quote, ShippingAssignmentInterface $shippingAssignment) { if ($quote->getIsActive()) { $this->shippingAssignmentProcessor->save($quote, $shippingAssignment); } }