Skip to content

Commit 483d4f1

Browse files
committed
MAGETWO-91433: ProductListing: Grid view is getting changed to List view when user adding product from wishlist section.
1 parent cfb5cfb commit 483d4f1

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,22 @@ 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+
89+
if ($encodedUrl) {
90+
$refererUrl = $this->_urlCoder->decode($encodedUrl);
91+
} else {
92+
$url = (string)$this->_request->getParam(self::PARAM_NAME_REFERER_URL);
93+
if ($url) {
94+
$refererUrl = $url;
95+
}
9596
}
9697

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

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Wishlist\Controller\Index;
77

8+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
89
use Magento\Framework\App\Action;
910
use Magento\Framework\Data\Form\FormKey\Validator;
1011
use Magento\Framework\Exception\NotFoundException;
@@ -27,18 +28,27 @@ class Remove extends \Magento\Wishlist\Controller\AbstractIndex
2728
*/
2829
protected $formKeyValidator;
2930

31+
/**
32+
* @var ProductCollectionFactory
33+
*/
34+
private $productCollectionFactory;
35+
3036
/**
3137
* @param Action\Context $context
3238
* @param WishlistProviderInterface $wishlistProvider
3339
* @param Validator $formKeyValidator
40+
* @param ProductCollectionFactory|null $productCollectionFactory
3441
*/
3542
public function __construct(
3643
Action\Context $context,
3744
WishlistProviderInterface $wishlistProvider,
38-
Validator $formKeyValidator
45+
Validator $formKeyValidator,
46+
ProductCollectionFactory $productCollectionFactory = null
3947
) {
4048
$this->wishlistProvider = $wishlistProvider;
4149
$this->formKeyValidator = $formKeyValidator;
50+
$this->productCollectionFactory = $productCollectionFactory
51+
?: \Magento\Framework\App\ObjectManager::getInstance()->get(ProductCollectionFactory::class);
4252
parent::__construct($context);
4353
}
4454

@@ -69,10 +79,15 @@ public function execute()
6979
try {
7080
$item->delete();
7181
$wishlist->save();
82+
$product = $this->productCollectionFactory
83+
->create()
84+
->addIdFilter($item->getProductId())
85+
->addAttributeToSelect('name')
86+
->getFirstItem();
7287
$this->messageManager->addComplexSuccessMessage(
7388
'removeWishlistItemSuccessMessage',
7489
[
75-
'product_name' => $item->getProduct()->getName()
90+
'product_name' => $product->getName()
7691
]
7792
);
7893
} catch (\Magento\Framework\Exception\LocalizedException $e) {

0 commit comments

Comments
 (0)