Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,37 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
/** @var Address $address */
$address = $value['model'];
$rates = $address->getAllShippingRates();
$carrierTitle = null;
$methodTitle = null;
$carrierTitle = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove redundant lines.

Copy link
Author

@sergiy-v sergiy-v Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove redundant lines.

In case I'll remove these lines the $carrierTitle and the $methodTitle variables might not be defined (please check lines 46, 47).
Should I add any changes here?
Thank you.

$methodTitle = '';

if (count($rates) > 0 && !empty($address->getShippingMethod())) {
list($carrierCode, $methodCode) = explode('_', $address->getShippingMethod(), 2);
if (!count($rates) || empty($address->getShippingMethod())) {
return null;
}

/** @var Rate $rate */
foreach ($rates as $rate) {
if ($rate->getCode() == $address->getShippingMethod()) {
$carrierTitle = $rate->getCarrierTitle();
$methodTitle = $rate->getMethodTitle();
break;
}
}
list($carrierCode, $methodCode) = explode('_', $address->getShippingMethod(), 2);

$data = [
'carrier_code' => $carrierCode,
'method_code' => $methodCode,
'carrier_title' => $carrierTitle,
'method_title' => $methodTitle,
'amount' => [
'value' => $address->getShippingAmount(),
'currency' => $address->getQuote()->getQuoteCurrencyCode(),
],
/** @deprecated The field should not be used on the storefront */
'base_amount' => null,
];
} else {
$data = null;
/** @var Rate $rate */
foreach ($rates as $rate) {
if ($rate->getCode() == $address->getShippingMethod()) {
$carrierTitle = $rate->getCarrierTitle();
$methodTitle = $rate->getMethodTitle();
break;
}
}

$data = [
'carrier_code' => $carrierCode,
'method_code' => $methodCode,
'carrier_title' => $carrierTitle,
'method_title' => $methodTitle,
'amount' => [
'value' => $address->getShippingAmount(),
'currency' => $address->getQuote()->getQuoteCurrencyCode(),
],
/** @deprecated The field should not be used on the storefront */
'base_amount' => null,
];

return $data;
}
}
10 changes: 5 additions & 5 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ type CartAddressCountry {
}

type SelectedShippingMethod {
carrier_code: String
method_code: String
carrier_title: String
method_title: String
amount: Money
carrier_code: String!
method_code: String!
carrier_title: String!
method_title: String!
amount: Money!
base_amount: Money @deprecated(reason: "The field should not be used on the storefront")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,7 @@ public function testGetGetSelectedShippingMethodIfShippingMethodIsNotSet()

$shippingAddress = current($response['cart']['shipping_addresses']);
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);

self::assertNull($shippingAddress['selected_shipping_method']['carrier_code']);
self::assertNull($shippingAddress['selected_shipping_method']['method_code']);
self::assertNull($shippingAddress['selected_shipping_method']['carrier_title']);
self::assertNull($shippingAddress['selected_shipping_method']['method_title']);
self::assertNull($shippingAddress['selected_shipping_method']['amount']);
self::assertNull($shippingAddress['selected_shipping_method']);
}

/**
Expand Down