Skip to content

Commit 79888d4

Browse files
author
Yuri Kovsher
committed
Merge remote-tracking branch 'main-ce/develop' into MAGETWO-36610
Conflicts: app/code/Magento/Wishlist/Controller/Index/Cart.php app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php
2 parents c6f5d6a + 385f475 commit 79888d4

File tree

9 files changed

+182
-35
lines changed

9 files changed

+182
-35
lines changed

app/code/Magento/Customer/Model/Resource/GroupRepository.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
164164

165165
/** @var \Magento\Customer\Model\Resource\Group\Collection $collection */
166166
$collection = $this->groupFactory->create()->getCollection();
167+
$collection->addTaxClass();
167168

168169
//Add filters from root filter group to the collection
169170
/** @var FilterGroup $group */
@@ -234,6 +235,8 @@ protected function translateField($field)
234235
return 'customer_group_code';
235236
case GroupInterface::ID:
236237
return 'customer_group_id';
238+
case GroupInterface::TAX_CLASS_NAME:
239+
return 'class_name';
237240
default:
238241
return $field;
239242
}

app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testGetCurrentStatus($status, $lastLoginAt, $lastVisitAt, $lastL
171171
'customer/online_customers/online_minutes_interval',
172172
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
173173
)
174-
->willReturn(60); //TODO: it's value mocked because unit tests run data providers before all testsuite
174+
->willReturn(240); //TODO: it's value mocked because unit tests run data providers before all testsuite
175175

176176
$this->customerLog->expects($this->any())->method('getLastLoginAt')->willReturn($lastLoginAt);
177177
$this->customerLog->expects($this->any())->method('getLastVisitAt')->willReturn($lastVisitAt);

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class Cart extends Action\Action implements IndexInterface
3535
*/
3636
protected $cart;
3737

