Skip to content

Commit 6f39331

Browse files
author
OlgaVasyltsun
committed
Merge remote-tracking branch 'origin/2.4-develop' into MC-36048
2 parents 1f5c123 + de9332c commit 6f39331

File tree

20 files changed

+284
-531
lines changed

20 files changed

+284
-531
lines changed

app/code/Magento/GroupedProduct/Model/Wishlist/Product/Item.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GroupedProduct\Model\Wishlist\Product;
99

10+
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
1011
use Magento\Wishlist\Model\Item as WishlistItem;
1112
use Magento\GroupedProduct\Model\Product\Type\Grouped as TypeGrouped;
1213
use Magento\Catalog\Model\Product;
@@ -36,7 +37,7 @@ public function beforeRepresentProduct(
3637

3738
$diff = array_diff_key($itemOptions, $productOptions);
3839

39-
if (!$diff) {
40+
if (!$diff && $this->isAddAction($productOptions['info_buyRequest'])) {
4041
$buyRequest = $subject->getBuyRequest();
4142
$superGroupInfo = $buyRequest->getData('super_group');
4243

@@ -78,10 +79,13 @@ public function beforeCompareOptions(
7879
array $options2
7980
): array {
8081
$diff = array_diff_key($options1, $options2);
82+
$productOptions = isset($options1['info_buyRequest']['product']) ? $options1 : $options2;
8183

8284
if (!$diff) {
8385
foreach (array_keys($options1) as $key) {
84-
if (preg_match('/associated_product_\d+/', $key)) {
86+
if (preg_match('/associated_product_\d+/', $key)
87+
&& $this->isAddAction($productOptions['info_buyRequest'])
88+
) {
8589
unset($options1[$key]);
8690
unset($options2[$key]);
8791
}
@@ -90,4 +94,18 @@ public function beforeCompareOptions(
9094

9195
return [$options1, $options2];
9296
}
97+
98+
/**
99+
* Check that current request belongs to add to wishlist action.
100+
*
101+
* @param OptionInterface $buyRequest
102+
*
103+
* @return bool
104+
*/
105+
private function isAddAction(OptionInterface $buyRequest): bool
106+
{
107+
$requestValue = json_decode($buyRequest->getValue(), true);
108+
109+
return $requestValue['action'] === 'add';
110+
}
93111
}

app/code/Magento/GroupedProduct/Test/Unit/Model/Wishlist/Product/ItemTest.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,29 @@ public function testBeforeRepresentProduct()
115115
*/
116116
public function testBeforeCompareOptionsSameKeys()
117117
{
118-
$options1 = ['associated_product_34' => 3];
119-
$options2 = ['associated_product_34' => 2];
118+
$infoBuyRequestMock = $this->createPartialMock(
119+
\Magento\Catalog\Model\Product\Configuration\Item\Option::class,
120+
[
121+
'getValue',
122+
]
123+
);
124+
125+
$infoBuyRequestMock->expects($this->atLeastOnce())
126+
->method('getValue')
127+
->willReturn('{"product":"3","action":"add"}');
128+
$options1 = [
129+
'associated_product_34' => 3,
130+
'info_buyRequest' => $infoBuyRequestMock,
131+
];
132+
$options2 = [
133+
'associated_product_34' => 3,
134+
'info_buyRequest' => $infoBuyRequestMock,
135+
];
120136

121137
$res = $this->model->beforeCompareOptions($this->subjectMock, $options1, $options2);
122138

123-
$this->assertEquals([], $res[0]);
124-
$this->assertEquals([], $res[1]);
139+
$this->assertEquals(['info_buyRequest' => $infoBuyRequestMock], $res[0]);
140+
$this->assertEquals(['info_buyRequest' => $infoBuyRequestMock], $res[1]);
125141
}
126142

127143
/**
@@ -175,16 +191,26 @@ private function getProductAssocOption($initVal, $prodId)
175191
{
176192
$items = [];
177193

178-
$optionMock = $this->createPartialMock(
194+
$associatedProductMock = $this->createPartialMock(
195+
\Magento\Catalog\Model\Product\Configuration\Item\Option::class,
196+
[
197+
'getValue',
198+
]
199+
);
200+
$infoBuyRequestMock = $this->createPartialMock(
179201
\Magento\Catalog\Model\Product\Configuration\Item\Option::class,
180202
[
181203
'getValue',
182204
]
183205
);
184206

185-
$optionMock->expects($this->once())->method('getValue')->willReturn($initVal);
207+
$associatedProductMock->expects($this->once())->method('getValue')->willReturn($initVal);
208+
$infoBuyRequestMock->expects($this->once())
209+
->method('getValue')
210+
->willReturn('{"product":"'. $prodId . '","action":"add"}');
186211

187-
$items['associated_product_' . $prodId] = $optionMock;
212+
$items['associated_product_' . $prodId] = $associatedProductMock;
213+
$items['info_buyRequest'] = $infoBuyRequestMock;
188214

189215
return $items;
190216
}

app/code/Magento/Paypal/Controller/Express/AbstractExpress/Cancel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function execute()
3131
->unsLastSuccessQuoteId()
3232
->unsLastOrderId()
3333
->unsLastRealOrderId();
34+
$this->_getSession()->unsQuoteId(); // clean quote from session that was set in OnAuthorization
3435
$this->messageManager->addSuccessMessage(
3536
__('Express Checkout and Order have been canceled.')
3637
);

app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Paypal\Model\Api\ProcessableException as ApiProcessableException;
1212

1313
/**
14-
* Class PlaceOrder
14+
* Creates order on backend and prepares session to show appropriate next step in flow
1515
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1616
*/
1717
class PlaceOrder extends \Magento\Paypal\Controller\Express\AbstractExpress
@@ -127,6 +127,7 @@ public function execute()
127127
return;
128128
}
129129
$this->_initToken(false); // no need in token anymore
130+
$this->_getSession()->unsQuoteId(); // clean quote from session that was set in OnAuthorization
130131
$this->_redirect('checkout/onepage/success');
131132
return;
132133
} catch (ApiProcessableException $e) {

app/code/Magento/Paypal/Test/Mftf/ActionGroup/StorefrontLoginToPayPalPaymentAccountTwoStepActionGroup.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<waitForPageLoad stepKey="waitForPageLoad"/>
1717
<seeCurrentUrlMatches regex="~\//www.sandbox.paypal.com/~" stepKey="seeCurrentUrlMatchesConfigPath1"/>
1818
<conditionalClick selector="{{PayPalPaymentSection.notYouLink}}" dependentSelector="{{PayPalPaymentSection.notYouLink}}" visible="true" stepKey="selectNotYouSection"/>
19+
<conditionalClick selector="{{PayPalPaymentSection.existingAccountLoginBtn}}" dependentSelector="{{PayPalPaymentSection.existingAccountLoginBtn}}" visible="true" stepKey="skipAccountCreationAndLogin"/>
20+
<waitForPageLoad stepKey="waitForLoginPageLoad"/>
1921
<waitForElement selector="{{PayPalPaymentSection.email}}" stepKey="waitForLoginForm" />
2022
<fillField selector="{{PayPalPaymentSection.email}}" userInput="{{credentials.magento/paypal_sandbox_login_email}}" stepKey="fillEmail"/>
2123
<click selector="{{PayPalPaymentSection.nextButton}}" stepKey="clickNext"/>

app/code/Magento/Paypal/Test/Mftf/Section/PayPalExpressCheckoutConfigSection/PayPalPaymentSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<section name="PayPalPaymentSection">
1111
<element name="guestCheckout" type="input" selector="#guest"/>
1212
<element name="loginSection" type="input" selector=" #main&gt;#login"/>
13+
<element name="existingAccountLoginBtn" type="input" selector="#loginSection a"/>
1314
<element name="email" type="input" selector="//input[contains(@name, 'email') and not(contains(@style, 'display:none'))]"/>
1415
<element name="password" type="input" selector="//input[contains(@name, 'password') and not(contains(@style, 'display:none'))]"/>
1516
<element name="loginBtn" type="input" selector="button#btnLogin"/>

app/code/Magento/Paypal/Test/Mftf/Test/StorefrontPaypalSmartButtonInCheckoutPageTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<severity value="CRITICAL"/>
1818
<testCaseId value="MC-13690"/>
1919
<group value="paypalExpress"/>
20-
<skip>
21-
<issueId value="MC-35722"/>
22-
</skip>
2320
</annotations>
2421
<before>
2522
<!-- Login -->

app/code/Magento/Paypal/Test/Mftf/Test/StorefrontPaypalSmartButtonWithFranceMerchantCountryTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<severity value="MAJOR"/>
1818
<testCaseId value="MC-33274"/>
1919
<group value="paypalExpress"/>
20-
<skip>
21-
<issueId value="MC-35722"/>
22-
</skip>
2320
</annotations>
2421
<before>
2522
<!--Set price scope global-->

app/code/Magento/Wishlist/Model/Wishlist.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false
492492
} else {
493493
$_buyRequest = new DataObject();
494494
}
495+
if ($_buyRequest->getData('action') !== 'updateItem') {
496+
$_buyRequest->setData('action', 'add');
497+
}
495498

496499
/* @var $product Product */
497500
$cartCandidates = $product->getTypeInstance()->processConfiguration($_buyRequest, clone $product);
@@ -750,15 +753,16 @@ public function updateItem($itemId, $buyRequest, $params = null)
750753
}
751754
$params->setCurrentConfig($item->getBuyRequest());
752755
$buyRequest = $this->_catalogProduct->addParamsToBuyRequest($buyRequest, $params);
756+
$buyRequest->setData('action', 'updateItem');
753757

754758
$product->setWishlistStoreId($item->getStoreId());
755759
$items = $this->getItemCollection();
756760
$isForceSetQuantity = true;
757-
foreach ($items as $_item) {
758-
/* @var $_item Item */
759-
if ($_item->getProductId() == $product->getId() && $_item->representProduct(
760-
$product
761-
) && $_item->getId() != $item->getId()
761+
foreach ($items as $wishlistItem) {
762+
/* @var $wishlistItem Item */
763+
if ($wishlistItem->getProductId() == $product->getId()
764+
&& $wishlistItem->getId() != $item->getId()
765+
&& $wishlistItem->representProduct($product)
762766
) {
763767
// We do not add new wishlist item, but updating the existing one
764768
$isForceSetQuantity = false;

app/code/Magento/Wishlist/Test/Unit/Model/WishlistTest.php

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -243,34 +243,22 @@ public function testLoadByCustomerId()
243243

244244
/**
245245
* @param int|Item|MockObject $itemId
246-
* @param DataObject $buyRequest
246+
* @param DataObject|MockObject $buyRequest
247247
* @param null|array|DataObject $param
248248
* @throws LocalizedException
249249
*
250250
* @dataProvider updateItemDataProvider
251251
*/
252-
public function testUpdateItem($itemId, $buyRequest, $param)
252+
public function testUpdateItem($itemId, $buyRequest, $param): void
253253
{
254254
$storeId = 1;
255255
$productId = 1;
256256
$stores = [(new DataObject())->setId($storeId)];
257257

258-
$newItem = $this->getMockBuilder(Item::class)
259-
->setMethods(
260-
['setProductId', 'setWishlistId', 'setStoreId', 'setOptions', 'setProduct', 'setQty', 'getItem', 'save']
261-
)
262-
->disableOriginalConstructor()
263-
->getMock();
264-
$newItem->expects($this->any())->method('setProductId')->willReturnSelf();
265-
$newItem->expects($this->any())->method('setWishlistId')->willReturnSelf();
266-
$newItem->expects($this->any())->method('setStoreId')->willReturnSelf();
267-
$newItem->expects($this->any())->method('setOptions')->willReturnSelf();
268-
$newItem->expects($this->any())->method('setProduct')->willReturnSelf();
269-
$newItem->expects($this->any())->method('setQty')->willReturnSelf();
270-
$newItem->expects($this->any())->method('getItem')->willReturn(2);
271-
$newItem->expects($this->any())->method('save')->willReturnSelf();
258+
$newItem = $this->prepareWishlistItem();
272259

273260
$this->itemFactory->expects($this->once())->method('create')->willReturn($newItem);
261+
$this->productHelper->expects($this->once())->method('addParamsToBuyRequest')->willReturn($buyRequest);
274262

275263
$this->storeManager->expects($this->any())->method('getStores')->willReturn($stores);
276264
$this->storeManager->expects($this->any())->method('getStore')->willReturn($stores[0]);
@@ -355,13 +343,48 @@ public function testUpdateItem($itemId, $buyRequest, $param)
355343
);
356344
}
357345

346+
/**
347+
* Prepare wishlist item mock.
348+
*
349+
* @return MockObject
350+
*/
351+
private function prepareWishlistItem(): MockObject
352+
{
353+
$newItem = $this->getMockBuilder(Item::class)
354+
->setMethods(
355+
['setProductId', 'setWishlistId', 'setStoreId', 'setOptions', 'setProduct', 'setQty', 'getItem', 'save']
356+
)
357+
->disableOriginalConstructor()
358+
->getMock();
359+
$newItem->expects($this->any())->method('setProductId')->willReturnSelf();
360+
$newItem->expects($this->any())->method('setWishlistId')->willReturnSelf();
361+
$newItem->expects($this->any())->method('setStoreId')->willReturnSelf();
362+
$newItem->expects($this->any())->method('setOptions')->willReturnSelf();
363+
$newItem->expects($this->any())->method('setProduct')->willReturnSelf();
364+
$newItem->expects($this->any())->method('setQty')->willReturnSelf();
365+
$newItem->expects($this->any())->method('getItem')->willReturn(2);
366+
$newItem->expects($this->any())->method('save')->willReturnSelf();
367+
368+
return $newItem;
369+
}
370+
358371
/**
359372
* @return array
360373
*/
361-
public function updateItemDataProvider()
374+
public function updateItemDataProvider(): array
362375
{
376+
$dataObjectMock = $this->createMock(DataObject::class);
377+
$dataObjectMock->expects($this->once())
378+
->method('setData')
379+
->with('action', 'updateItem')
380+
->willReturnSelf();
381+
$dataObjectMock->expects($this->once())
382+
->method('getData')
383+
->with('action')
384+
->willReturn('updateItem');
385+
363386
return [
364-
'0' => [1, new DataObject(), null]
387+
'0' => [1, $dataObjectMock, null]
365388
];
366389
}
367390

0 commit comments

Comments
 (0)