Skip to content

Commit 61a5a30

Browse files
authored
Merge pull request #4863 from magento-epam/EPAM-PR-77
- Increase test coverage for Promotion and Loyalty functional area - fixed Fatal error is displayed during multishipping checkout when open Cart page in another window - fixed Admin user with permission for 1 store can manage product quantity
2 parents 586c9df + b7223a5 commit 61a5a30

File tree

21 files changed

+504
-65
lines changed

21 files changed

+504
-65
lines changed

app/code/Magento/Bundle/Test/Mftf/Test/AdminRemoveDefaultImageBundleProductTest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<createData entity="SimpleProduct2" stepKey="simpleProduct2"/>
2525
</before>
2626
<after>
27+
<!-- Delete the bundled product we created in the test body -->
28+
<actionGroup ref="deleteProductBySku" stepKey="deleteBundleProduct">
29+
<argument name="sku" value="{{BundleProduct.sku}}"/>
30+
</actionGroup>
2731
<amOnPage url="{{AdminLogoutPage.url}}" stepKey="amOnLogoutPage"/>
2832
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
2933
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminAssertDisabledQtyActionGroup">
12+
<annotations>
13+
<description>Goes to the 'Quantity' field and assert disabled attribute.</description>
14+
</annotations>
15+
16+
<seeElement selector="{{AdminProductFormSection.productQuantity}}" stepKey="assertProductQty"/>
17+
<assertElementContainsAttribute selector="{{AdminProductFormSection.productQuantity}}" attribute="disabled" expectedValue="true" stepKey="checkIfQtyIsDisabled" />
18+
</actionGroup>
19+
</actionGroups>

app/code/Magento/CatalogInventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
2-
3-
declare(strict_types=1);
4-
52
/**
63
* Copyright © Magento, Inc. All rights reserved.
74
* See COPYING.txt for license details.
85
*/
6+
declare(strict_types=1);
7+
98
namespace Magento\CatalogInventory\Ui\DataProvider\Product\Form\Modifier;
109

1110
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\StockDataFilter;
@@ -238,7 +237,7 @@ private function prepareMeta()
238237
$this->meta = $this->arrayManager->merge(
239238
$fieldsetPath . '/children',
240239
$this->meta,
241-
['container_quantity_and_stock_status_qty' => $container]
240+
['quantity_and_stock_status_qty' => $container]
242241
);
243242
}
244243
}

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartSummarySection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<element name="totalAmount" type="text" selector="//*[@id='cart-totals']//tr[@class='grand totals']//td//span[@class='price' and contains(text(), '{{amount}}')]" parameterized="true"/>
2121
<element name="proceedToCheckout" type="button" selector=".action.primary.checkout span" timeout="30"/>
2222
<element name="discountAmount" type="text" selector="td[data-th='Discount']"/>
23-
<element name="shippingHeading" type="button" selector="#block-shipping-heading" timeout="60"/>
23+
<element name="shippingHeading" type="button" selector="#block-shipping-heading" timeout="10"/>
2424
<element name="postcode" type="input" selector="input[name='postcode']" timeout="10"/>
2525
<element name="stateProvince" type="select" selector="select[name='region_id']" timeout="10"/>
2626
<element name="stateProvinceInput" type="input" selector="input[name='region']"/>

app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/ConfigurableQty.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier;
79

810
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
11+
use Magento\Catalog\Model\Locator\LocatorInterface;
912

1013
/**
1114
* Data provider for quantity in the Configurable products
@@ -16,21 +19,37 @@ class ConfigurableQty extends AbstractModifier
1619
const CODE_QTY_CONTAINER = 'quantity_and_stock_status_qty';
1720

1821
/**
19-
* {@inheritdoc}
22+
* @var LocatorInterface
23+
*/
24+
private $locator;
25+
26+
/**
27+
* ConfigurableQty constructor
28+
*
29+
* @param LocatorInterface $locator
30+
*/
31+
public function __construct(LocatorInterface $locator)
32+
{
33+
$this->locator = $locator;
34+
}
35+
36+
/**
37+
* @inheritdoc
2038
*/
2139
public function modifyData(array $data)
2240
{
2341
return $data;
2442
}
2543