38+
/**
39+
* @var \Magento\Checkout\Helper\Cart
40+
*/
41+
protected $cartHelper;
42+
3843
/**
3944
* @var \Magento\Wishlist\Model\Item\OptionFactory
4045
*/
@@ -65,6 +70,7 @@ class Cart extends Action\Action implements IndexInterface
6570
* @param \Magento\Catalog\Helper\Product $productHelper
6671
* @param \Magento\Framework\Escaper $escaper
6772
* @param \Magento\Wishlist\Helper\Data $helper
73+
* @param \Magento\Checkout\Helper\Cart $cartHelper
6874
*/
6975
public function __construct(
7076
Action\Context $context,
@@ -75,7 +81,8 @@ public function __construct(
7581
\Magento\Wishlist\Model\Item\OptionFactory $optionFactory,
7682
\Magento\Catalog\Helper\Product $productHelper,
7783
\Magento\Framework\Escaper $escaper,
78-
\Magento\Wishlist\Helper\Data $helper
84+
\Magento\Wishlist\Helper\Data $helper,
85+
\Magento\Checkout\Helper\Cart $cartHelper
7986
) {
8087
$this->wishlistProvider = $wishlistProvider;
8188
$this->quantityProcessor = $quantityProcessor;
@@ -85,6 +92,7 @@ public function __construct(
8592
$this->productHelper = $productHelper;
8693
$this->escaper = $escaper;
8794
$this->helper = $helper;
95+
$this->cartHelper = $cartHelper;
8896
parent::__construct($context);
8997
}
9098

@@ -94,7 +102,7 @@ public function __construct(
94102
* If Product has required options - item removed from wishlist and redirect
95103
* to product view page with message about needed defined required options
96104
*
97-
* @return \Magento\Framework\Controller\Result\Redirect
105+
* @return \Magento\Framework\Controller\ResultInterface
98106
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
99107
* @SuppressWarnings(PHPMD.NPathComplexity)
100108
*/
@@ -161,8 +169,8 @@ public function execute()
161169
$this->messageManager->addSuccess($message);
162170
}
163171

164-
if ($this->cart->getShouldRedirectToCart()) {
165-
$redirectUrl = $this->cart->getCartUrl();
172+
if ($this->cartHelper->getShouldRedirectToCart()) {
173+
$redirectUrl = $this->cartHelper->getCartUrl();
166174
} else {
167175
$refererUrl = $this->_redirect->getRefererUrl();
168176
if ($refererUrl && $refererUrl != $configureUrl) {
@@ -179,6 +187,14 @@ public function execute()
179187
}
180188

181189
$this->helper->calculate();
190+
191+
if ($this->getRequest()->isAjax()) {
192+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
193+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
194+
$resultJson->setData(['backUrl' => $redirectUrl]);
195+
return $resultJson;
196+
}
197+
182198
$resultRedirect->setUrl($redirectUrl);
183199
return $resultRedirect;
184200
}

app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class CartTest extends \PHPUnit_Framework_TestCase
9090
*/
9191
protected $urlMock;
9292

93+
/**
94+
* @var \Magento\Checkout\Helper\Cart|\PHPUnit_Framework_MockObject_MockObject
95+
*/
96+
protected $cartHelperMock;
97+
9398
/**
9499
* @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject
95100
*/
@@ -100,6 +105,11 @@ class CartTest extends \PHPUnit_Framework_TestCase
100105
*/
101106
protected $resultRedirectMock;
102107

108+
/**
109+
* @var \Magento\Framework\Controller\Result\Json|\PHPUnit_Framework_MockObject_MockObject
110+
*/
111+
protected $resultJsontMock;
112+
103113
/**
104114
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
105115
*/
@@ -143,7 +153,7 @@ protected function setUp()
143153

144154
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
145155
->disableOriginalConstructor()
146-
->setMethods(['getParams', 'getParam'])
156+
->setMethods(['getParams', 'getParam', 'isAjax'])
147157
->getMockForAbstractClass();
148158

149159
$this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface')
@@ -163,12 +173,18 @@ protected function setUp()
163173
->disableOriginalConstructor()
164174
->setMethods(['getUrl'])
165175
->getMockForAbstractClass();
176+
$this->cartHelperMock = $this->getMockBuilder('Magento\Checkout\Helper\Cart')
177+
->disableOriginalConstructor()
178+
->getMock();
166179
$this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory')
167180
->disableOriginalConstructor()
168181
->getMock();
169182
$this->resultRedirectMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect')
170183
->disableOriginalConstructor()
171184
->getMock();
185+
$this->resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Json')
186+
->disableOriginalConstructor()
187+
->getMock();
172188

173189
$this->contextMock = $this->getMockBuilder('Magento\Framework\App\Action\Context')
174190
->disableOriginalConstructor()
@@ -187,14 +203,19 @@ protected function setUp()
187203
->will($this->returnValue($this->messageManagerMock));
188204
$this->contextMock->expects($this->any())
189205
->method('getUrl')
190-
->will($this->returnValue($this->urlMock));
206+
->willReturn($this->urlMock);
191207
$this->contextMock->expects($this->any())
192208
->method('getResultFactory')
193209
->willReturn($this->resultFactoryMock);
194210
$this->resultFactoryMock->expects($this->any())
195211
->method('create')
196-
->with(ResultFactory::TYPE_REDIRECT, [])
197-
->willReturn($this->resultRedirectMock);
212+
->willReturnMap(
213+
[
214+
[ResultFactory::TYPE_REDIRECT, [], $this->resultRedirectMock],
215+
[ResultFactory::TYPE_JSON, [], $this->resultJsontMock]
216+
]
217+
);
218+
198219

199220
$this->model = new Cart(
200221
$this->contextMock,
@@ -205,7 +226,8 @@ protected function setUp()
205226
$this->optionFactoryMock,
206227
$this->productHelperMock,
207228
$this->escaperMock,
208-
$this->helperMock
229+
$this->helperMock,
230+
$this->cartHelperMock
209231
);
210232
}
211233

@@ -281,10 +303,36 @@ public function testExecuteWithNoWishlist()
281303
$this->assertSame($this->resultRedirectMock, $this->model->execute());
282304
}
283305

306+
public function testExecuteWithQuantityArray()
307+
{
308+
$refererUrl = $this->prepareExecuteWithQuantityArray();
309+
310+
$this->resultRedirectMock->expects($this->once())
311+
->method('setUrl')
312+
->with($refererUrl)
313+
->willReturnSelf();
314+
315+
$this->assertSame($this->resultRedirectMock, $this->model->execute());
316+
}
317+
318+
public function testExecuteWithQuantityArrayAjax()
319+
{
320+
$refererUrl = $this->prepareExecuteWithQuantityArray(true);
321+
322+
$this->resultJsonMock->expects($this->once())
323+
->method('setData')
324+
->with(['backUrl' => $redirectUrl])
325+
->willReturnSelf();
326+
327+
$this->assertSame($this->resultJsonMock, $this->model->execute());
328+
}
329+
284330
/**
331+
* @param bool $isAjax
332+
* @return array
285333
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
286334
*/
287-
public function testExecuteWithQuantityArray()
335+
protected function prepareExecuteWithQuantityArray($isAjax = false)
288336
{
289337
$itemId = 2;
290338
$wishlistId = 1;
@@ -404,6 +452,9 @@ public function testExecuteWithQuantityArray()
404452
$this->requestMock->expects($this->once())
405453
->method('getParams')
406454
->willReturn($params);
455+
$this->requestMock->expects($this->once())
456+
->method('isAjax')
457+
->willReturn(false);
407458

408459
$buyRequestMock = $this->getMockBuilder('Magento\Framework\Object')
409460
->disableOriginalConstructor()
@@ -474,7 +525,7 @@ public function testExecuteWithQuantityArray()
474525
->with('You added ' . $productName . ' to your shopping cart.', null)
475526
->willReturnSelf();
476527

477-
$this->checkoutCartMock->expects($this->once())
528+
$this->cartHelperMock->expects($this->once())
478529
->method('getShouldRedirectToCart')
479530
->willReturn(false);
480531

@@ -485,12 +536,8 @@ public function testExecuteWithQuantityArray()
485536
$this->helperMock->expects($this->once())
486537
->method('calculate')
487538
->willReturnSelf();
488-
$this->resultRedirectMock->expects($this->once())
489-
->method('setUrl')
490-
->with($refererUrl)
491-
->willReturnSelf();
492-
493-
$this->assertSame($this->resultRedirectMock, $this->model->execute());
539+
540+
return $refererUrl;
494541
}
495542

496543
/**

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.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,24 @@
3333
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
3434
</variation>
3535
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation5">
36-
<data name="issue" xsi:type="string">Bug: MAGETWO-36224</data>
3736
<data name="products" xsi:type="string">downloadableProduct::with_two_separately_links</data>
3837
<data name="qty" xsi:type="string">-</data>
3938
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
4039
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
4140
</variation>
4241
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation6">
43-
<data name="issue" xsi:type="string">Bug: MAGETWO-36224</data>
4442
<data name="products" xsi:type="string">configurableProduct::default</data>
4543
<data name="qty" xsi:type="string">3</data>
4644
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
4745
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
4846
</variation>
4947
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation7">
50-
<data name="issue" xsi:type="string">Bug: MAGETWO-36224</data>
5148
<data name="products" xsi:type="string">bundleProduct::bundle_dynamic_product</data>
5249
<data name="qty" xsi:type="string">2</data>
5350
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
5451
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
5552
</variation>
5653
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation8">
57-
<data name="issue" xsi:type="string">Bug: MAGETWO-36224</data>
5854
<data name="products" xsi:type="string">bundleProduct::bundle_fixed_product</data>
5955
<data name="qty" xsi:type="string">2</data>
6056
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />

0 commit comments

Comments
 (0)