Skip to content

magento/magento2#39905 Product Removed on Mobile Still Appears in Web's Mini Compare Section Until Re-login #40023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: 2.4-develop
Choose a base branch
from
Open
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