Skip to content

Commit d0b7189

Browse files
committed
Merge remote-tracking branch 'origin/MC-20387' into 2.3-develop-pr35
2 parents 720434d + 8557356 commit d0b7189

File tree

14 files changed

+318
-69
lines changed

14 files changed

+318
-69
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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="AssertStorefrontShippingLabelDescriptionInOrderSummaryActionGroup">
12+
<annotations>
13+
<description>Validates that the Shipping label description is present and correct.</description>
14+
</annotations>
15+
16+
<arguments>
17+
<argument name="labelDescription" type="string"/>
18+
</arguments>
19+
<waitForElementVisible selector="{{CheckoutOrderSummarySection.orderSummaryShippingTotalLabelDescription}}" time="30" stepKey="waitForElement"/>
20+
<see selector="{{CheckoutOrderSummarySection.orderSummaryShippingTotalLabelDescription}}" userInput="{{labelDescription}}" stepKey="seeShippingMethodLabelDescription"/>
21+
</actionGroup>
22+
</actionGroups>

app/code/Magento/Checkout/Test/Mftf/ActionGroup/CheckoutActionGroup.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@
171171
<seeInCurrentUrl url="{{CheckoutPage.url}}/#payment" stepKey="assertCheckoutPaymentUrl"/>
172172
</actionGroup>
173173

174+
<!-- Submit Shipping Address on Checkout Shipping page -->
175+
<actionGroup name="StorefrontCheckoutForwardFromShippingStep">
176+
<annotations>
177+
<description>Clicks next on Checkout Shipping step</description>
178+
</annotations>
179+
<waitForElementVisible selector="{{CheckoutShippingSection.next}}" time="30" stepKey="waitForNextButton"/>
180+
<click selector="{{CheckoutShippingSection.next}}" stepKey="clickNext"/>
181+
</actionGroup>
182+
174183
<!-- Logged in user checkout filling shipping section -->
175184
<actionGroup name="LoggedInUserCheckoutAddNewShippingSectionWithoutRegionActionGroup">
176185
<annotations>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
<element name="additionalAddress" type="text" selector=".block.block-addresses-list"/>
2020
<element name="miniCartTabClosed" type="button" selector=".title[aria-expanded='false']" timeout="30"/>
2121
<element name="itemsQtyInCart" type="text" selector=".items-in-cart > .title > strong > span"/>
22+
<element name="orderSummaryShippingTotalLabelDescription" type="text" selector=".shipping.totals .label.description"/>
2223
</section>
2324
</sections>

