Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/imported-magento-magento2-32275'…
Browse files Browse the repository at this point in the history
… into 2.4-develop-pr131
  • Loading branch information
zakdma committed Mar 3, 2021
2 parents da59a6a + f2c831b commit bff13d9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/code/Magento/Wishlist/Controller/Index/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ public function execute()

$item->mergeBuyRequest($buyRequest);
$item->addToCart($this->cart, true);

$related = $this->getRequest()->getParam('related_product');
if (!empty($related)) {
$this->cart->addProductsByIds(explode(',', $related));
}

$this->cart->save()->getQuote()->collectTotals();
$wishlist->save();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\Wishlist\Controller\Index;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Checkout\Model\CartFactory;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Request\Http as HttpRequest;
Expand Down Expand Up @@ -35,6 +36,9 @@ class CartTest extends AbstractController
/** @var Escaper */
private $escaper;

/** @var ProductRepositoryInterface */
private $productRepository;

/**
* @inheritdoc
*/
Expand All @@ -46,6 +50,7 @@ protected function setUp(): void
$this->getWishlistByCustomerId = $this->_objectManager->get(GetWishlistByCustomerId::class);
$this->cartFactory = $this->_objectManager->get(CartFactory::class);
$this->escaper = $this->_objectManager->get(Escaper::class);
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
}

/**
Expand Down Expand Up @@ -107,6 +112,38 @@ public function testAddNotExistingItemToCart(): void
$this->assertRedirect($this->stringContains('wishlist/index/'));
}

/**
* Add wishlist item with related Products to Cart.
*
* @return void
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
* @magentoDataFixture Magento/Catalog/_files/products.php
*/
public function testAddItemWithRelatedProducts(): void
{
$firstProductId = $this->productRepository->get('simple')->getId();
$secondProductID = $this->productRepository->get('custom-design-simple-product')->getId();
$relatedIds = $expectedAddedIds = [$firstProductId, $secondProductID];

$this->customerSession->setCustomerId(1);
$item = $this->getWishlistByCustomerId->getItemBySku(1, 'simple-1');
$this->assertNotNull($item);

$this->performAddToCartRequest([
'item' => $item->getId(),
'qty' => 1,
'related_product' => implode(',', $relatedIds),
]);

$this->assertCount(0, $this->getWishlistByCustomerId->execute(1)->getItemCollection());
$cart = $this->cartFactory->create();
$this->assertEquals(3, $cart->getItemsCount());
$expectedAddedIds[] = $item->getProductId();
foreach ($expectedAddedIds as $addedId) {
$this->assertContains($addedId, $cart->getProductIds());
}
}

/**
* Perform request add to cart from wish list.
*
Expand Down

0 comments on commit bff13d9

Please sign in to comment.