Skip to content

Commit 9909d00

Browse files
authored
Merge pull request #2879 from magento-arcticfoxes/MAGETWO-91433
[2.3.0-Regression] MAGETWO-91433
2 parents fe2ed1b + d3d9257 commit 9909d00

File tree

15 files changed

+270
-40
lines changed

15 files changed

+270
-40
lines changed

app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontCategoryActionGroup.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@
4545
<!-- @TODO: MAGETWO-80272 Move to Magento_Checkout -->
4646
<seeElement selector="{{StorefrontCategoryProductSection.ProductAddToCartByName(product.name)}}" stepKey="AssertAddToCart" />
4747
</actionGroup>
48-
</actionGroups>
48+
49+
<actionGroup name="StorefrontSwitchCategoryViewToListMode">
50+
<click selector="{{StorefrontCategoryMainSection.modeListButton}}" stepKey="switchCategoryViewToListMode"/>
51+
<waitForElement selector="{{StorefrontCategoryMainSection.CategoryTitle}}" time="30" stepKey="waitForCategoryReload"/>
52+
</actionGroup>
53+
</actionGroups>

app/code/Magento/Store/App/Response/Redirect.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ public function __construct(
7777

7878
/**
7979
* @return string
80+
* @throws \Magento\Framework\Exception\NoSuchEntityException
8081
*/
8182
protected function _getUrl()
8283
{
8384
$refererUrl = $this->_request->getServer('HTTP_REFERER');
84-
$url = (string)$this->_request->getParam(self::PARAM_NAME_REFERER_URL);
85-
if ($url) {
86-
$refererUrl = $url;
87-
}
88-
$url = $this->_request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_BASE64_URL);
89-
if ($url) {
90-
$refererUrl = $this->_urlCoder->decode($url);
91-
}
92-
$url = $this->_request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED);
93-
if ($url) {
94-
$refererUrl = $this->_urlCoder->decode($url);
85+
$encodedUrl = $this->_request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED)
86+
?: $this->_request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_BASE64_URL);
87+
88+
if ($encodedUrl) {
89+
$refererUrl = $this->_urlCoder->decode($encodedUrl);
90+
} else {
91+
$url = (string)$this->_request->getParam(self::PARAM_NAME_REFERER_URL);
92+
if ($url) {
93+
$refererUrl = $url;
94+
}
9595
}
9696

9797
if (!$this->_isUrlInternal($refererUrl)) {

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Framework\Exception\NotFoundException;
1111
use Magento\Framework\Controller\ResultFactory;
1212
use Magento\Wishlist\Controller\WishlistProviderInterface;
13+
use Magento\Wishlist\Model\Item;
14+
use Magento\Wishlist\Model\Product\AttributeValueProvider;
1315

1416
/**
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -26,18 +28,27 @@ class Remove extends \Magento\Wishlist\Controller\AbstractIndex
2628
*/
2729
protected $formKeyValidator;
2830

31+
/**
32+
* @var AttributeValueProvider
33+
*/
34+
private $attributeValueProvider;
35+
2936
/**
3037
* @param Action\Context $context
3138
* @param WishlistProviderInterface $wishlistProvider
3239
* @param Validator $formKeyValidator
40+
* @param AttributeValueProvider|null $attributeValueProvider
3341
*/
3442
public function __construct(
3543
Action\Context $context,
3644
WishlistProviderInterface $wishlistProvider,
37-
Validator $formKeyValidator
45+
Validator $formKeyValidator,
46+
AttributeValueProvider $attributeValueProvider = null
3847
) {
3948
$this->wishlistProvider = $wishlistProvider;
4049
$this->formKeyValidator = $formKeyValidator;
50+
$this->attributeValueProvider = $attributeValueProvider
51+
?: \Magento\Framework\App\ObjectManager::getInstance()->get(AttributeValueProvider::class);
4152
parent::__construct($context);
4253
}
4354

@@ -56,7 +67,8 @@ public function execute()
5667
}
5768

