Skip to content

Commit

Permalink
Merge pull request #140 from IrinaZhadzinets/issue-908
Browse files Browse the repository at this point in the history
#908 - Change cart currency when switch currency on the website
  • Loading branch information
carinadues authored Jul 6, 2022
2 parents 4329227 + 1e697fa commit 046db6d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
34 changes: 20 additions & 14 deletions src/Model/Resolver/Currency/SaveSelectedCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* See LICENSE for license details.
*
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
* @package scandipwa/module-customer-graph-ql
* @link https://github.com/scandipwa/module-customer-graph-ql
* @package scandipwa/catalog-graphql
* @link https://github.com/scandipwa/catalog-graphql
*/

declare(strict_types=1);

namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Currency;
Expand All @@ -21,35 +22,39 @@
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;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Api\GuestCartRepositoryInterface;
use ScandiPWA\QuoteGraphQl\Model\Resolver\CartResolver;
use Magento\Webapi\Controller\Rest\ParamOverriderCustomerId;

/**
* Class SaveCartItem
* @package ScandiPWA\QuoteGraphQl\Model\Resolver
*/
class SaveSelectedCurrency implements ResolverInterface
class SaveSelectedCurrency extends CartResolver
{
/**
* @var StoreManagerInterface
*/
protected $storeManager;

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

/**
* SaveSelectedCurrency constructor.
* @param StoreManagerInterface $storeManager
* @param SessionManager $sessionManager
*/
public function __construct(
StoreManagerInterface $storeManager,
SessionManager $sessionManager
ParamOverriderCustomerId $overriderCustomerId,
CartManagementInterface $quoteManagement,
GuestCartRepositoryInterface $guestCartRepository
) {
parent::__construct(
$guestCartRepository,
$overriderCustomerId,
$quoteManagement
);

$this->storeManager = $storeManager;
$this->sessionManager = $sessionManager;
}

/**
Expand Down Expand Up @@ -77,7 +82,8 @@ public function resolve(

// Rebuilds active quotes all values (price, currency, etc.)
try {
$this->sessionManager->getQuote()->collectTotals()->save();
$quote = $this->getCart($args);
$quote->collectTotals()->save();
} catch (NoSuchEntityException $exception) {
// Ignore if quote is not set
}
Expand Down
2 changes: 1 addition & 1 deletion src/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interface AggregationOptionInterface {
}

type Mutation {
saveSelectedCurrency(currency: String): Query @resolver(class:"ScandiPWA\\CatalogGraphQl\\Model\\Resolver\\Currency\\SaveSelectedCurrency")
saveSelectedCurrency(currency: String, guestCartId: String): Query @resolver(class:"ScandiPWA\\CatalogGraphQl\\Model\\Resolver\\Currency\\SaveSelectedCurrency")
}

type Query {
Expand Down

0 comments on commit 046db6d

Please sign in to comment.