Skip to content

Commit fa53b0f

Browse files
committed
Merge remote-tracking branch 'origin/MC-36250' into 2.4-develop-pr36
2 parents 4887758 + 7cb33b0 commit fa53b0f

File tree

8 files changed

+123
-10
lines changed

8 files changed

+123
-10
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Model\Adminhtml\ResourceModel\Item\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
12+
use Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface;
13+
14+
/**
15+
* Wishlist items products collection builder for adminhtml area
16+
*/
17+
class CollectionBuilder implements CollectionBuilderInterface
18+
{
19+
/**
20+
* @inheritDoc
21+
*/
22+
public function build(WishlistItemCollection $wishlistItemCollection, Collection $productCollection): Collection
23+
{
24+
return $productCollection;
25+
}
26+
}

app/code/Magento/Wishlist/Model/ResourceModel/Item/Collection.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\EntityManager\MetadataPool;
1313
use Magento\Sales\Model\ConfigInterface;
14+
use Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface;
1415

1516
/**
1617
* Wishlist item collection
@@ -157,6 +158,10 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
157158
* @var ConfigInterface
158159
*/
159160
private $salesConfig;
161+
/**
162+
* @var CollectionBuilderInterface
163+
*/
164+
private $productCollectionBuilder;
160165

161166
/**
162167
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
@@ -178,8 +183,8 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
178183
* @param \Magento\Framework\App\State $appState
179184
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
180185
* @param TableMaintainer|null $tableMaintainer
181-
* @param ConfigInterface|null $salesConfig
182-
*
186+
* @param ConfigInterface|null $salesConfig
187+
* @param CollectionBuilderInterface|null $productCollectionBuilder
183188
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
184189
*/
185190
public function __construct(
@@ -202,7 +207,8 @@ public function __construct(
202207
\Magento\Framework\App\State $appState,
203208
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
204209
TableMaintainer $tableMaintainer = null,
205-
ConfigInterface $salesConfig = null
210+
ConfigInterface $salesConfig = null,
211+
?CollectionBuilderInterface $productCollectionBuilder = null
206212
) {
207213
$this->stockConfiguration = $stockConfiguration;
208214
$this->_adminhtmlSales = $adminhtmlSales;
@@ -219,6 +225,8 @@ public function __construct(
219225
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
220226
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
221227
$this->salesConfig = $salesConfig ?: ObjectManager::getInstance()->get(ConfigInterface::class);
228+
$this->productCollectionBuilder = $productCollectionBuilder
229+
?: ObjectManager::getInstance()->get(CollectionBuilderInterface::class);
222230
}
223231

224232
/**
@@ -309,12 +317,10 @@ protected function _assignProducts()
309317
$productCollection->setVisibility($this->_productVisibility->getVisibleInSiteIds());
310318
}
311319

312-
$productCollection->addPriceData()
313-
->addTaxPercents()
314-
->addIdFilter($this->_productIds)
315-
->addAttributeToSelect($this->_wishlistConfig->getProductAttributes())
316-
->addOptionsToResult()
317-
->addUrlRewrite();
320+
$productCollection->addIdFilter($this->_productIds)
321+
->addAttributeToSelect($this->_wishlistConfig->getProductAttributes());
322+
323+
$productCollection = $this->productCollectionBuilder->build($this, $productCollection);
318324

319325
if ($this->_productSalable) {
320326
$productCollection = $this->_adminhtmlSales->applySalableProductTypesFilter($productCollection);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Model\ResourceModel\Item\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
12+
13+
/**
14+
* Wishlist items products collection builder
15+
*/
16+
class CollectionBuilder implements CollectionBuilderInterface
17+
{
18+
/**
19+
* @inheritDoc
20+
*/
21+
public function build(WishlistItemCollection $wishlistItemCollection, Collection $productCollection): Collection
22+
{
23+
return $productCollection->addPriceData()
24+
->addTaxPercents()
25+
->addOptionsToResult()
26+
->addUrlRewrite();
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Model\ResourceModel\Item\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
12+
13+
/**
14+
* Wishlist items products collection builder
15+
*/
16+
interface CollectionBuilderInterface
17+
{
18+
/**
19+
* Modify product collection
20+
*
21+
* @param WishlistItemCollection $wishlistItemCollection
22+
* @param Collection $productCollection
23+
* @return Collection
24+
*/
25+
public function build(WishlistItemCollection $wishlistItemCollection, Collection $productCollection): Collection;
26+
}

app/code/Magento/Wishlist/Model/Wishlist.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function getItemCollection()
383383
$this
384384
)->addStoreFilter(
385385
$this->getSharedStoreIds()
386-
)->setVisibilityFilter();
386+
)->setVisibilityFilter($this->_useCurrentWebsite);
387387
}
388388

389389
return $this->_itemCollection;
@@ -475,6 +475,7 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false
475475
$_buyRequest = $buyRequest;
476476
} elseif (is_string($buyRequest)) {
477477
$isInvalidItemConfiguration = false;
478+
$buyRequestData = [];
478479
try {
479480
$buyRequestData = $this->serializer->unserialize($buyRequest);
480481
if (!is_array($buyRequestData)) {
@@ -515,6 +516,7 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false
515516

516517
$errors = [];
517518
$items = [];
519+
$item = null;
518520

519521
foreach ($cartCandidates as $candidate) {
520522
if ($candidate->getParentProductId()) {

app/code/Magento/Wishlist/etc/adminhtml/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424
<type name="Magento\Catalog\Model\ResourceModel\Product">
2525
<plugin name="cleanups_wishlist_item_after_product_delete" type="Magento\Wishlist\Plugin\Model\ResourceModel\Product" />
2626
</type>
27+
<preference for="Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface"
28+
type="Magento\Wishlist\Model\Adminhtml\ResourceModel\Item\Product\CollectionBuilder"/>
2729
</config>

app/code/Magento/Wishlist/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@
7878
</argument>
7979
</arguments>
8080
</type>
81+
<preference for="Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface"
82+
type="Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilder"/>
8183
</config>

dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,27 @@ public function testUpdateNotExistingProductInWishList(): void
268268
$wishlist->updateItem($item, []);
269269
}
270270

271+
/**
272+
* Test that admin user should be able to update wishlist on second website
273+
*
274+
* @magentoAppArea adminhtml
275+
* @magentoDbIsolation disabled
276+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_on_second_website.php
277+
*
278+
* @return void
279+
*/
280+
public function testUpdateWishListItemOnSecondWebsite(): void
281+
{
282+
$wishlist = $this->getWishlistByCustomerId->execute(1);
283+
$item = $this->getWishlistByCustomerId->getItemBySku(1, 'simple-2');
284+
$this->assertNotNull($item);
285+
$this->assertEquals(1, $item->getQty());
286+
$buyRequest = $this->dataObjectFactory->create(['data' => ['qty' => 2]]);
287+
$wishlist->updateItem($item->getId(), $buyRequest);
288+
$updatedItem = $this->getWishlistByCustomerId->getItemBySku(1, 'simple-2');
289+
$this->assertEquals(2, $updatedItem->getQty());
290+
}
291+
271292
/**
272293
* Assert item in wish list.
273294
*

0 commit comments

Comments
 (0)