Skip to content

magento/magento2#31206: Selected shipping method does not contain val… #31322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\QuoteGraphQl\Model\Resolver\ShippingAddress;

use Magento\Directory\Model\Currency;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Model\Cart\ShippingMethodConverter;
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Address\Rate;

Expand All @@ -20,6 +21,19 @@
*/
class SelectedShippingMethod implements ResolverInterface
{
/**
* @var ShippingMethodConverter
*/
private $shippingMethodConverter;

/**
* @param ShippingMethodConverter $shippingMethodConverter
*/
public function __construct(ShippingMethodConverter $shippingMethodConverter)
{
$this->shippingMethodConverter = $shippingMethodConverter;
}

/**
* @inheritdoc
*/
Expand All @@ -31,8 +45,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
/** @var Address $address */
$address = $value['model'];
$rates = $address->getAllShippingRates();
$carrierTitle = '';
$methodTitle = '';

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

/** @var Rate $rate */
foreach ($rates as $rate) {
if ($rate->getCode() == $address->getShippingMethod()) {
$carrierTitle = $rate->getCarrierTitle();
$methodTitle = $rate->getMethodTitle();
if ($rate->getCode() === $address->getShippingMethod()) {
break;
}
}

$data = [
$cart = $address->getQuote();
$selectedShippingMethod = $this->shippingMethodConverter->modelToDataObject(
$rate,
$cart->getQuoteCurrencyCode()
);

return [
'carrier_code' => $carrierCode,
'method_code' => $methodCode,
'carrier_title' => $carrierTitle,
'method_title' => $methodTitle,
'carrier_title' => $selectedShippingMethod->getCarrierTitle() ?? '',
'method_title' => $selectedShippingMethod->getMethodTitle() ?? '',
'amount' => [
'value' => $address->getShippingAmount(),
'currency' => $address->getQuote()->getQuoteCurrencyCode(),
'currency' => $cart->getQuoteCurrencyCode(),
],
'price_excl_tax' => [
'value' => $selectedShippingMethod->getPriceExclTax(),
'currency' => $cart->getQuoteCurrencyCode(),
],
'price_incl_tax' => [
'value' => $selectedShippingMethod->getPriceInclTax(),
'currency' => $cart->getQuoteCurrencyCode(),
],
/** @deprecated The field should not be used on the storefront */
'base_amount' => null,
];

return $data;
}
}
2 changes: 2 additions & 0 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ type SelectedShippingMethod @doc(description: "Contains details about the select
method_title: String! @doc(description: "The label for the method code.")
amount: Money! @doc(description: "The cost of shipping using this shipping method.")
base_amount: Money @deprecated(reason: "The field should not be used on the storefront.")
price_excl_tax: Money! @doc(description: "The cost of shipping using this shipping method, excluding tax.")
price_incl_tax: Money! @doc(description: "The cost of shipping using this shipping method, including tax.")
}

type AvailableShippingMethod @doc(description: "Contains details about the possible shipping methods and carriers.") {
Expand Down
80 changes: 41 additions & 39 deletions app/code/Magento/Tax/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,109 +23,109 @@ class Config
/**
* Tax notifications
*/
const XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT = 'tax/notification/ignore_discount';
public const XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT = 'tax/notification/ignore_discount';

const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY = 'tax/notification/ignore_price_display';
public const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY = 'tax/notification/ignore_price_display';

const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';
public const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';

const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';
public const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';

// tax classes
const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';
public const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';

// tax calculation
const CONFIG_XML_PATH_PRICE_INCLUDES_TAX = 'tax/calculation/price_includes_tax';
public const CONFIG_XML_PATH_PRICE_INCLUDES_TAX = 'tax/calculation/price_includes_tax';

const CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX = 'tax/calculation/shipping_includes_tax';
public const CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX = 'tax/calculation/shipping_includes_tax';

const CONFIG_XML_PATH_BASED_ON = 'tax/calculation/based_on';
public const CONFIG_XML_PATH_BASED_ON = 'tax/calculation/based_on';

const CONFIG_XML_PATH_APPLY_ON = 'tax/calculation/apply_tax_on';
public const CONFIG_XML_PATH_APPLY_ON = 'tax/calculation/apply_tax_on';

const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT = 'tax/calculation/apply_after_discount';
public const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT = 'tax/calculation/apply_after_discount';

const CONFIG_XML_PATH_DISCOUNT_TAX = 'tax/calculation/discount_tax';
public const CONFIG_XML_PATH_DISCOUNT_TAX = 'tax/calculation/discount_tax';

const XML_PATH_ALGORITHM = 'tax/calculation/algorithm';
public const XML_PATH_ALGORITHM = 'tax/calculation/algorithm';

const CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED = 'tax/calculation/cross_border_trade_enabled';
public const CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED = 'tax/calculation/cross_border_trade_enabled';

// tax defaults
const CONFIG_XML_PATH_DEFAULT_COUNTRY = 'tax/defaults/country';
public const CONFIG_XML_PATH_DEFAULT_COUNTRY = 'tax/defaults/country';

const CONFIG_XML_PATH_DEFAULT_REGION = 'tax/defaults/region';
public const CONFIG_XML_PATH_DEFAULT_REGION = 'tax/defaults/region';

const CONFIG_XML_PATH_DEFAULT_POSTCODE = 'tax/defaults/postcode';
public const CONFIG_XML_PATH_DEFAULT_POSTCODE = 'tax/defaults/postcode';

/**
* Prices display settings
*/
const CONFIG_XML_PATH_PRICE_DISPLAY_TYPE = 'tax/display/type';
public const CONFIG_XML_PATH_PRICE_DISPLAY_TYPE = 'tax/display/type';

const CONFIG_XML_PATH_DISPLAY_SHIPPING = 'tax/display/shipping';
public const CONFIG_XML_PATH_DISPLAY_SHIPPING = 'tax/display/shipping';

/**
* Shopping cart display settings
*/
const XML_PATH_DISPLAY_CART_PRICE = 'tax/cart_display/price';
public const XML_PATH_DISPLAY_CART_PRICE = 'tax/cart_display/price';

const XML_PATH_DISPLAY_CART_SUBTOTAL = 'tax/cart_display/subtotal';
public const XML_PATH_DISPLAY_CART_SUBTOTAL = 'tax/cart_display/subtotal';

const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';
public const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';

/**
* Tax cart display discount
*
* @deprecated
*/
const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';
public const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';

const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';
public const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';

const XML_PATH_DISPLAY_CART_FULL_SUMMARY = 'tax/cart_display/full_summary';
public const XML_PATH_DISPLAY_CART_FULL_SUMMARY = 'tax/cart_display/full_summary';

const XML_PATH_DISPLAY_CART_ZERO_TAX = 'tax/cart_display/zero_tax';
public const XML_PATH_DISPLAY_CART_ZERO_TAX = 'tax/cart_display/zero_tax';

/**
* Shopping cart display settings
*/
const XML_PATH_DISPLAY_SALES_PRICE = 'tax/sales_display/price';
public const XML_PATH_DISPLAY_SALES_PRICE = 'tax/sales_display/price';

const XML_PATH_DISPLAY_SALES_SUBTOTAL = 'tax/sales_display/subtotal';
public const XML_PATH_DISPLAY_SALES_SUBTOTAL = 'tax/sales_display/subtotal';

const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';
public const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';

/**
* Tax sales display discount
*
* @deprecated
*/
const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';
public const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';

const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
public const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';

const XML_PATH_DISPLAY_SALES_FULL_SUMMARY = 'tax/sales_display/full_summary';
public const XML_PATH_DISPLAY_SALES_FULL_SUMMARY = 'tax/sales_display/full_summary';

const XML_PATH_DISPLAY_SALES_ZERO_TAX = 'tax/sales_display/zero_tax';
public const XML_PATH_DISPLAY_SALES_ZERO_TAX = 'tax/sales_display/zero_tax';

const CALCULATION_STRING_SEPARATOR = '|';
public const CALCULATION_STRING_SEPARATOR = '|';

const DISPLAY_TYPE_EXCLUDING_TAX = 1;
public const DISPLAY_TYPE_EXCLUDING_TAX = 1;

const DISPLAY_TYPE_INCLUDING_TAX = 2;
public const DISPLAY_TYPE_INCLUDING_TAX = 2;

const DISPLAY_TYPE_BOTH = 3;
public const DISPLAY_TYPE_BOTH = 3;

/**
* Price conversion constant for positive
*/
const PRICE_CONVERSION_PLUS = 1;
public const PRICE_CONVERSION_PLUS = 1;

/**
* Price conversion constant for negative
*/
const PRICE_CONVERSION_MINUS = 2;
public const PRICE_CONVERSION_MINUS = 2;

/**
* @var bool|null
Expand Down Expand Up @@ -912,7 +912,9 @@ public function getInfoUrl($store = null)
public function needPriceConversion($store = null)
{
$res = false;
$priceIncludesTax = $this->priceIncludesTax($store) || $this->getNeedUseShippingExcludeTax();
$priceIncludesTax = $this->priceIncludesTax($store)
|| $this->getNeedUseShippingExcludeTax()
|| $this->shippingPriceIncludesTax($store);
if ($priceIncludesTax) {
switch ($this->getPriceDisplayType($store)) {
case self::DISPLAY_TYPE_EXCLUDING_TAX:
Expand Down
Loading