-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1118 from buckaroo-it/BP-3896-Product-link-in-car…
…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
Showing
1 changed file
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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('[email protected]'); | ||
|