Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('no-reply@example.com');
Expand Down
Loading