2644
/**
27-
* {@inheritdoc}
45+
* @inheritdoc
2846
*/
2947
public function modifyMeta(array $meta)
3048
{
3149
if ($groupCode = $this->getGroupCodeByField($meta, self::CODE_QTY_CONTAINER)) {
3250
$parentChildren = &$meta[$groupCode]['children'];
33-
if (!empty($parentChildren[self::CODE_QTY_CONTAINER])) {
51+
$isConfigurable = $this->locator->getProduct()->getTypeId() === 'configurable';
52+
if (!empty($parentChildren[self::CODE_QTY_CONTAINER]) && $isConfigurable) {
3453
$parentChildren[self::CODE_QTY_CONTAINER] = array_replace_recursive(
3554
$parentChildren[self::CODE_QTY_CONTAINER],
3655
[
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
9+
<section name="StorefrontCheckoutCartGiftMessageSection">
10+
<element name="giftItemMessage" type="textarea" selector="tbody.cart:nth-of-type({{blockNumber}}) #gift-message-whole-message" parameterized="true"/>
11+
</section>
12+
</sections>

app/code/Magento/Multishipping/Block/Checkout/Shipping.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Multishipping\Block\Checkout;
79

810
use Magento\Framework\Pricing\PriceCurrencyInterface;
911
use Magento\Quote\Model\Quote\Address;
12+
use Magento\Store\Model\ScopeInterface;
1013

1114
/**
1215
* Mustishipping checkout shipping
@@ -67,6 +70,8 @@ public function getCheckout()
6770
}
6871

6972
/**
73+
* Add page title and prepare layout
74+
*
7075
* @return $this
7176
*/
7277
protected function _prepareLayout()
@@ -78,6 +83,8 @@ protected function _prepareLayout()
7883
}
7984

8085
/**
86+
* Retrieves addresses
87+
*
8188
* @return Address[]
8289
*/
8390
public function getAddresses()
@@ -86,6 +93,8 @@ public function getAddresses()
8693
}
8794

8895
/**
96+
* Returns count of addresses
97+
*
8998
* @return mixed
9099
*/
91100
public function getAddressCount()
@@ -99,14 +108,16 @@ public function getAddressCount()
99108
}
100109

101110
/**
111+
* Retrieves the address items
112+
*
102113
* @param Address $address
103114
* @return \Magento\Framework\DataObject[]
104115
*/
105116
public function getAddressItems($address)
106117
{
107118
$items = [];
108119
foreach ($address->getAllItems() as $item) {
109-
if ($item->getParentItemId()) {
120+
if ($item->getParentItemId() || !$item->getQuoteItemId()) {
110121
continue;
111122
}
112123
$item->setQuoteItem($this->getCheckout()->getQuote()->getItemById($item->getQuoteItemId()));
@@ -118,6 +129,8 @@ public function getAddressItems($address)
118129
}
119130

120131
/**
132+
* Retrieves the address shipping method
133+
*
121134
* @param Address $address
122135
* @return mixed
123136
*/
@@ -127,6 +140,8 @@ public function getAddressShippingMethod($address)
127140
}
128141

129142
/**
143+
* Retrieves address shipping rates
144+
*
130145
* @param Address $address
131146
* @return mixed
132147
*/
@@ -137,22 +152,20 @@ public function getShippingRates($address)
137152
}
138153

139154
/**
155+
* Retrieves the carrier name by the code
156+
*
140157
* @param string $carrierCode
141158
* @return string
142159
*/
143160
public function getCarrierName($carrierCode)
144161
{
145-
if ($name = $this->_scopeConfig->getValue(
146-
'carriers/' . $carrierCode . '/title',
147-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
148-
)
149-
) {
150-
return $name;
151-
}
152-
return $carrierCode;
162+
$name = $this->_scopeConfig->getValue('carriers/' . $carrierCode . '/title', ScopeInterface::SCOPE_STORE);
163+
return $name ?: $carrierCode;
153164
}
154165

155166
/**
167+
* Retrieves the address edit url
168+
*
156169
* @param Address $address
157170
* @return string
158171
*/
@@ -162,6 +175,8 @@ public function getAddressEditUrl($address)
162175
}
163176

164177
/**
178+
* Retrieves the url for items edition
179+
*
165180
* @return string
166181
*/
167182
public function getItemsEditUrl()
@@ -170,6 +185,8 @@ public function getItemsEditUrl()
170185
}
171186

172187
/**
188+
* Retrieves the url for the post action
189+
*
173190
* @return string
174191
*/
175192
public function getPostActionUrl()
@@ -178,6 +195,8 @@ public function getPostActionUrl()
178195
}
179196

180197
/**
198+
* Retrieves the back url
199+
*
181200
* @return string
182201
*/
183202
public function getBackUrl()
@@ -186,6 +205,8 @@ public function getBackUrl()
186205
}
187206

