Skip to content

Commit bff13d9

Browse files
committed
Merge remote-tracking branch 'origin/imported-magento-magento2-32275' into 2.4-develop-pr131
2 parents da59a6a + f2c831b commit bff13d9

File tree

2 files changed

+43
-0
lines changed
  • app/code/Magento/Wishlist/Controller/Index
  • dev/tests/integration/testsuite/Magento/Wishlist/Controller/Index

2 files changed

+43
-0
lines changed

app/code/Magento/Wishlist/Controller/Index/Cart.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ public function execute()
216216

217217
$item->mergeBuyRequest($buyRequest);
218218
$item->addToCart($this->cart, true);
219+
220+
$related = $this->getRequest()->getParam('related_product');
221+
if (!empty($related)) {
222+
$this->cart->addProductsByIds(explode(',', $related));
223+
}
224+
219225
$this->cart->save()->getQuote()->collectTotals();
220226
$wishlist->save();
221227

dev/tests/integration/testsuite/Magento/Wishlist/Controller/Index/CartTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Wishlist\Controller\Index;
99

10+
use Magento\Catalog\Api\ProductRepositoryInterface;
1011
use Magento\Checkout\Model\CartFactory;
1112
use Magento\Customer\Model\Session;
1213
use Magento\Framework\App\Request\Http as HttpRequest;
@@ -35,6 +36,9 @@ class CartTest extends AbstractController
3536
/** @var Escaper */
3637
private $escaper;
3738

39+
/** @var ProductRepositoryInterface */
40+
private $productRepository;
41+
3842
/**
3943
* @inheritdoc
4044
*/
@@ -46,6 +50,7 @@ protected function setUp(): void
4650
$this->getWishlistByCustomerId = $this->_objectManager->get(GetWishlistByCustomerId::class);
4751
$this->cartFactory = $this->_objectManager->get(CartFactory::class);
4852
$this->escaper = $this->_objectManager->get(Escaper::class);
53+
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
4954
}
5055

5156
/**
@@ -107,6 +112,38 @@ public function testAddNotExistingItemToCart(): void
107112
$this->assertRedirect($this->stringContains('wishlist/index/'));
108113
}
109114

115+
/**
116+
* Add wishlist item with related Products to Cart.
117+
*
118+
* @return void
119+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
120+
* @magentoDataFixture Magento/Catalog/_files/products.php
121+
*/
122+
public function testAddItemWithRelatedProducts(): void
123+
{
124+
$firstProductId = $this->productRepository->get('simple')->getId();
125+
$secondProductID = $this->productRepository->get('custom-design-simple-product')->getId();
126+
$relatedIds = $expectedAddedIds = [$firstProductId, $secondProductID];
127+
128+
$this->customerSession->setCustomerId(1);
129+
$item = $this->getWishlistByCustomerId->getItemBySku(1, 'simple-1');
130+
$this->assertNotNull($item);
131+
132+
$this->performAddToCartRequest([
133+
'item' => $item->getId(),
134+
'qty' => 1,
135+
'related_product' => implode(',', $relatedIds),
136+
]);
137+
138+
$this->assertCount(0, $this->getWishlistByCustomerId->execute(1)->getItemCollection());
139+
$cart = $this->cartFactory->create();
140+
$this->assertEquals(3, $cart->getItemsCount());
141+
$expectedAddedIds[] = $item->getProductId();
142+
foreach ($expectedAddedIds as $addedId) {
143+
$this->assertContains($addedId, $cart->getProductIds());
144+
}
145+
}
146+
110147
/**
111148
* Perform request add to cart from wish list.
112149
*

0 commit comments

Comments
 (0)