/** * Removing all quote items for specified product * * @param int $productId * @return void */ public function dropAllQuoteChildItems($productId) { $connection = $this->quoteResource->getConnection(); $select = $connection->select(); $quoteItemIds = $connection->fetchCol($select->from($this->getTable('quote_item'), ['item_id'])->where('product_id = :product_id'), ['product_id' => $productId]); if ($quoteItemIds) { $connection->delete($this->getTable('quote_item'), ['parent_item_id IN(?)' => $quoteItemIds]); } }
/** * @param CartInterface $quote * @return CartInterface * * @throws InputException * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function save(CartInterface $quote) { /** @var \Magento\Quote\Model\Quote $quote */ // Quote Item processing $items = $quote->getItems(); if ($items) { foreach ($items as $item) { /** @var \Magento\Quote\Model\Quote\Item $item */ if (!$item->isDeleted()) { $quote->setLastAddedItem($this->cartItemPersister->save($quote, $item)); } } } // Billing Address processing $billingAddress = $quote->getBillingAddress(); if ($billingAddress) { $this->billingAddressPersister->save($quote, $billingAddress); } $this->processShippingAssignment($quote); $this->quoteResourceModel->save($quote->collectTotals()); return $quote; }
/** * When deleting product, subtract it from all quotes quantities * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { $product = $observer->getEvent()->getProduct(); $this->_quote->substractProductFromQuotes($product); }
/** * When applying a catalog price rule, make related quotes recollect on demand * * @param \Magento\Framework\Event\Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(\Magento\Framework\Event\Observer $observer) { $this->_quote->markQuotesRecollectOnCatalogRules(); }
/** * Mark recollect contain product(s) quotes * * @param int $productId * @param int $status * @return void */ protected function _recollectQuotes($productId, $status) { if ($status != \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) { $this->_quote->markQuotesRecollect($productId); } }