We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 4a176d04 authored by cyattilakiss's avatar cyattilakiss Committed by GitHub

Use quote retrieved by quote id (#667)

parent d6032d10
...@@ -85,6 +85,11 @@ class PaymentMethods extends AbstractHelper ...@@ -85,6 +85,11 @@ class PaymentMethods extends AbstractHelper
*/ */
protected $themeProvider; protected $themeProvider;
/**
* @var \Magento\Quote\Model\Quote
*/
protected $quote;
/** /**
* PaymentMethods constructor. * PaymentMethods constructor.
* *
...@@ -133,41 +138,51 @@ class PaymentMethods extends AbstractHelper ...@@ -133,41 +138,51 @@ class PaymentMethods extends AbstractHelper
{ {
// get quote from quoteId // get quote from quoteId
$quote = $this->quoteRepository->getActive($quoteId); $quote = $this->quoteRepository->getActive($quoteId);
$store = $quote->getStore();
$paymentMethods = $this->fetchAlternativeMethods($store, $country); // If quote cannot be found early return the empty paymentMethods array
if (empty($quote)) {
return [];
}
$this->setQuote($quote);
$paymentMethods = $this->fetchAlternativeMethods($country);
return $paymentMethods; return $paymentMethods;
} }
/** /**
* @param $store
* @param $country * @param $country
* @return array * @return array
*/ */
protected function fetchAlternativeMethods($store, $country) protected function fetchAlternativeMethods($country)
{ {
$merchantAccount = $this->adyenHelper->getAdyenAbstractConfigData('merchant_account'); $quote = $this->getQuote();
$store = $quote->getStore();
$merchantAccount = $this->adyenHelper->getAdyenAbstractConfigData('merchant_account', $store->getId());
if (!$merchantAccount) { if (!$merchantAccount) {
return []; return [];
} }
$currencyCode = $this->getCurrentCurrencyCode($store);
$adyFields = [ $adyFields = [
"channel" => "Web", "channel" => "Web",
"merchantAccount" => $merchantAccount, "merchantAccount" => $merchantAccount,
"countryCode" => $this->getCurrentCountryCode($store, $country), "countryCode" => $this->getCurrentCountryCode($store, $country),
"amount" => [ "amount" => [
"currency" => $this->getCurrentCurrencyCode($store), "currency" => $currencyCode,
"value" => (int)$this->adyenHelper->formatAmount( "value" => (int)$this->adyenHelper->formatAmount(
$this->getCurrentPaymentAmount(), $this->getCurrentPaymentAmount(),
$this->getCurrentCurrencyCode($store) $currencyCode
), ),
], ],
"shopperReference" => $this->getCurrentShopperReference(), "shopperReference" => $this->getCurrentShopperReference(),
"shopperLocale" => $this->adyenHelper->getCurrentLocaleCode($store->getId()) "shopperLocale" => $this->adyenHelper->getCurrentLocaleCode($store->getId())
]; ];
$billingAddress = $this->getQuote()->getBillingAddress(); $billingAddress = $quote->getBillingAddress();
if (!empty($billingAddress)) { if (!empty($billingAddress)) {
if ($customerTelephone = trim($billingAddress->getTelephone())) { if ($customerTelephone = trim($billingAddress->getTelephone())) {
...@@ -319,7 +334,7 @@ class PaymentMethods extends AbstractHelper ...@@ -319,7 +334,7 @@ class PaymentMethods extends AbstractHelper
{ {
// initialize the adyen client // initialize the adyen client
$client = $this->adyenHelper->initializeAdyenClient($this->getQuote()->getStoreId()); $client = $this->adyenHelper->initializeAdyenClient($store->getId());
// initialize service // initialize service
$service = $this->adyenHelper->createAdyenCheckoutService($client); $service = $this->adyenHelper->createAdyenCheckoutService($client);
...@@ -342,7 +357,15 @@ class PaymentMethods extends AbstractHelper ...@@ -342,7 +357,15 @@ class PaymentMethods extends AbstractHelper
*/ */
protected function getQuote() protected function getQuote()
{ {
return $this->session->getQuote(); return $this->quote;
}
/**
* @param \Magento\Quote\Model\Quote $quote
*/
protected function setQuote(\Magento\Quote\Model\Quote $quote)
{
$this->quote = $quote;
} }
/** /**
...@@ -389,4 +412,4 @@ class PaymentMethods extends AbstractHelper ...@@ -389,4 +412,4 @@ class PaymentMethods extends AbstractHelper
return $responseData; return $responseData;
} }
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment