From 91d8a9279adab6e067422840af32eec8b7507a50 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 1 May 2019 02:12:06 +0300 Subject: [PATCH 1/2] magento/graphql-ce#646: Incorrect name of Selected Shipping Method --- .../SelectedShippingMethod.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/SelectedShippingMethod.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/SelectedShippingMethod.php index cd8f20c3f164..61c535d35009 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/SelectedShippingMethod.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/SelectedShippingMethod.php @@ -30,17 +30,26 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value /** @var Address $address */ $address = $value['model']; $rates = $address->getAllShippingRates(); + $carrierTitle = null; + $methodTitle = null; if (count($rates) > 0) { list($carrierCode, $methodCode) = explode('_', $address->getShippingMethod(), 2); + /** @var Rate $rate */ - $rate = current($rates); + 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' => $rate->getCarrierTitle(), - 'method_title' => $rate->getMethodTitle(), + 'carrier_title' => $carrierTitle, + 'method_title' => $methodTitle, 'amount' => [ 'value' => $address->getShippingAmount(), 'currency' => $address->getQuote()->getQuoteCurrencyCode(), @@ -54,8 +63,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $data = [ 'carrier_code' => null, 'method_code' => null, - 'carrier_title' => null, - 'method_title' => null, + 'carrier_title' => $carrierTitle, + 'method_title' => $methodTitle, 'amount' => null, 'base_amount' => null, ]; From 64e76c4888f8baae719791ed2787b9f0948562b4 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 1 May 2019 13:29:31 -0500 Subject: [PATCH 2/2] GraphQL-646: Incorrect name of Selected Shipping Method --- .../Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index c50ae0a70380..7de689a6ad0f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -116,6 +116,7 @@ public function testSetUpsShippingMethod(string $methodCode, string $methodTitle self::assertEquals(self::CARRIER_TITLE, $shippingAddress['selected_shipping_method']['carrier_title']); self::assertArrayHasKey('method_title', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodTitle, $shippingAddress['selected_shipping_method']['method_title']); } /** @@ -171,6 +172,7 @@ public function testSetUpsShippingMethodBasedOnCanadaAddress(string $methodCode, self::assertEquals(self::CARRIER_TITLE, $shippingAddress['selected_shipping_method']['carrier_title']); self::assertArrayHasKey('method_title', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodTitle, $shippingAddress['selected_shipping_method']['method_title']); } /**