app/code/Magento/Checkout/view/frontend/web/js/view/summary/shipping.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
define([
77
'jquery',
88
'Magento_Checkout/js/view/summary/abstract-total',
9-
'Magento_Checkout/js/model/quote'
10-
], function ($, Component, quote) {
9+
'Magento_Checkout/js/model/quote',
10+
'Magento_SalesRule/js/view/summary/discount'
11+
], function ($, Component, quote, discountView) {
1112
'use strict';
1213

1314
return Component.extend({
@@ -57,6 +58,34 @@ define([
5758
price = this.totals()['shipping_amount'];
5859

5960
return this.getFormattedPrice(price);
61+
},
62+
63+
/**
64+
* If is set coupon code, but there wasn't displayed discount view.
65+
*
66+
* @return {Boolean}
67+
*/
68+
haveToShowCoupon: function () {
69+
var couponCode = this.totals()['coupon_code'];
70+
71+
if (typeof couponCode === 'undefined') {
72+
couponCode = false;
73+
}
74+
75+
return couponCode && !discountView().isDisplayed();
76+
},
77+
78+
/**
79+
* Returns coupon code description.
80+
*
81+
* @return {String}
82+
*/
83+
getCouponDescription: function () {
84+
if (!this.haveToShowCoupon()) {
85+
return '';
86+
}
87+
88+
return '(' + this.totals()['coupon_code'] + ')';
6089
}
6190
});
6291
});

app/code/Magento/Sales/Block/Adminhtml/Totals.php

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Sales\Block\Adminhtml;
77

8-
use Magento\Sales\Model\Order;
8+
use Magento\Framework\DataObject;
99

1010
/**
1111
* Adminhtml sales totals block
@@ -57,84 +57,70 @@ public function formatValue($total)
5757
protected function _initTotals()
5858
{
5959
$this->_totals = [];
60-
$this->_totals['subtotal'] = new \Magento\Framework\DataObject(
60+
$order = $this->getSource();
61+
62+
$this->_totals['subtotal'] = new DataObject(
6163
[
6264
'code' => 'subtotal',
63-
'value' => $this->getSource()->getSubtotal(),
64-
'base_value' => $this->getSource()->getBaseSubtotal(),
65+
'value' => $order->getSubtotal(),
66+
'base_value' => $order->getBaseSubtotal(),
6567
'label' => __('Subtotal'),
6668
]
6769
);
6870

6971
/**
70-
* Add shipping
72+
* Add discount
7173
*/
72-
if (!$this->getSource()->getIsVirtual() && ((double)$this->getSource()->getShippingAmount() ||
73-
$this->getSource()->getShippingDescription())
74-
) {
75-
$shippingLabel = __('Shipping & Handling');
76-
if ($this->isFreeShipping($this->getOrder()) && $this->getSource()->getDiscountDescription()) {
77-
$shippingLabel .= sprintf(' (%s)', $this->getSource()->getDiscountDescription());
74+
if ((double)$order->getDiscountAmount() != 0) {
75+
if ($order->getDiscountDescription()) {
76+
$discountLabel = __('Discount (%1)', $order->getDiscountDescription());
77+
} else {
78+
$discountLabel = __('Discount');
7879
}
79-
$this->_totals['shipping'] = new \Magento\Framework\DataObject(
80+
$this->_totals['discount'] = new DataObject(
8081
[
81-
'code' => 'shipping',
82-
'value' => $this->getSource()->getShippingAmount(),
83-
'base_value' => $this->getSource()->getBaseShippingAmount(),
84-
'label' => $shippingLabel,
82+
'code' => 'discount',
83+
'value' => $order->getDiscountAmount(),
84+
'base_value' => $order->getBaseDiscountAmount(),
85+
'label' => $discountLabel,
8586
]
8687
);
8788
}
8889

8990
/**
90-
* Add discount
91+
* Add shipping
9192
*/
92-
if ((double)$this->getSource()->getDiscountAmount() != 0) {
93-
if ($this->getSource()->getDiscountDescription()) {
94-
$discountLabel = __('Discount (%1)', $this->getSource()->getDiscountDescription());
95-
} else {
96-
$discountLabel = __('Discount');
93+
if (!$order->getIsVirtual()
94+
&& ((double)$order->getShippingAmount()
95+
|| $order->getShippingDescription())
96+
) {
97+
$shippingLabel = __('Shipping & Handling');
98+
99+
if ($order->getCouponCode() && !isset($this->_totals['discount'])) {
100+
$shippingLabel .= " ({$order->getCouponCode()})";
97101
}
98-
$this->_totals['discount'] = new \Magento\Framework\DataObject(
102+
103+
$this->_totals['shipping'] = new DataObject(
99104
[
100-
'code' => 'discount',
101-
'value' => $this->getSource()->getDiscountAmount(),
102-
'base_value' => $this->getSource()->getBaseDiscountAmount(),
103-
'label' => $discountLabel,
105+
'code' => 'shipping',
106+
'value' => $order->getShippingAmount(),
107+
'base_value' => $order->getBaseShippingAmount(),
108+
'label' => $shippingLabel,
104109
]
105110
);
106111
}
107112

108-
$this->_totals['grand_total'] = new \Magento\Framework\DataObject(
113+
$this->_totals['grand_total'] = new DataObject(
109114
[
110115
'code' => 'grand_total',
111116
'strong' => true,
112-
'value' => $this->getSource()->getGrandTotal(),
113-
'base_value' => $this->getSource()->getBaseGrandTotal(),
117+
'value' => $order->getGrandTotal(),
118+
'base_value' => $order->getBaseGrandTotal(),
114119
'label' => __('Grand Total'),
115120
'area' => 'footer',
116121
]
117122
);
118123

119124
return $this;
120125
}
121-
122-
/**
123-
* Availability of free shipping in at least one order item
124-
*
125-
* @param Order $order
126-
* @return bool
127-
*/
128-
private function isFreeShipping(Order $order): bool
129-
{
130-
$isFreeShipping = false;
131-
foreach ($order->getItems() as $orderItem) {
132-
if ($orderItem->getFreeShipping() == '1') {
133-
$isFreeShipping = true;
134-
break;
135-
}
136-
}
137-
138-
return $isFreeShipping;
139-
}
140126
}

app/code/Magento/Sales/Block/Order/Totals.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Sales\Model\Order;
99

1010
/**
11+
* Order totals.
12+
*
1113
* @api
1214
* @since 100.0.2
1315
*/
@@ -85,6 +87,8 @@ public function getOrder()
8587
}
8688

8789
/**
90+
* Sets order.
91+
*
8892
* @param Order $order
8993
* @return $this
9094
*/
@@ -118,20 +122,6 @@ protected function _initTotals()
118122
['code' => 'subtotal', 'value' => $source->getSubtotal(), 'label' => __('Subtotal')]
119123
);
120124

121-
/**
122-
* Add shipping
123-
*/
124-
if (!$source->getIsVirtual() && ((double)$source->getShippingAmount() || $source->getShippingDescription())) {
125-
$this->_totals['shipping'] = new \Magento\Framework\DataObject(
126-
[
127-
'code' => 'shipping',
128-
'field' => 'shipping_amount',
129-
'value' => $this->getSource()->getShippingAmount(),
130-
'label' => __('Shipping & Handling'),
131-
]
132-
);
133-
}
134-
135125
/**
136126
* Add discount
137127
*/
@@ -151,6 +141,25 @@ protected function _initTotals()
151141
);
152142
}
153143

144+
/**
145+
* Add shipping
146+
*/
147+
if (!$source->getIsVirtual() && ((double)$source->getShippingAmount() || $source->getShippingDescription())) {
148+
$label = __('Shipping & Handling');
149+
if ($this->getSource()->getCouponCode() && !isset($this->_totals['discount'])) {
150+
$label = __('Shipping & Handling (%1)', $this->getSource()->getCouponCode());
151+
}
152+
153+
$this->_totals['shipping'] = new \Magento\Framework\DataObject(
154+
[
155+
'code' => 'shipping',
156+
'field' => 'shipping_amount',
157+
'value' => $this->getSource()->getShippingAmount(),
158+
'label' => $label,
159+
]
160+
);
161+
}
162+
154163
$this->_totals['grand_total'] = new \Magento\Framework\DataObject(
155164
[
156165
'code' => 'grand_total',
@@ -286,7 +295,6 @@ public function removeTotal($code)
286295
* $totalCode => $totalSortOrder
287296
* )
288297
*
289-
*
290298
* @param array $order
291299
* @return $this
292300
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -303,7 +311,7 @@ function ($code1, $code2) use ($order) {
303311
}
304312

305313
/**
306-
* get totals array for visualization
314+
* Get totals array for visualization
307315
*
308316
* @param array|null $area
309317
* @return array
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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="AssertAdminShippingDescriptionInOrderViewActionGroup">
12+
<annotations>
13+
<description>Validates that the Shipping Description will shown in Shipping total description.</description>
14+
</annotations>
15+
16+
<arguments>
17+
<argument name="description" type="string"/>
18+
</arguments>
19+
<waitForElementVisible selector="{{AdminOrderTotalSection.shippingDescription}}" time="30" stepKey="waitForElement"/>
20+
<see selector="{{AdminOrderTotalSection.shippingDescription}}" userInput="{{description}}" stepKey="seeOrderTotalShippingDescription"/>
21+
</actionGroup>
22+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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="AssertStorefrontShippingDescriptionInOrderViewActionGroup">
12+
<annotations>
13+
<description>Validates that the Shipping Description will shown in Shipping total description.</description>
14+
</annotations>
15+
16+
<arguments>
17+
<argument name="description" type="string"/>
18+
</arguments>
19+
<waitForElementVisible selector="{{StorefrontOrderDetailsSection.shippingTotalDescription}}" time="30" stepKey="waitForElement"/>
20+
<see selector="{{StorefrontOrderDetailsSection.shippingTotalDescription}}" userInput="{{description}}" stepKey="seeShippingTotalDescription"/>
21+
</actionGroup>
22+
</actionGroups>

app/code/Magento/Sales/Test/Mftf/Section/AdminOrderTotalSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<section name="AdminOrderTotalSection">
1212
<element name="subTotal" type="text" selector=".order-subtotal-table tbody tr.col-0>td span.price"/>
1313
<element name="grandTotal" type="text" selector=".order-subtotal-table tfoot tr.col-0>td span.price"/>
14+
<element name="shippingDescription" type="text" selector="//table[contains(@class, 'order-subtotal-table')]//td[contains(text(), 'Shipping &amp; Handling')]"/>
1415
<element name="shippingAndHandling" type="text" selector="//table[contains(@class, 'order-subtotal-table')]//td[normalize-space(.)='Shipping &amp; Handling']/following-sibling::td//span[@class='price']"/>
1516
<element name="total" type="text" selector="//table[contains(@class,'order-subtotal-table')]/tbody/tr/td[contains(text(), '{{total}}')]/following-sibling::td/span/span[contains(@class, 'price')]" parameterized="true"/>
1617
</section>

app/code/Magento/Sales/Test/Mftf/Section/StorefrontOrderDetailsSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<element name="orderDetailsBlock" type="block" selector=".block-order-details-view"/>
1313
<element name="billingAddressBlock" type="block" selector=".box-order-billing-address > .box-content > address"/>
1414
<element name="discountSalesRule" type="text" selector="tr.discount span.price"/>
15+
<element name="shippingTotalDescription" type="text" selector="#my-orders-table tr.shipping th.mark"/>
1516
<element name="grandTotalPrice" type="text" selector="tr.grand_total span.price"/>
1617
<element name="paymentMethod" type="text" selector=".box-order-billing-method dt.title"/>
1718
<element name="shippingMethod" type="text" selector=".box-order-shipping-method div.box-content"/>

0 commit comments

Comments
 (0)