Skip to content

Commit ff750b9

Browse files
committed
Merge branch 'pr-31322' into 2.4-develop-prs
2 parents a5b8a60 + 9b49cee commit ff750b9

File tree

4 files changed

+242
-59
lines changed

4 files changed

+242
-59
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/SelectedShippingMethod.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
declare(strict_types=1);
78

89
namespace Magento\QuoteGraphQl\Model\Resolver\ShippingAddress;
910

10-
use Magento\Directory\Model\Currency;
1111
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\GraphQl\Config\Element\Field;
1313
use Magento\Framework\GraphQl\Query\ResolverInterface;
1414
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Quote\Model\Cart\ShippingMethodConverter;
1516
use Magento\Quote\Model\Quote\Address;
1617
use Magento\Quote\Model\Quote\Address\Rate;
1718

@@ -20,6 +21,19 @@
2021
*/
2122
class SelectedShippingMethod implements ResolverInterface
2223
{
24+
/**
25+
* @var ShippingMethodConverter
26+
*/
27+
private $shippingMethodConverter;
28+
29+
/**
30+
* @param ShippingMethodConverter $shippingMethodConverter
31+
*/
32+
public function __construct(ShippingMethodConverter $shippingMethodConverter)
33+
{
34+
$this->shippingMethodConverter = $shippingMethodConverter;
35+
}
36+
2337
/**
2438
* @inheritdoc
2539
*/
@@ -31,8 +45,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
3145
/** @var Address $address */
3246
$address = $value['model'];
3347
$rates = $address->getAllShippingRates();
34-
$carrierTitle = '';
35-
$methodTitle = '';
3648

3749
if (!count($rates) || empty($address->getShippingMethod())) {
3850
return null;
@@ -42,26 +54,36 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4254

4355
/** @var Rate $rate */
4456
foreach ($rates as $rate) {
45-
if ($rate->getCode() == $address->getShippingMethod()) {
46-
$carrierTitle = $rate->getCarrierTitle();
47-
$methodTitle = $rate->getMethodTitle();
57+
if ($rate->getCode() === $address->getShippingMethod()) {
4858
break;
4959
}
5060
}
5161

52-
$data = [
62+
$cart = $address->getQuote();
63+
$selectedShippingMethod = $this->shippingMethodConverter->modelToDataObject(
64+
$rate,
65+
$cart->getQuoteCurrencyCode()
66+
);
67+
68+
return [
5369
'carrier_code' => $carrierCode,
5470
'method_code' => $methodCode,
55-
'carrier_title' => $carrierTitle,
56-
'method_title' => $methodTitle,
71+
'carrier_title' => $selectedShippingMethod->getCarrierTitle() ?? '',
72+
'method_title' => $selectedShippingMethod->getMethodTitle() ?? '',
5773
'amount' => [
5874
'value' => $address->getShippingAmount(),
59-
'currency' => $address->getQuote()->getQuoteCurrencyCode(),
75+
'currency' => $cart->getQuoteCurrencyCode(),
76+
],
77+
'price_excl_tax' => [
78+
'value' => $selectedShippingMethod->getPriceExclTax(),
79+
'currency' => $cart->getQuoteCurrencyCode(),
80+
],
81+
'price_incl_tax' => [
82+
'value' => $selectedShippingMethod->getPriceInclTax(),
83+
'currency' => $cart->getQuoteCurrencyCode(),
6084
],
6185
/** @deprecated The field should not be used on the storefront */
6286
'base_amount' => null,
6387
];
64-
65-
return $data;
6688
}
6789
}

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ type SelectedShippingMethod @doc(description: "Contains details about the select
267267
method_title: String! @doc(description: "The label for the method code.")
268268
amount: Money! @doc(description: "The cost of shipping using this shipping method.")
269269
base_amount: Money @deprecated(reason: "The field should not be used on the storefront.")
270+
price_excl_tax: Money! @doc(description: "The cost of shipping using this shipping method, excluding tax.")
271+
price_incl_tax: Money! @doc(description: "The cost of shipping using this shipping method, including tax.")
270272
}
271273

272274
type AvailableShippingMethod @doc(description: "Contains details about the possible shipping methods and carriers.") {

app/code/Magento/Tax/Model/Config.php

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,109 +23,109 @@ class Config
2323
/**
2424
* Tax notifications
2525
*/
26-
const XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT = 'tax/notification/ignore_discount';
26+
public const XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT = 'tax/notification/ignore_discount';
2727

28-
const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY = 'tax/notification/ignore_price_display';
28+
public const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY = 'tax/notification/ignore_price_display';
2929

30-
const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';
30+
public const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';
3131

32-
const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';
32+
public const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';
3333

3434
// tax classes
35-
const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';
35+
public const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';
3636

3737
// tax calculation
38-
const CONFIG_XML_PATH_PRICE_INCLUDES_TAX = 'tax/calculation/price_includes_tax';
38+
public const CONFIG_XML_PATH_PRICE_INCLUDES_TAX = 'tax/calculation/price_includes_tax';
3939

40-
const CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX = 'tax/calculation/shipping_includes_tax';
40+
public const CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX = 'tax/calculation/shipping_includes_tax';
4141

42-
const CONFIG_XML_PATH_BASED_ON = 'tax/calculation/based_on';
42+
public const CONFIG_XML_PATH_BASED_ON = 'tax/calculation/based_on';
4343

44-
const CONFIG_XML_PATH_APPLY_ON = 'tax/calculation/apply_tax_on';
44+
public const CONFIG_XML_PATH_APPLY_ON = 'tax/calculation/apply_tax_on';
4545

46-
const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT = 'tax/calculation/apply_after_discount';
46+
public const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT = 'tax/calculation/apply_after_discount';
4747

48-
const CONFIG_XML_PATH_DISCOUNT_TAX = 'tax/calculation/discount_tax';
48+
public const CONFIG_XML_PATH_DISCOUNT_TAX = 'tax/calculation/discount_tax';
4949

50-
const XML_PATH_ALGORITHM = 'tax/calculation/algorithm';
50+
public const XML_PATH_ALGORITHM = 'tax/calculation/algorithm';
5151

52-
const CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED = 'tax/calculation/cross_border_trade_enabled';
52+
public const CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED = 'tax/calculation/cross_border_trade_enabled';
5353

5454
// tax defaults
55-
const CONFIG_XML_PATH_DEFAULT_COUNTRY = 'tax/defaults/country';
55+
public const CONFIG_XML_PATH_DEFAULT_COUNTRY = 'tax/defaults/country';
5656

57-
const CONFIG_XML_PATH_DEFAULT_REGION = 'tax/defaults/region';
57+
public const CONFIG_XML_PATH_DEFAULT_REGION = 'tax/defaults/region';
5858

59-
const CONFIG_XML_PATH_DEFAULT_POSTCODE = 'tax/defaults/postcode';
59+
public const CONFIG_XML_PATH_DEFAULT_POSTCODE = 'tax/defaults/postcode';
6060

6161
/**
6262
* Prices display settings
6363
*/
64-
const CONFIG_XML_PATH_PRICE_DISPLAY_TYPE = 'tax/display/type';
64+
public const CONFIG_XML_PATH_PRICE_DISPLAY_TYPE = 'tax/display/type';
6565

66-
const CONFIG_XML_PATH_DISPLAY_SHIPPING = 'tax/display/shipping';
66+
public const CONFIG_XML_PATH_DISPLAY_SHIPPING = 'tax/display/shipping';
6767

6868
/**
6969
* Shopping cart display settings
7070
*/
71-
const XML_PATH_DISPLAY_CART_PRICE = 'tax/cart_display/price';
71+
public const XML_PATH_DISPLAY_CART_PRICE = 'tax/cart_display/price';
7272

73-
const XML_PATH_DISPLAY_CART_SUBTOTAL = 'tax/cart_display/subtotal';
73+
public const XML_PATH_DISPLAY_CART_SUBTOTAL = 'tax/cart_display/subtotal';
7474

75-
const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';
75+
public const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';
7676

7777
/**
7878
* Tax cart display discount
7979
*
8080
* @deprecated
8181
*/
82-
const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';
82+
public const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';
8383

84-
const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';
84+
public const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';
8585

86-
const XML_PATH_DISPLAY_CART_FULL_SUMMARY = 'tax/cart_display/full_summary';
86+
public const XML_PATH_DISPLAY_CART_FULL_SUMMARY = 'tax/cart_display/full_summary';
8787

88-
const XML_PATH_DISPLAY_CART_ZERO_TAX = 'tax/cart_display/zero_tax';
88+
public const XML_PATH_DISPLAY_CART_ZERO_TAX = 'tax/cart_display/zero_tax';
8989

9090
/**
9191
* Shopping cart display settings
9292
*/
93-
const XML_PATH_DISPLAY_SALES_PRICE = 'tax/sales_display/price';
93+
public const XML_PATH_DISPLAY_SALES_PRICE = 'tax/sales_display/price';
9494

95-
const XML_PATH_DISPLAY_SALES_SUBTOTAL = 'tax/sales_display/subtotal';
95+
public const XML_PATH_DISPLAY_SALES_SUBTOTAL = 'tax/sales_display/subtotal';
9696

97-
const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';
97+
public const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';
9898

9999
/**
100100
* Tax sales display discount
101101
*
102102
* @deprecated
103103
*/
104-
const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';
104+
public const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';
105105

106-
const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
106+
public const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
107107

108-
const XML_PATH_DISPLAY_SALES_FULL_SUMMARY = 'tax/sales_display/full_summary';
108+
public const XML_PATH_DISPLAY_SALES_FULL_SUMMARY = 'tax/sales_display/full_summary';
109109

110-
const XML_PATH_DISPLAY_SALES_ZERO_TAX = 'tax/sales_display/zero_tax';
110+
public const XML_PATH_DISPLAY_SALES_ZERO_TAX = 'tax/sales_display/zero_tax';
111111

112-
const CALCULATION_STRING_SEPARATOR = '|';
112+
public const CALCULATION_STRING_SEPARATOR = '|';
113113

114-
const DISPLAY_TYPE_EXCLUDING_TAX = 1;
114+
public const DISPLAY_TYPE_EXCLUDING_TAX = 1;
115115

116-
const DISPLAY_TYPE_INCLUDING_TAX = 2;
116+
public const DISPLAY_TYPE_INCLUDING_TAX = 2;
117117

118-
const DISPLAY_TYPE_BOTH = 3;
118+
public const DISPLAY_TYPE_BOTH = 3;
119119

120120
/**
121121
* Price conversion constant for positive
122122
*/
123-
const PRICE_CONVERSION_PLUS = 1;
123+
public const PRICE_CONVERSION_PLUS = 1;
124124

125125
/**
126126
* Price conversion constant for negative
127127
*/
128-
const PRICE_CONVERSION_MINUS = 2;
128+
public const PRICE_CONVERSION_MINUS = 2;
129129

130130
/**
131131
* @var bool|null
@@ -912,7 +912,9 @@ public function getInfoUrl($store = null)
912912
public function needPriceConversion($store = null)
913913
{
914914
$res = false;
915-
$priceIncludesTax = $this->priceIncludesTax($store) || $this->getNeedUseShippingExcludeTax();
915+
$priceIncludesTax = $this->priceIncludesTax($store)
916+
|| $this->getNeedUseShippingExcludeTax()
917+
|| $this->shippingPriceIncludesTax($store);
916918
if ($priceIncludesTax) {
917919
switch ($this->getPriceDisplayType($store)) {
918920
case self::DISPLAY_TYPE_EXCLUDING_TAX:

0 commit comments

Comments
 (0)