![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/Ecombricks/InventoryInstantPurchase/Plugin/Model/QuoteManagement/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See COPYING.txt for license details. */ namespace Ecombricks\InventoryInstantPurchase\Plugin\Model\QuoteManagement; /** * Quote management purchase plugin */ class Purchase { /** * Quote repository * * @var \Magento\Quote\Api\CartRepositoryInterface */ protected $quoteRepository; /** * Quote management * * @var \Magento\Quote\Api\CartManagementInterface */ protected $quoteManagement; /** * Quote config * * @var \Ecombricks\InventoryQuote\Model\Config */ protected $quoteConfig; /** * Constructor * * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository * @param \Magento\Quote\Api\CartManagementInterface $quoteManagement * @param \Ecombricks\InventoryQuote\Model\Config $quoteConfig * @return void */ public function __construct( \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Quote\Api\CartManagementInterface $quoteManagement, \Ecombricks\InventoryQuote\Model\Config $quoteConfig ) { $this->quoteRepository = $quoteRepository; $this->quoteManagement = $quoteManagement; $this->quoteConfig = $quoteConfig; } /** * Purchase * * @param \Magento\Quote\Model\Quote $quote * @return int * @throws \Magento\Framework\Exception\LocalizedException */ protected function purchase(\Magento\Quote\Model\Quote $quote): int { $quote->collectTotals(); $this->quoteRepository->save($quote); $orderId = $this->quoteManagement->placeOrder($quote->getId()); return ($this->quoteConfig->isSplitOrder()) ? current($orderId) : (int) $orderId; } /** * Around purchase * * @param \Magento\InstantPurchase\Model\QuoteManagement\Purchase $subject * @param \Closure $proceed * @param \Magento\Quote\Model\Quote $quote * @return int * @throws \Magento\Framework\Exception\LocalizedException */ public function aroundPurchase( \Magento\InstantPurchase\Model\QuoteManagement\Purchase $subject, \Closure $proceed, \Magento\Quote\Model\Quote $quote ): int { if (!$this->quoteConfig->isSplitOrder()) { return $proceed($quote); } return $this->purchase($quote); } }