From c1ebf8dd97baa8ed3f94136001e70306fec01919 Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Fri, 6 Dec 2024 12:33:12 +0100 Subject: [PATCH] add StoreManagerInterface --- Model/Ideal/QuoteCreate.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Model/Ideal/QuoteCreate.php b/Model/Ideal/QuoteCreate.php index 926065dd9..2fcba3147 100644 --- a/Model/Ideal/QuoteCreate.php +++ b/Model/Ideal/QuoteCreate.php @@ -36,6 +36,7 @@ use Buckaroo\Magento2\Api\Data\QuoteCreateResponseInterfaceFactory; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Store\Model\StoreManagerInterface; class QuoteCreate implements IdealQuoteCreateInterface { @@ -49,6 +50,7 @@ class QuoteCreate implements IdealQuoteCreateInterface protected $shipmentEstimation; protected $logger; protected $quote; + protected $storeManager; public function __construct( QuoteCreateResponseInterfaceFactory $responseFactory, @@ -59,7 +61,8 @@ public function __construct( CheckoutSession $checkoutSession, QuoteRepository $quoteRepository, ShipmentEstimationInterface $shipmentEstimation, - Log $logger + Log $logger, + StoreManagerInterface $storeManager ) { $this->responseFactory = $responseFactory; $this->quoteBuilderInterfaceFactory = $quoteBuilderInterfaceFactory; @@ -70,6 +73,7 @@ public function __construct( $this->quoteRepository = $quoteRepository; $this->shipmentEstimation = $shipmentEstimation; $this->logger = $logger; + $this->storeManager = $storeManager; } /** @@ -101,13 +105,27 @@ public function execute(string $page, string $form_data = null) $this->setPaymentMethod(); } catch (\Throwable $th) { + $this->logger->debug('Error during quote creation: ' . $th->getMessage()); throw new IdealException("Failed to create quote"); } + $this->restoreStoreContext(); $this->calculateQuoteTotals(); return $this->responseFactory->create(["quote" => $this->quote]); } + /** + * Restore store context for the quote + */ + protected function restoreStoreContext() + { + if ($this->quote && $this->quote->getStoreId()) { + $this->storeManager->setCurrentStore($this->quote->getStoreId()); + } else { + $this->logger->debug('Store ID not set on quote.'); + } + } + /** * Get a customer's address by address ID * @@ -220,7 +238,7 @@ protected function setPlaceholderAddress(Address $address) */ protected function calculateQuoteTotals() { - $this->quote->setStoreId($this->quote->getStore()->getId()); + $this->restoreStoreContext(); if ($this->quote->getCustomerEmail() === null) { $this->quote->setCustomerEmail('no-reply@example.com');