5869
$id = (int)$this->getRequest()->getParam('item');
59-
$item = $this->_objectManager->create(\Magento\Wishlist\Model\Item::class)->load($id);
70+
/** @var Item $item */
71+
$item = $this->_objectManager->create(Item::class)->load($id);
6072
if (!$item->getId()) {
6173
throw new NotFoundException(__('Page not found.'));
6274
}
@@ -67,6 +79,14 @@ public function execute()
6779
try {
6880
$item->delete();
6981
$wishlist->save();
82+
$productName = $this->attributeValueProvider
83+
->getRawAttributeValue($item->getProductId(), 'name');
84+
$this->messageManager->addComplexSuccessMessage(
85+
'removeWishlistItemSuccessMessage',
86+
[
87+
'product_name' => $productName,
88+
]
89+
);
7090
} catch (\Magento\Framework\Exception\LocalizedException $e) {
7191
$this->messageManager->addError(
7292
__('We can\'t delete the item from Wish List right now because of an error: %1.', $e->getMessage())
@@ -76,13 +96,8 @@ public function execute()
7696
}
7797

7898
$this->_objectManager->get(\Magento\Wishlist\Helper\Data::class)->calculate();
79-
$request = $this->getRequest();
80-
$refererUrl = (string)$request->getServer('HTTP_REFERER');
81-
$url = (string)$request->getParam(\Magento\Framework\App\Response\RedirectInterface::PARAM_NAME_REFERER_URL);
82-
if ($url) {
83-
$refererUrl = $url;
84-
}
85-
if ($request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED) && $refererUrl) {
99+
$refererUrl = $this->_redirect->getRefererUrl();
100+
if ($refererUrl) {
86101
$redirectUrl = $refererUrl;
87102
} else {
88103
$redirectUrl = $this->_redirect->getRedirectUrl($this->_url->getUrl('*/*'));

app/code/Magento/Wishlist/CustomerData/Wishlist.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
146146
),
147147
'product_is_saleable_and_visible' => $product->isSaleable() && $product->isVisibleInSiteVisibility(),
148148
'product_has_required_options' => $product->getTypeInstance()->hasRequiredOptions($product),
149-
'add_to_cart_params' => $this->wishlistHelper->getAddToCartParams($wishlistItem, true),
150-
'delete_item_params' => $this->wishlistHelper->getRemoveParams($wishlistItem, true),
149+
'add_to_cart_params' => $this->wishlistHelper->getAddToCartParams($wishlistItem),
150+
'delete_item_params' => $this->wishlistHelper->getRemoveParams($wishlistItem),
151151
];
152152
}
153153

app/code/Magento/Wishlist/Helper/Data.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,12 @@ public function getRemoveParams($item, $addReferer = false)
284284
{
285285
$url = $this->_getUrl('wishlist/index/remove');
286286
$params = ['item' => $item->getWishlistItemId()];
287+
$params[ActionInterface::PARAM_NAME_URL_ENCODED] = '';
288+
287289
if ($addReferer) {
288290
$params = $this->addRefererToParams($params);
289291
}
292+
290293
return $this->_postDataHelper->getPostData($url, $params);
291294
}
292295

