Skip to content

Commit

Permalink
ENGCOM-4138: Provide available shipping rates for addresses #339
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav authored Feb 14, 2019
2 parents 3acf405 + c39db0d commit 2d09e02
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 328 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,42 @@
*/
declare(strict_types=1);

namespace Magento\QuoteGraphQl\Model\Cart\Address\Mapper;
namespace Magento\QuoteGraphQl\Model\Cart;

use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Model\Quote\Address as QuoteAddress;

/**
* Class Address
*
* Extract the necessary address fields from an Address model
*/
class Address
class ExtractDataFromAddress
{
/**
* Converts Address model data to nested array
* @var ExtensibleDataObjectConverter
*/
private $dataObjectConverter;

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

/**
* Converts Address model to flat array
*
* @param QuoteAddress $address
* @return array
*/
public function toNestedArray(QuoteAddress $address): array
public function execute(QuoteAddress $address): array
{
$addressData = [
$addressData = $this->dataObjectConverter->toFlatArray($address, [], AddressInterface::class);
$addressData['model'] = $address;

$addressData = array_merge($addressData, [
'country' => [
'code' => $address->getCountryId(),
'label' => $address->getCountry()
Expand All @@ -41,7 +57,7 @@ public function toNestedArray(QuoteAddress $address): array
],
'items_weight' => $address->getWeight(),
'customer_notes' => $address->getCustomerNotes()
];
]);

if (!$address->hasItems()) {
return $addressData;
Expand Down
24 changes: 14 additions & 10 deletions app/code/Magento/QuoteGraphQl/Model/Resolver/BillingAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\QuoteGraphQl\Model\Cart\Address\BillingAddressDataProvider;
use Magento\QuoteGraphQl\Model\Cart\ExtractDataFromAddress;

/**
* @inheritdoc
*/
class BillingAddress implements ResolverInterface
{
/**
* @var BillingAddressDataProvider
* @var ExtractDataFromAddress
*/
private $addressDataProvider;
private $extractDataFromAddress;

/**
* @param BillingAddressDataProvider $addressDataProvider
* @param ExtractDataFromAddress $extractDataFromAddress
*/
public function __construct(
BillingAddressDataProvider $addressDataProvider
) {
$this->addressDataProvider = $addressDataProvider;
public function __construct(ExtractDataFromAddress $extractDataFromAddress)
{
$this->extractDataFromAddress = $extractDataFromAddress;
}

/**
Expand All @@ -40,9 +39,14 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
if (!isset($value['model'])) {
throw new LocalizedException(__('"model" value should be specified'));
}

$cart = $value['model'];

return $this->addressDataProvider->getCartAddresses($cart);
$billingAddress = $cart->getBillingAddress();
if (null === $billingAddress) {
return null;
}

$addressData = $this->extractDataFromAddress->execute($billingAddress);
return $addressData;
}
}
Loading

0 comments on commit 2d09e02

Please sign in to comment.