Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Copy link
Contributor Author

@KrasnoshchokBohdan KrasnoshchokBohdan Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Den4ik Hi!
Sorry to bother you. I probably should have marked this as a draft immediately.
Currently, I'm struggling with a solution for reloading the compare-product customer section after changes made by a GraphQL mutation (

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @KrasnoshchokBohdan
Thanks for details

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ define([
customerData.reload(['compare-products'], false);
compareProductsReloaded = true;
}

// Force reload on page load
customerData.reload(['compare-products'], false);

initSidebar();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

namespace Magento\CompareListGraphQl\Model\Resolver;

use Magento\Catalog\Helper\Product\Compare;
use Magento\Catalog\Model\MaskedListIdToCompareListId;
use Magento\CompareListGraphQl\Model\Service\AddToCompareList;
use Magento\CompareListGraphQl\Model\Service\Customer\GetListIdByCustomerId;
use Magento\CompareListGraphQl\Model\Service\GetCompareList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
Expand Down Expand Up @@ -44,22 +46,31 @@ class AddProductsToCompareList implements ResolverInterface
*/
private $getListIdByCustomerId;

/**
* @var Compare
*/
private mixed $productCompareHelper;

/**
* @param AddToCompareList $addProductToCompareList
* @param GetCompareList $getCompareList
* @param MaskedListIdToCompareListId $maskedListIdToCompareListId
* @param GetListIdByCustomerId $getListIdByCustomerId
* @param Compare|null $productCompareHelper
*/
public function __construct(
AddToCompareList $addProductToCompareList,
GetCompareList $getCompareList,
MaskedListIdToCompareListId $maskedListIdToCompareListId,
GetListIdByCustomerId $getListIdByCustomerId
GetListIdByCustomerId $getListIdByCustomerId,
?Compare $productCompareHelper = null
) {
$this->addProductToCompareList = $addProductToCompareList;
$this->getCompareList = $getCompareList;
$this->maskedListIdToCompareListId = $maskedListIdToCompareListId;
$this->getListIdByCustomerId = $getListIdByCustomerId;
$this->productCompareHelper = $productCompareHelper ?: ObjectManager::getInstance()
->get(Compare::class);
}

/**
Expand Down Expand Up @@ -104,6 +115,7 @@ public function resolve(

try {
$this->addProductToCompareList->execute($listId, $args['input']['products'], $context);
$this->productCompareHelper->calculate();
} catch (\Exception $exception) {
throw new GraphQlInputException(__($exception->getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

namespace Magento\CompareListGraphQl\Model\Resolver;

use Magento\Catalog\Helper\Product\Compare;
use Magento\CompareListGraphQl\Model\Service\AddToCompareList;
use Magento\CompareListGraphQl\Model\Service\CreateCompareList as CreateCompareListService;
use Magento\CompareListGraphQl\Model\Service\Customer\GetListIdByCustomerId;
use Magento\CompareListGraphQl\Model\Service\GetCompareList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
Expand Down Expand Up @@ -50,25 +52,34 @@ class CreateCompareList implements ResolverInterface
*/
private $createCompareList;

/**
* @var Compare
*/
private mixed $productCompareHelper;

/**
* @param Random $mathRandom
* @param GetListIdByCustomerId $getListIdByCustomerId
* @param AddToCompareList $addProductToCompareList
* @param GetCompareList $getCompareList
* @param CreateCompareListService $createCompareList
* @param Compare|null $productCompareHelper
*/
public function __construct(
Random $mathRandom,
GetListIdByCustomerId $getListIdByCustomerId,
AddToCompareList $addProductToCompareList,
GetCompareList $getCompareList,
CreateCompareListService $createCompareList
CreateCompareListService $createCompareList,
?Compare $productCompareHelper = null
) {
$this->mathRandom = $mathRandom;
$this->getListIdByCustomerId = $getListIdByCustomerId;
$this->addProductToCompareList = $addProductToCompareList;
$this->getCompareList = $getCompareList;
$this->createCompareList = $createCompareList;
$this->productCompareHelper = $productCompareHelper ?: ObjectManager::getInstance()
->get(Compare::class);
}

/**
Expand Down Expand Up @@ -111,6 +122,7 @@ public function resolve(
} else {
$listId = $this->createCompareList->execute($generatedListId, $customerId);
$this->addProductToCompareList->execute($listId, $products, $context);
$this->productCompareHelper->calculate();
}
}
} catch (LocalizedException $exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

namespace Magento\CompareListGraphQl\Model\Resolver;

use Magento\Catalog\Helper\Product\Compare;
use Magento\Catalog\Model\MaskedListIdToCompareListId;
use Magento\CompareListGraphQl\Model\Service\Customer\GetListIdByCustomerId;
use Magento\CompareListGraphQl\Model\Service\GetCompareList;
use Magento\CompareListGraphQl\Model\Service\RemoveFromCompareList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
Expand Down Expand Up @@ -44,22 +46,31 @@ class RemoveProductsFromCompareList implements ResolverInterface
*/
private $getListIdByCustomerId;

/**
* @var Compare
*/
private mixed $productCompareHelper;

/**
* @param GetCompareList $getCompareList
* @param RemoveFromCompareList $removeFromCompareList
* @param MaskedListIdToCompareListId $maskedListIdToCompareListId
* @param GetListIdByCustomerId $getListIdByCustomerId
* @param Compare|null $productCompareHelper
*/
public function __construct(
GetCompareList $getCompareList,
RemoveFromCompareList $removeFromCompareList,
MaskedListIdToCompareListId $maskedListIdToCompareListId,
GetListIdByCustomerId $getListIdByCustomerId
GetListIdByCustomerId $getListIdByCustomerId,
?Compare $productCompareHelper = null
) {
$this->getCompareList = $getCompareList;
$this->removeFromCompareList = $removeFromCompareList;
$this->maskedListIdToCompareListId = $maskedListIdToCompareListId;
$this->getListIdByCustomerId = $getListIdByCustomerId;
$this->productCompareHelper = $productCompareHelper ?: ObjectManager::getInstance()
->get(Compare::class);
}

/**
Expand Down Expand Up @@ -111,6 +122,7 @@ public function resolve(

try {
$this->removeFromCompareList->execute($listId, $args['input']['products']);
$this->productCompareHelper->calculate();
} catch (LocalizedException $exception) {
throw new GraphQlInputException(
__('Something was wrong during removing products from compare list')
Expand Down