Skip to content

Commit

Permalink
ENGCOM-5010: magento/graphql-ce#646: Incorrect name of Selected Shipp…
Browse files Browse the repository at this point in the history
…ing Method #647

 - Merge Pull Request magento/graphql-ce#647 from magento/graphql-ce:646-incorrect-selected-shipping-method
 - Merged commits:
   1. 91d8a92
   2. 64e76c4
  • Loading branch information
magento-engcom-team committed May 1, 2019
2 parents 37677f8 + 64e76c4 commit 28e791a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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']);
}

/**
Expand Down

0 comments on commit 28e791a

Please sign in to comment.