This repository was archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
GraphQl shipping address coverage #192
Merged
magento-engcom-team
merged 21 commits into
2.3-develop
from
graph-ql-shipping-address-coverage
Nov 19, 2018
Merged
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e327bb6
graphQl: shipping address concept
ef8f126
graph-ql: concept of shipping address coverage, added separate flows …
a0bb0fc
graphQl: updated shipping address coverage content
c8dbdf4
graphQl: fixed multi shipping model
bf0aaad
graphQl: merge mainline
0a6c0b5
graphQl: removed multishipping implementation, fixed namespaces
90831f5
graphQl: removed not needed exception, added test coverage
5d2b1c8
graphQl: fixed dependency issue
e1f09fb
graphQl: added extension point for multishipping
55b6f4e
graphQl: fixed SetShippingAddressesInterface param
7c21b3b
graphQl: removed set shipping addresses chain, using di preference in…
2644b54
Merge branches 'graph-ql-shipping-address-coverage' and 'set-shipping…
c857857
graphQl: fixed composer json
240cfb3
graphQl: fixed typos and wrong descriptions
afd128e
graphQl: removed redundant multishipping references
d6f393a
Merge branches '2.3-develop' and 'graph-ql-shipping-address-coverage'…
2b5c1aa
Merge branches '2.3-develop' and 'graph-ql-shipping-address-coverage'…
313544e
Merge remote-tracking branch 'origin/2.3-develop' into graph-ql-shipp…
4694c06
GraphQL-39: Manage Shipping methods on Cart
c498773
GraphQL-39: Manage Shipping methods on Cart
39225d4
GraphQL-39: Manage Shipping methods on Cart
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingAddressOnCart.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
|
||
| use Magento\Authorization\Model\UserContextInterface; | ||
| use Magento\Customer\Api\Data\AddressInterface; | ||
| use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
| use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
| use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
| use Magento\Quote\Api\Data\CartInterface; | ||
| use Magento\Quote\Model\Quote\Address; | ||
| use Magento\Quote\Model\ShippingAddressManagementInterface; | ||
| use Magento\Customer\Api\AddressRepositoryInterface; | ||
|
|
||
| /** | ||
| * Set single shipping address for a specified shopping cart | ||
| */ | ||
| class SetShippingAddressOnCart implements SetShippingAddressesOnCartInterface | ||
| { | ||
| /** | ||
| * @var ShippingAddressManagementInterface | ||
| */ | ||
| private $shippingAddressManagement; | ||
|
|
||
| /** | ||
| * @var AddressRepositoryInterface | ||
| */ | ||
| private $addressRepository; | ||
|
|
||
| /** | ||
| * @var Address | ||
| */ | ||
| private $addressModel; | ||
|
|
||
| /** | ||
| * @param ShippingAddressManagementInterface $shippingAddressManagement | ||
| * @param AddressRepositoryInterface $addressRepository | ||
| * @param Address $addressModel | ||
| */ | ||
| public function __construct( | ||
| ShippingAddressManagementInterface $shippingAddressManagement, | ||
| AddressRepositoryInterface $addressRepository, | ||
| Address $addressModel | ||
| ) { | ||
| $this->shippingAddressManagement = $shippingAddressManagement; | ||
| $this->addressRepository = $addressRepository; | ||
| $this->addressModel = $addressModel; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function execute(ContextInterface $context, CartInterface $cart, array $shippingAddresses): void | ||
| { | ||
| if (count($shippingAddresses) > 1) { | ||
| throw new GraphQlInputException( | ||
| __('Multiple addresses do not allowed here!') | ||
| ); | ||
| } | ||
| $shippingAddress = current($shippingAddresses); | ||
| $customerAddressId = $shippingAddress['customer_address_id'] ?? null; | ||
| $addressInput = $shippingAddress['address'] ?? null; | ||
|
|
||
| if (!$customerAddressId && !$addressInput) { | ||
| throw new GraphQlInputException( | ||
| __('Shipping address should contain either "customer_address_id" or "address" input.') | ||
|
keharper marked this conversation as resolved.
Outdated
|
||
| ); | ||
| } | ||
| if ($customerAddressId && $addressInput) { | ||
| throw new GraphQlInputException( | ||
| __('Shipping address can\'t contain "customer_address_id" and "address" input at the same time.') | ||
|
keharper marked this conversation as resolved.
Outdated
|
||
| ); | ||
| } | ||
| if ($customerAddressId) { | ||
| if ((!$context->getUserId()) || $context->getUserType() == UserContextInterface::USER_TYPE_GUEST) { | ||
| throw new GraphQlAuthorizationException( | ||
| __( | ||
| 'Address management allowed only for authorized customers.' | ||
|
keharper marked this conversation as resolved.
Outdated
|
||
| ) | ||
| ); | ||
| } | ||
| /** @var AddressInterface $customerAddress */ | ||
| $customerAddress = $this->addressRepository->getById($customerAddressId); | ||
| $shippingAddress = $this->addressModel->importCustomerAddressData($customerAddress); | ||
| } else { | ||
| $shippingAddress = $this->addressModel->addData($addressInput); | ||
| } | ||
|
|
||
| $this->shippingAddressManagement->assign($cart->getId(), $shippingAddress); | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingAddressesOnCartInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
|
||
| use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
| use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
| use Magento\Quote\Api\Data\CartInterface; | ||
|
|
||
| /** | ||
| * Extension point for setting shipping addresses for a specified shopping cart | ||
| * | ||
| * All objects that are responsible for set shipping addresses on cart via GraphQl should implement this interface. | ||
|
keharper marked this conversation as resolved.
Outdated
|
||
| */ | ||
| interface SetShippingAddressesOnCartInterface | ||
| { | ||
|
|
||
| /** | ||
| * Set shipping addresses for a specified shopping cart | ||
| * | ||
| * @param ContextInterface $context | ||
| * @param CartInterface $cart | ||
| * @param array $shippingAddresses | ||
| * @return void | ||
| * @throws GraphQlInputException | ||
| */ | ||
| public function execute(ContextInterface $context, CartInterface $cart, array $shippingAddresses): void; | ||
| } | ||
100 changes: 100 additions & 0 deletions
100
app/code/Magento/QuoteGraphQl/Model/Resolver/SetShippingAddressesOnCart.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\QuoteGraphQl\Model\Resolver; | ||
|
|
||
| use Magento\Framework\GraphQl\Config\Element\Field; | ||
| use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
| use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
| use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
| use Magento\Framework\Stdlib\ArrayManager; | ||
| use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; | ||
| use Magento\Quote\Model\ShippingAddressManagementInterface; | ||
| use Magento\QuoteGraphQl\Model\Cart\GetCartForUser; | ||
| use Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCartInterface; | ||
|
|
||
| /** | ||
| * Class SetShippingAddressesOnCart | ||
| * | ||
| * Mutation resolver for setting shipping addresses for shopping cart | ||
| */ | ||
| class SetShippingAddressesOnCart implements ResolverInterface | ||
| { | ||
| /** | ||
| * @var MaskedQuoteIdToQuoteIdInterface | ||
| */ | ||
| private $maskedQuoteIdToQuoteId; | ||
|
|
||
| /** | ||
| * @var ShippingAddressManagementInterface | ||
| */ | ||
| private $shippingAddressManagement; | ||
|
|
||
| /** | ||
| * @var GetCartForUser | ||
| */ | ||
| private $getCartForUser; | ||
|
|
||
| /** | ||
| * @var ArrayManager | ||
| */ | ||
| private $arrayManager; | ||
|
|
||
| /** | ||
| * @var SetShippingAddressesOnCartInterface | ||
| */ | ||
| private $setShippingAddressesOnCart; | ||
|
|
||
| /** | ||
| * @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId | ||
| * @param ShippingAddressManagementInterface $shippingAddressManagement | ||
| * @param GetCartForUser $getCartForUser | ||
| * @param ArrayManager $arrayManager | ||
| * @param SetShippingAddressesOnCartInterface $setShippingAddressesOnCart | ||
| */ | ||
| public function __construct( | ||
| MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId, | ||
| ShippingAddressManagementInterface $shippingAddressManagement, | ||
| GetCartForUser $getCartForUser, | ||
| ArrayManager $arrayManager, | ||
| SetShippingAddressesOnCartInterface $setShippingAddressesOnCart | ||
| ) { | ||
| $this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; | ||
| $this->shippingAddressManagement = $shippingAddressManagement; | ||
| $this->getCartForUser = $getCartForUser; | ||
| $this->arrayManager = $arrayManager; | ||
| $this->setShippingAddressesOnCart = $setShippingAddressesOnCart; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
| { | ||
| $shippingAddresses = $this->arrayManager->get('input/shipping_addresses', $args); | ||
| $maskedCartId = $this->arrayManager->get('input/cart_id', $args); | ||
|
|
||
| if (!$maskedCartId) { | ||
| throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); | ||
| } | ||
| if (!$shippingAddresses) { | ||
| throw new GraphQlInputException(__('Required parameter "shipping_addresses" is missing')); | ||
| } | ||
|
|
||
| $maskedCartId = $args['input']['cart_id']; | ||
| $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); | ||
|
|
||
| $this->setShippingAddressesOnCart->execute($context, $cart, $shippingAddresses); | ||
|
|
||
| return [ | ||
| 'cart' => [ | ||
| 'cart_id' => $maskedCartId, | ||
| 'model' => $cart | ||
| ] | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?xml version="1.0"?> | ||
| <!-- | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| --> | ||
| <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
| <preference for="Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCartInterface" | ||
| type="Magento\QuoteGraphQl\Model\Cart\SetShippingAddressOnCart" /> | ||
| <virtualType name="multishippingPaymentSpecification" type="Magento\Payment\Model\Method\Specification\Composite"> | ||
| <arguments> | ||
| <argument name="specifications" xsi:type="array"> | ||
| <item name="enabled" xsi:type="string">Magento\Multishipping\Model\Payment\Method\Specification\Enabled</item> | ||
| </argument> | ||
| </arguments> | ||
| </virtualType> | ||
| <type name="Magento\Multishipping\Block\Checkout\Billing"> | ||
| <arguments> | ||
| <argument name="paymentSpecification" xsi:type="object">multishippingPaymentSpecification</argument> | ||
| </arguments> | ||
| </type> | ||
| <type name="Magento\Multishipping\Model\Checkout\Type\Multishipping"> | ||
| <arguments> | ||
| <argument name="paymentSpecification" xsi:type="object">multishippingPaymentSpecification</argument> | ||
| </arguments> | ||
| </type> | ||
| </config> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.