Skip to content

Commit 14eb322

Browse files
committed
MC-40417: Unexpected behavior when updating a Product with a Customizable Option (File) in the Wish List
1 parent a472e83 commit 14eb322

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Magento\Framework\Exception\NotFoundException;
1313
use Magento\Framework\Exception\NoSuchEntityException;
1414
use Magento\Framework\Controller\ResultFactory;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\UrlInterface;
17+
use Magento\Framework\App\Response\RedirectInterface;
1518

1619
/**
1720
* Wish list Add controller
@@ -40,31 +43,39 @@ class Add extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPost
4043
*/
4144
protected $formKeyValidator;
4245

46+
private $redirect;
47+
48+
private $urlBuilder;
49+
4350
/**
4451
* @param Action\Context $context
4552
* @param \Magento\Customer\Model\Session $customerSession
4653
* @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
4754
* @param ProductRepositoryInterface $productRepository
4855
* @param Validator $formKeyValidator
56+
* @param RedirectInterface $redirect
57+
* @param UrlInterface $urlBuilder
4958
*/
5059
public function __construct(
5160
Action\Context $context,
5261
\Magento\Customer\Model\Session $customerSession,
5362
\Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider,
5463
ProductRepositoryInterface $productRepository,
55-
Validator $formKeyValidator
64+
Validator $formKeyValidator,
65+
RedirectInterface $redirect = null,
66+
UrlInterface $urlBuilder = null
5667
) {
5768
$this->_customerSession = $customerSession;
5869
$this->wishlistProvider = $wishlistProvider;
5970
$this->productRepository = $productRepository;
6071
$this->formKeyValidator = $formKeyValidator;
72+
$this->redirect = $redirect ?: ObjectManager::getInstance()->get(RedirectInterface::class);
73+
$this->urlBuilder = $urlBuilder ?: ObjectManager::getInstance()->get(UrlInterface::class);
6174
parent::__construct($context);
6275
}
6376

6477
/**
65-
* Adding new item
66-
*
67-
* @return \Magento\Framework\Controller\Result\Redirect
78+
* @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
6879
* @throws NotFoundException
6980
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7081
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -153,7 +164,16 @@ public function execute()
153164
);
154165
}
155166

167+
if ($this->getRequest()->isAjax()) {
168+
$url = $this->urlBuilder->getUrl('*', $this->redirect->updatePathParams(['wishlist_id' => $wishlist->getId()]));
169+
/** @var Json $resultJson */
170+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
171+
$resultJson->setData(['backUrl' => $url]);
172+
173+
return $resultJson;
174+
}
156175
$resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]);
176+
157177
return $resultRedirect;
158178
}
159179
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontCustomerUpdateProductInWishlistActionGroup" extends="StorefrontCustomerAddProductToWishlistActionGroup">
12+
<annotations>
13+
<description>Updates the provided Product to the Wish List from the Storefront Product page. Validates that the Success Message is present and correct.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="productVar"/>
17+
</arguments>
18+
<see selector="{{StorefrontCustomerWishlistSection.successMsg}}" userInput="{{productVar.name}} has been updated in your Wish List." stepKey="addProductToWishlistSeeProductNameAddedToWishlist"/>
19+
</actionGroup>
20+
</actionGroups>

app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddSimpleProductWithCustomizableOptionsToWishlistTest.xml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<group value="wishlist"/>
1919
</annotations>
2020
<before>
21-
<!-- Create Data -->
2221
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
2322
<createData entity="_defaultCategory" stepKey="createCategory"/>
2423
<createData entity="SimpleProduct2" stepKey="createProduct">
@@ -29,14 +28,13 @@
2928
</updateData>
3029
</before>
3130
<after>
32-
<!-- Delete data -->
3331
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
3432
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
3533
<deleteData createDataKey="createProduct" stepKey="deleteProduct1"/>
3634
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
3735
</after>
3836

39-
<!-- 1. Login as a customer -->
37+
<!-- Login as a customer -->
4038
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount">
4139
<argument name="Customer" value="$createCustomer$"/>
4240
</actionGroup>
@@ -48,26 +46,25 @@
4846
<attachFile userInput="adobe-base.jpg" selector="{{StorefrontProductInfoMainSection.addLinkFileUploadFile(ProductOptionFile.title)}}" stepKey="fillUploadFile"/>
4947

5048
<!-- Add product to the wishlist -->
51-
<click selector="{{StorefrontProductInfoMainSection.productAddToWishlist}}" stepKey="addProductToWishlistClickAddToWishlist"/>
52-
<waitForElement selector="{{StorefrontCustomerWishlistSection.successMsg}}" time="30" stepKey="addProductToWishlistWaitForSuccessMessage"/>
53-
<amOnPage url="{{StorefrontCustomerWishlistPage.url}}" stepKey="amOnWishListPage"/>
54-
<waitForPageLoad stepKey="waitForWishlistPageLoad"/>
49+
<actionGroup ref="StorefrontCustomerAddProductToWishlistActionGroup" stepKey="addProductWithOptionToWishlist">
50+
<argument name="productVar" value="$createProduct$"/>
51+
</actionGroup>
5552

5653
<!-- Assert product is present in wishlist -->
5754
<actionGroup ref="AssertProductIsPresentInWishListActionGroup" stepKey="assertProductPresent">
5855
<argument name="productName" value="$createProduct.name$"/>
5956
<argument name="productPrice" value="$109.99"/>
6057
</actionGroup>
6158

59+
<!-- Edit wishlist product -->
6260
<actionGroup ref="StorefrontCustomerUpdateWishlistItemActionGroup" stepKey="clickEditWishlistItem">
6361
<argument name="productName" value="$createProduct.name$"/>
6462
</actionGroup>
6563

66-
<click selector="{{StorefrontProductInfoMainSection.productAddToWishlist}}" stepKey="addProductToWishlistClickAddToWishlist2"/>
67-
<waitForElement selector="{{StorefrontCustomerWishlistSection.successMsg}}" time="30" stepKey="addProductToWishlistWaitForSuccessMessage2"/>
68-
69-
<amOnPage url="{{StorefrontCustomerWishlistPage.url}}" stepKey="amOnWishListPage2"/>
70-
<waitForPageLoad stepKey="waitForWishlistPageLoad2"/>
64+
<!-- Update product in wishlist from product page -->
65+
<actionGroup ref="StorefrontCustomerUpdateProductInWishlistActionGroup" stepKey="updateProductWithOptionInWishlist">
66+
<argument name="productVar" value="$createProduct$"/>
67+
</actionGroup>
7168

7269
<actionGroup ref="AssertProductIsPresentInWishListActionGroup" stepKey="assertProductPresent2">
7370
<argument name="productName" value="$createProduct.name$"/>

0 commit comments

Comments
 (0)