Skip to content

Commit 67cbd1f

Browse files
author
Sergey Semenov
committed
MAGETWO-36224: Success message is absent while adding product with options from wishlist to shopping cart
1 parent 98bd971 commit 67cbd1f

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ class Cart extends Action\Action implements IndexInterface
3636
*/
3737
protected $cart;
3838

39+
/**
40+
* @var \Magento\Checkout\Helper\Cart
41+
*/
42+
protected $cartHelper;
43+
44+
/**
45+
* @var \Magento\Framework\Json\Helper\Data
46+
*/
47+
protected $jsonHelper;
48+
3949
/**
4050
* @var \Magento\Wishlist\Model\Item\OptionFactory
4151
*/
@@ -76,7 +86,9 @@ public function __construct(
7686
\Magento\Wishlist\Model\Item\OptionFactory $optionFactory,
7787
\Magento\Catalog\Helper\Product $productHelper,
7888
\Magento\Framework\Escaper $escaper,
79-
\Magento\Wishlist\Helper\Data $helper
89+
\Magento\Wishlist\Helper\Data $helper,
90+
\Magento\Checkout\Helper\Cart $cartHelper,
91+
\Magento\Framework\Json\Helper\Data $jsonHelper
8092
) {
8193
$this->wishlistProvider = $wishlistProvider;
8294
$this->quantityProcessor = $quantityProcessor;
@@ -86,6 +98,8 @@ public function __construct(
8698
$this->productHelper = $productHelper;
8799
$this->escaper = $escaper;
88100
$this->helper = $helper;
101+
$this->cartHelper = $cartHelper;
102+
$this->jsonHelper = $jsonHelper;
89103
parent::__construct($context);
90104
}
91105

@@ -159,8 +173,8 @@ public function execute()
159173
$this->messageManager->addSuccess($message);
160174
}
161175

162-
if ($this->cart->getShouldRedirectToCart()) {
163-
$redirectUrl = $this->cart->getCartUrl();
176+
if ($this->cartHelper->getShouldRedirectToCart()) {
177+
$redirectUrl = $this->cartHelper->getCartUrl();
164178
} else {
165179
$refererUrl = $this->_redirect->getRefererUrl();
166180
if ($refererUrl && $refererUrl != $configureUrl) {
@@ -178,6 +192,13 @@ public function execute()
178192

179193
$this->helper->calculate();
180194

195+
if ($this->getRequest()->isAjax()) {
196+
$this->getResponse()->representJson(
197+
$this->jsonHelper->jsonEncode(['backUrl' => $redirectUrl])
198+
);
199+
return;
200+
}
201+
181202
return $this->getResponse()->setRedirect($redirectUrl);
182203
}
183204
}

app/code/Magento/Wishlist/view/frontend/templates/view.phtml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
<?php echo($block->getChildHtml('wishlist.rss.link'));?>
1414
<form class="form-wishlist-items" id="wishlist-view-form"
1515
data-mage-init='{"wishlist":{
16-
"dataAttribute":"item-id",
17-
"nameFormat":"qty[{0}]",
18-
"btnRemoveSelector":".action.delete",
19-
"qtySelector":".qty",
20-
"addToCartSelector":".action.tocart",
21-
"addAllToCartSelector":".primary > .action.tocart",
22-
"commentInputType":"textarea",
23-
"infoList":false,
2416
"addToCartUrl":"<?php echo $block->getItemAddToCartUrl("%item%");?>",
2517
"confirmRemoveMessage":"<?php echo __("Are you sure you want to remove this product from your wishlist?") ?>",
2618
"addAllToCartUrl":"<?php echo $block->getAddAllToCartUrl(); ?>",

app/code/Magento/Wishlist/view/frontend/web/wishlist.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ define([
8181
var itemId = elem.data(this.options.dataAttribute),
8282
url = this.options.addToCartUrl.replace('%item%', itemId),
8383
inputName = $.validator.format(this.options.nameFormat, itemId),
84-
inputValue = elem.parent().find('[name="' + inputName + '"]').val(),
84+
inputValue = $('[name="' + inputName + '"]').val(),
8585
separator = (url.indexOf('?') >= 0) ? '&' : '?';
8686
url += separator + inputName + '=' + encodeURIComponent(inputValue);
8787
this._validateAndRedirect(url);
8888
}
89-
9089
},
9190

9291
/**

dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,19 @@ protected function getPreset($name)
198198
'id' => '%id%',
199199
'name' => '%item1_simple::getProductName%',
200200
'position' => '%position%',
201-
'qty' => 17,
201+
'qty' => 3,
202202
],
203203
[
204204
'id' => '%id%',
205205
'name' => '%item1_simple::getProductName%',
206206
'position' => '%position%',
207-
'qty' => 36,
207+
'qty' => 1,
208208
],
209209
[
210210
'id' => '%id%',
211211
'name' => '%item1_simple::getProductName%',
212212
'position' => '%position%',
213-
'qty' => 20,
213+
'qty' => 2,
214214
],
215215
],
216216
'products' => [

dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli
3333
const DOMAIN = 'CS';
3434
/* end tags */
3535

36+
/**
37+
* Prepare data for test
38+
*
39+
* @param Customer $customer
40+
* @return array
41+
*/
42+
public function __prepare(Customer $customer)
43+
{
44+
$customer->persist();
45+
46+
return ['customer' => $customer];
47+
}
48+
3649
/**
3750
* Run suggest searching result test.
3851
*
@@ -43,9 +56,6 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli
4356
*/
4457
public function test(Customer $customer, $products, $qty)
4558
{
46-
$this->markTestIncomplete('Bug: MAGETWO-34757');
47-
// Preconditions
48-
$customer->persist();
4959
$this->loginCustomer($customer);
5060
$products = $this->createProducts($products);
5161
$this->addToWishlist($products);

0 commit comments

Comments
 (0)