@@ -395,9 +398,12 @@ public function getAddToCartUrl($item)
395398
public function getAddToCartParams($item, $addReferer = false)
396399
{
397400
$params = $this->_getCartUrlParameters($item);
401+
$params[ActionInterface::PARAM_NAME_URL_ENCODED] = '';
402+
398403
if ($addReferer) {
399404
$params = $this->addRefererToParams($params);
400405
}
406+
401407
return $this->_postDataHelper->getPostData(
402408
$this->_getUrlStore($item)->getUrl('wishlist/index/cart'),
403409
$params
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
11+
12+
/**
13+
* Provides existing attribute value for a product entity.
14+
*/
15+
class AttributeValueProvider
16+
{
17+
/**
18+
* @var ProductCollectionFactory
19+
*/
20+
private $productCollectionFactory;
21+
22+
/**
23+
* @param ProductCollectionFactory $productCollectionFactory
24+
*/
25+
public function __construct(
26+
ProductCollectionFactory $productCollectionFactory
27+
) {
28+
$this->productCollectionFactory = $productCollectionFactory;
29+
}
30+
31+
/**
32+
* Provides existing raw attribute value by the attribute code of the product entity.
33+
*
34+
* @param int $productId
35+
* @param string $attributeCode
36+
* @param int|null $storeId
37+
* @return null|string
38+
*/
39+
public function getRawAttributeValue(int $productId, string $attributeCode, int $storeId = null):? string
40+
{
41+
$collection = $this->productCollectionFactory->create();
42+
$collection->addIdFilter($productId)
43+
->addStoreFilter($storeId)
44+
->addAttributeToSelect($attributeCode);
45+
46+
if ($collection->isEnabledFlat()) {
47+
$data = $collection->getConnection()->fetchRow($collection->getSelect());
48+
$attributeValue = $data[$attributeCode] ?? null;
49+
} else {
50+
$attributeValue = $collection->getFirstItem()->getData($attributeCode);
51+
}
52+
53+
return $attributeValue;
54+
}
55+
}

app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontCustomerWishlistActionGroup.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,24 @@
5353
<seeElement selector="{{StorefrontCustomerWishlistSidebarSection.ProductAddToCartByName(productVar.name)}}" stepKey="AssertWishlistSidebarAddToCart" />
5454
<seeElement selector="{{StorefrontCustomerWishlistSidebarSection.ProductImageByName(productVar.name)}}" stepKey="AssertWishlistSidebarProductImage" />
5555
</actionGroup>
56-
</actionGroups>
56+
57+
<!--Remove a product from the wishlist using the sidebar -->
58+
<actionGroup name="StorefrontCustomerRemoveProductFromWishlistUsingSidebar">
59+
<arguments>
60+
<argument name="product"/>
61+
</arguments>
62+
<click selector="{{StorefrontCustomerWishlistSidebarSection.ProductRemoveByName(product.name)}}" stepKey="RemoveProductFromWishlistUsingSidebarClickRemoveItemFromWishlist"/>
63+
<waitForElement selector="{{StorefrontCategoryMainSection.SuccessMsg}}" time="30" stepKey="RemoveProductFromWishlistUsingSidebarWaitForSuccessMessage"/>
64+
<see selector="{{StorefrontCategoryMainSection.SuccessMsg}}" userInput="{{product.name}} has been removed from your Wish List." stepKey="RemoveProductFromWishlistUsingSidebarSeeProductNameRemovedFromWishlist"/>
65+
</actionGroup>
66+
67+
<!--Add a product to the cart from the wishlist using the sidebar -->
68+
<actionGroup name="StorefrontCustomerAddProductToCartFromWishlistUsingSidebar">
69+
<arguments>
70+
<argument name="product"/>
71+
</arguments>
72+
<click selector="{{StorefrontCustomerWishlistSidebarSection.ProductAddToCartByName(product.name)}}" stepKey="AddProductToCartFromWishlistUsingSidebarClickAddToCartFromWishlist"/>
73+
<waitForElement selector="{{StorefrontCategoryMainSection.SuccessMsg}}" time="30" stepKey="AddProductToCartFromWishlistUsingSidebarWaitForSuccessMessage"/>
74+
<see selector="{{StorefrontCategoryMainSection.SuccessMsg}}" userInput="You added {{product.name}} to your shopping cart." stepKey="AddProductToCartFromWishlistUsingSidebarSeeProductNameAddedToCartFromWishlist"/>
75+
</actionGroup>
76+
</actionGroups>

app/code/Magento/Wishlist/Test/Mftf/Section/StorefrontCustomerWishlistSidebarSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<element name="ProductImageByName" type="text" selector="//main//ol[@id='wishlist-sidebar']//a[@class='product-item-link']/span[text()='{{var1}}']//ancestor::ol//img[@class='product-image-photo']" parameterized="true"/>
1515
<element name="ProductAddToCartByName" type="button" selector="//main//ol[@id='wishlist-sidebar']//a[@class='product-item-link']/span[text()='{{var1}}']//ancestor::ol//button[contains(@class, 'action tocart primary')]" parameterized="true"/>
1616
<element name="ProductImageByImageName" type="text" selector="//main//ol[@id='wishlist-sidebar']//a//img[contains(@src, '{{var1}}')]" parameterized="true"/>
17+
<element name="ProductRemoveByName" type="button" selector="//main//ol[@id='wishlist-sidebar']//a[@class='product-item-link']/span[text()='{{var1}}']//ancestor::ol//a[contains(@class, 'action delete')]" parameterized="true"/>
1718
</section>
1819
</sections>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
10+
<test name="StorefrontAddProductsToCartFromWishlistUsingSidebarTest">
11+
<annotations>
12+
<title value="Add products from the wishlist to the cart using the sidebar."/>
13+
<description value="Products added to the cart from wishlist and a customer remains on the same page."/>
14+
<group value="wishlist"/>
15+
</annotations>
16+
<before>
17+
<createData entity="SimpleSubCategory" stepKey="categoryFirst"/>
18+
<createData entity="SimpleSubCategory" stepKey="categorySecond"/>
19+
<createData entity="SimpleProduct" stepKey="simpleProduct1">
20+
<requiredEntity createDataKey="categoryFirst"/>
21+
</createData>
22+
<createData entity="SimpleProduct" stepKey="simpleProduct2">
23+
<requiredEntity createDataKey="categorySecond"/>
24+
</createData>
25+
<createData entity="Simple_US_Customer" stepKey="customer"/>
26+
</before>
27+
<after>
28+
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
29+
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
30+
<deleteData createDataKey="categoryFirst" stepKey="deleteCategoryFirst"/>
31+
<deleteData createDataKey="categorySecond" stepKey="deleteCategorySecond"/>
32+
<deleteData createDataKey="customer" stepKey="deleteCustomer"/>
33+
</after>
34+
<!-- Sign in as customer -->
35+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount">
36+
<argument name="Customer" value="$$customer$$"/>
37+
</actionGroup>
38+
<!-- Add product from first category to the wishlist -->
39+
<amOnPage url="{{StorefrontCategoryPage.url($$categoryFirst.name$$)}}" stepKey="navigateToCategoryFirstPage"/>
40+
<actionGroup ref="StorefrontCheckCategorySimpleProduct" stepKey="browseAssertCategoryProduct1">
41+
<argument name="product" value="$$simpleProduct1$$"/>
42+
</actionGroup>
43+
<actionGroup ref="StorefrontCustomerAddCategoryProductToWishlistActionGroup" stepKey="addSimpleProduct1ToWishlist">
44+
<argument name="productVar" value="$$simpleProduct1$$"/>
45+
</actionGroup>
46+
<!--Add product to the cart from the Wishlist using the sidebar from the second category page-->
47+
<amOnPage url="{{StorefrontCategoryPage.url($$categorySecond.name$$)}}" stepKey="navigateToCategorySecondPage"/>
48+
<actionGroup ref="StorefrontSwitchCategoryViewToListMode" stepKey="switchCategoryViewToListMode"/>
49+
<actionGroup ref="StorefrontCustomerCheckProductInWishlistSidebar" stepKey="checkSimpleProduct1InWishlistSidebar">
50+
<argument name="productVar" value="$$simpleProduct1$$"/>
51+
</actionGroup>
52+
<actionGroup ref="StorefrontCustomerAddProductToCartFromWishlistUsingSidebar" stepKey="addProduct1ToCartFromWishlistUsingSidebar">
53+
<argument name="product" value="$$simpleProduct1$$"/>
54+
</actionGroup>
55+
<!--Check that a customer on the same page as before-->
56+
<!--hardcoded URL because this method does not support replacement-->
57+
<seeCurrentUrlMatches regex="~\/$$categorySecond.name$$\.html\?(\S+)?\w+=list(&amp;\S+)?$~i" stepKey="seeCurrentCategoryUrlMatches"/>
58+
</test>
59+
</tests>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
10+
<test name="StorefrontRemoveProductsFromWishlistUsingSidebarTest">
11+
<annotations>
12+
<title value="Remove products from the wishlist using the sidebar."/>
13+
<description value="Products removed from wishlist and a customer remains on the same page."/>
14+
<group value="wishlist"/>
15+
</annotations>
16+
<before>
17+
<createData entity="SimpleSubCategory" stepKey="categoryFirst"/>
18+
<createData entity="SimpleSubCategory" stepKey="categorySecond"/>
19+
<createData entity="SimpleProduct" stepKey="simpleProduct1">
20+
<requiredEntity createDataKey="categoryFirst"/>
21+
</createData>
22+
<createData entity="SimpleProduct" stepKey="simpleProduct2">
23+
<requiredEntity createDataKey="categorySecond"/>
24+
</createData>
25+
<createData entity="Simple_US_Customer" stepKey="customer"/>
26+
</before>
27+
<after>
28+
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
29+
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
30+
<deleteData createDataKey="categoryFirst" stepKey="deleteCategoryFirst"/>
31+
<deleteData createDataKey="categorySecond" stepKey="deleteCategorySecond"/>
32+
<deleteData createDataKey="customer" stepKey="deleteCustomer"/>
33+
</after>
34+
<!-- Sign in as customer -->
35+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount">
36+
<argument name="Customer" value="$$customer$$"/>
37+
</actionGroup>
38+
<!-- Add product from first category to the wishlist -->
39+
<amOnPage url="{{StorefrontCategoryPage.url($$categoryFirst.name$$)}}" stepKey="navigateToCategoryFirstPage"/>
40+
<actionGroup ref="StorefrontCheckCategorySimpleProduct" stepKey="browseAssertCategoryProduct1">
41+
<argument name="product" value="$$simpleProduct1$$"/>
42+
</actionGroup>
43+
<actionGroup ref="StorefrontCustomerAddCategoryProductToWishlistActionGroup" stepKey="addSimpleProduct1ToWishlist">
44+
<argument name="productVar" value="$$simpleProduct1$$"/>
45+
</actionGroup>
46+
<!--Remove product from the Wishlist using the sidebar from the second category page-->
47+
<amOnPage url="{{StorefrontCategoryPage.url($$categorySecond.name$$)}}" stepKey="navigateToCategorySecondPage"/>
48+
<actionGroup ref="StorefrontSwitchCategoryViewToListMode" stepKey="switchCategoryViewToListMode"/>
49+
<actionGroup ref="StorefrontCustomerCheckProductInWishlistSidebar" stepKey="checkSimpleProduct1InWishlistSidebar">
50+
<argument name="productVar" value="$$simpleProduct1$$"/>
51+
</actionGroup>
52+
<actionGroup ref="StorefrontCustomerRemoveProductFromWishlistUsingSidebar" stepKey="removeProduct1FromWishlistUsingSidebar">
53+
<argument name="product" value="$$simpleProduct1$$"/>
54+
</actionGroup>
55+
<!--Check that a customer on the same page as before-->
56+
<!--hardcoded URL because this method does not support replacement-->
57+
<seeCurrentUrlMatches regex="~\/$$categorySecond.name$$\.html\?(\S+)?\w+=list(&amp;\S+)?$~i" stepKey="seeCurrentCategoryUrlMatches"/>
58+
</test>
59+
</tests>

0 commit comments

Comments
 (0)