Skip to content

Commit

Permalink
#1744 Update cart on currency change (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
riha112 authored Dec 21, 2020
1 parent b7df35a commit 853798e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Model/Resolver/Currency/SaveSelectedCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Currency;

use Exception;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Store\Model\StoreManagerInterface;
use \Magento\Checkout\Model\Session as SessionManager;

/**
* Class SaveCartItem
Expand All @@ -32,14 +34,22 @@ class SaveSelectedCurrency implements ResolverInterface
*/
protected $storeManager;

/**
* @var SessionManager
*/
protected $sessionManager;

/**
* SaveSelectedCurrency constructor.
* @param StoreManagerInterface $storeManager
* @param SessionManager $sessionManager
*/
public function __construct(
StoreManagerInterface $storeManager
StoreManagerInterface $storeManager,
SessionManager $sessionManager
) {
$this->storeManager = $storeManager;
$this->sessionManager = $sessionManager;
}

/**
Expand All @@ -64,6 +74,13 @@ public function resolve(

if ($currency) {
$this->storeManager->getStore()->setCurrentCurrencyCode($currency);

// Rebuilds active quotes all values (price, currency, etc.)
try {
$this->sessionManager->getQuote()->collectTotals()->save();
} catch (NoSuchEntityException $exception) {
// Ignore if quote is not set
}
}

return [];
Expand Down

0 comments on commit 853798e

Please sign in to comment.