Skip to content

Commit 9561b22

Browse files
committed
ACP2E-3987: Wishlist items are not shared between stores views within one website in GraphQL request
1 parent 376dd71 commit 9561b22

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItems.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function resolve(
6161
$wishlist = $value['model'];
6262

6363
if ($context->getExtensionAttributes()->getStore() instanceof StoreInterface) {
64-
$args['store_id'] = $context->getExtensionAttributes()->getStore()->getId();
64+
$args['website_id'] = $context->getExtensionAttributes()->getStore()->getWebsiteId();
6565
}
6666

6767
/** @var WishlistItemCollection $wishlistItemCollection */
@@ -95,6 +95,7 @@ public function resolve(
9595
* @param Wishlist $wishlist
9696
* @param array $args
9797
* @return WishlistItemCollection
98+
* @throws LocalizedException
9899
*/
99100
private function getWishListItems(Wishlist $wishlist, array $args): WishlistItemCollection
100101
{
@@ -104,8 +105,11 @@ private function getWishListItems(Wishlist $wishlist, array $args): WishlistItem
104105
/** @var WishlistItemCollection $wishlistItemCollection */
105106
$wishlistItemCollection = $this->wishlistItemCollectionFactory->create();
106107
$wishlistItemCollection->addWishlistFilter($wishlist);
107-
if (isset($args['store_id'])) {
108-
$wishlistItemCollection->addStoreFilter($args['store_id']);
108+
if (isset($args['website_id']) && $args['website_id']) {
109+
$website = $this->storeManager->getWebsite($args['website_id']);
110+
foreach ($website->getStores() as $store) {
111+
$wishlistItemCollection->addStoreFilter($store->getId());
112+
}
109113
} else {
110114
$wishlistItemCollection->addStoreFilter(array_map(function (StoreInterface $store) {
111115
return $store->getId();

app/code/Magento/WishlistGraphQl/Test/Unit/Model/Resolver/WishlistItemsTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\GraphQl\Model\Query\ContextExtensionInterface;
1414
use Magento\Store\Api\Data\StoreInterface;
1515
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\Store\Model\Website;
1617
use Magento\Wishlist\Model\ResourceModel\Item;
1718
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
1819
use Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory as WishlistItemCollectionFactory;
@@ -49,18 +50,18 @@ protected function setUp(): void
4950
*/
5051
public function testResolve(): void
5152
{
52-
$storeId = $itemId = 1;
53+
$webId = $storeId = $itemId = 1;
5354

5455
$field = $this->createMock(Field::class);
5556
$context = $this->getMockBuilder(ContextInterface::class)
5657
->disableOriginalConstructor()
5758
->getMock();
5859
$store = $this->createMock(StoreInterface::class);
59-
$store->expects($this->once())->method('getId')->willReturn($storeId);
60+
$store->expects($this->once())->method('getWebsiteId')->willReturn($webId);
61+
$store->expects($this->any())->method('getId')->willReturn($storeId);
6062

6163
$extensionAttributes = $this->getMockBuilder(ContextExtensionInterface::class)
6264
->disableOriginalConstructor()
63-
->addMethods(['getStore'])
6465
->getMock();
6566
$extensionAttributes->expects($this->exactly(2))
6667
->method('getStore')
@@ -100,6 +101,10 @@ public function testResolve(): void
100101
->method('create')
101102
->willReturn($wishlistCollection);
102103

104+
$website = $this->createMock(Website::class);
105+
$website->expects($this->any())->method('getStores')->willReturn([$store]);
106+
$this->storeManager->expects($this->once())->method('getWebsite')->with($webId)->willReturn($website);
107+
103108
$resolver = new WishlistItems($this->wishlistItemCollectionFactory, $this->storeManager);
104109
$resolver->resolve($field, $context, $info, ['model' => $wishlist]);
105110
}

0 commit comments

Comments
 (0)