188207
/**
208+
* Returns converted and formatted price
209+
*
189210
* @param Address $address
190211
* @param float $price
191212
* @param bool $flag
@@ -202,7 +223,7 @@ public function getShippingPrice($address, $price, $flag)
202223
}
203224

204225
/**
205-
* Retrieve text for items box
226+
* Retrieves text for items box
206227
*
207228
* @param \Magento\Framework\DataObject $addressEntity
208229
* @return string

app/code/Magento/Multishipping/Model/Cart/Controller/CartPlugin.php

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,89 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Multishipping\Model\Cart\Controller;
79

10+
use Magento\Checkout\Controller\Cart;
11+
use Magento\Checkout\Model\Session;
12+
use Magento\Customer\Api\AddressRepositoryInterface;
13+
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
16+
use Magento\Quote\Api\CartRepositoryInterface;
17+
use Magento\Quote\Model\Quote;
18+
19+
/**
20+
* Cleans shipping addresses and item assignments after MultiShipping flow
21+
*/
822
class CartPlugin
923
{
1024
/**
11-
* @var \Magento\Quote\Api\CartRepositoryInterface
25+
* @var CartRepositoryInterface
1226
*/
1327
private $cartRepository;
1428

1529
/**
16-
* @var \Magento\Checkout\Model\Session
30+
* @var Session
1731
*/
1832
private $checkoutSession;
1933

2034
/**
21-
* @var \Magento\Customer\Api\AddressRepositoryInterface
35+
* @var AddressRepositoryInterface
2236
*/
2337
private $addressRepository;
2438

2539
/**
26-
* @param \Magento\Quote\Api\CartRepositoryInterface $cartRepository
27-
* @param \Magento\Checkout\Model\Session $checkoutSession
28-
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
40+
* @param CartRepositoryInterface $cartRepository
41+
* @param Session $checkoutSession
42+
* @param AddressRepositoryInterface $addressRepository
2943
*/
3044
public function __construct(
31-
\Magento\Quote\Api\CartRepositoryInterface $cartRepository,
32-
\Magento\Checkout\Model\Session $checkoutSession,
33-
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
45+
CartRepositoryInterface $cartRepository,
46+
Session $checkoutSession,
47+
AddressRepositoryInterface $addressRepository
3448
) {
3549
$this->cartRepository = $cartRepository;
3650
$this->checkoutSession = $checkoutSession;
3751
$this->addressRepository = $addressRepository;
3852
}
3953

4054
/**
41-
* @param \Magento\Checkout\Controller\Cart $subject
42-
* @param \Magento\Framework\App\RequestInterface $request
55+
* Cleans shipping addresses and item assignments after MultiShipping flow
56+
*
57+
* @param Cart $subject
58+
* @param RequestInterface $request
4359
* @return void
4460
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
61+
* @throws LocalizedException
4562
*/
46-
public function beforeDispatch(
47-
\Magento\Checkout\Controller\Cart $subject,
48-
\Magento\Framework\App\RequestInterface $request
49-
) {
50-
/** @var \Magento\Quote\Model\Quote $quote */
63+
public function beforeDispatch(Cart $subject, RequestInterface $request)
64+
{
65+
/** @var Quote $quote */
5166
$quote = $this->checkoutSession->getQuote();
52-
53-
// Clear shipping addresses and item assignments after MultiShipping flow
54-
if ($quote->isMultipleShippingAddresses()) {
67+
if ($quote->isMultipleShippingAddresses() && $this->isCheckoutComplete()) {
5568
foreach ($quote->getAllShippingAddresses() as $address) {
5669
$quote->removeAddress($address->getId());
5770
}
5871

5972
$shippingAddress = $quote->getShippingAddress();
6073
$defaultShipping = $quote->getCustomer()->getDefaultShipping();
6174
if ($defaultShipping) {
62-
$defaultCustomerAddress = $this->addressRepository->getById(
63-
$defaultShipping
64-
);
75+
$defaultCustomerAddress = $this->addressRepository->getById($defaultShipping);
6576
$shippingAddress->importCustomerAddressData($defaultCustomerAddress);
6677
}
6778
$this->cartRepository->save($quote);
6879
}
6980
}
81+
82+
/**
83+
* Checks whether the checkout flow is complete
84+
*
85+
* @return bool
86+
*/
87+
private function isCheckoutComplete() : bool
88+
{
89+
return (bool) ($this->checkoutSession->getStepData(State::STEP_SHIPPING)['is_complete'] ?? true);
90+
}
7091
}

0 commit comments

Comments
 (0)