Skip to content

Commit

Permalink
Merge pull request #1118 from buckaroo-it/BP-3896-Product-link-in-car…
Browse files Browse the repository at this point in the history
…t-becomes-Invalid-after-canceling-iDEAL-quick-checkout-causing-404-error-on-frontend

BP-3896-Product-link-in-cart-becomes-Invalid-after-canceling-iDEAL-quick-checkout-causing-404-error-on-frontend
  • Loading branch information
vegimcarkaxhija authored Dec 6, 2024
2 parents 50e534c + c1ebf8d commit ab257a4
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Model/Ideal/QuoteCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -49,6 +50,7 @@ class QuoteCreate implements IdealQuoteCreateInterface
protected $shipmentEstimation;
protected $logger;
protected $quote;
protected $storeManager;

public function __construct(
QuoteCreateResponseInterfaceFactory $responseFactory,
Expand All @@ -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;
Expand All @@ -70,6 +73,7 @@ public function __construct(
$this->quoteRepository = $quoteRepository;
$this->shipmentEstimation = $shipmentEstimation;
$this->logger = $logger;
$this->storeManager = $storeManager;
}

/**
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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('[email protected]');
Expand Down

0 comments on commit ab257a4

Please sign in to comment.