Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
GraphQL-285: [Shipping methods] Get list of available shipping method…
Browse files Browse the repository at this point in the history
…s for current cart
  • Loading branch information
naydav committed Feb 14, 2019
1 parent 242cd2f commit 2fa4f1f
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 421 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 2fa4f1f

Please sign in to comment.