Skip to content

Commit 8b83782

Browse files
committed
Merge remote-tracking branch 'act4/ACP2E-3987' into PR_25_June_odubovyk
2 parents 465e5c7 + f50d4f0 commit 8b83782

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

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

Lines changed: 11 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,15 @@ 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+
$stores = [];
111+
foreach ($website->getStores() as $store) {
112+
$stores[] = $store->getId();
113+
}
114+
if ($stores) {
115+
$wishlistItemCollection->addStoreFilter($stores);
116+
}
109117
} else {
110118
$wishlistItemCollection->addStoreFilter(array_map(function (StoreInterface $store) {
111119
return $store->getId();

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
namespace Magento\WishlistGraphQl\Test\Unit\Model\Resolver;
99

1010
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
11+
use Magento\GraphQl\Model\Query\ContextExtensionInterface;
1112
use Magento\GraphQl\Model\Query\ContextInterface;
1213
use Magento\Framework\GraphQl\Config\Element\Field;
13-
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;
@@ -21,6 +22,9 @@
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use PHPUnit\Framework\TestCase;
2324

25+
/**
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
*/
2428
class WishlistItemsTest extends TestCase
2529
{
2630
/**
@@ -49,14 +53,13 @@ protected function setUp(): void
4953
*/
5054
public function testResolve(): void
5155
{
52-
$storeId = $itemId = 1;
56+
$webId = $storeId = $itemId = 1;
5357

5458
$field = $this->createMock(Field::class);
55-
$context = $this->getMockBuilder(ContextInterface::class)
56-
->disableOriginalConstructor()
57-
->getMock();
59+
$context = $this->createMock(ContextInterface::class);
5860
$store = $this->createMock(StoreInterface::class);
59-
$store->expects($this->once())->method('getId')->willReturn($storeId);
61+
$store->expects($this->once())->method('getWebsiteId')->willReturn($webId);
62+
$store->expects($this->any())->method('getId')->willReturn($storeId);
6063

6164
$extensionAttributes = $this->getMockBuilder(ContextExtensionInterface::class)
6265
->disableOriginalConstructor()
@@ -87,7 +90,7 @@ public function testResolve(): void
8790
->willReturnSelf();
8891
$wishlistCollection->expects($this->once())
8992
->method('addStoreFilter')
90-
->with($storeId)
93+
->with([$storeId])
9194
->willReturnSelf();
9295
$wishlistCollection->expects($this->once())->method('setVisibilityFilter')->willReturnSelf();
9396
$wishlistCollection->expects($this->once())->method('setCurPage')->willReturnSelf();
@@ -100,6 +103,10 @@ public function testResolve(): void
100103
->method('create')
101104
->willReturn($wishlistCollection);
102105

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

0 commit comments

Comments
 (0)