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

Provide available shipping rates for addresses #339

Merged

Conversation

pmclain
Copy link
Contributor

@pmclain pmclain commented Feb 3, 2019

Description (*)

Provide ability to retrieve available shipping rates for all cart shipping addresses. This PR separates the types of selected rate and available rates. Available methods are quite different objects from selected methods, given the selected methods are really just attributes of quote addresses.

This continues building some prerequisites for #39 #285

Manual testing scenarios (*)

  1. Create empty cart and add shippable products
  2. Set shipping address and request available_shipping_methods
mutation {
  setShippingAddressesOnCart(
    input: {
      cart_id: "$maskedQuoteId"
      shipping_addresses: [
        {
          address: {
            firstname: "test firstname"
            lastname: "test lastname"
            company: "test company"
            street: ["test street 1", "test street 2"]
            city: "test city"
            region: "test region"
            postcode: "887766"
            country_code: "US"
            telephone: "88776655"
            save_in_address_book: false
          }
        }
      ]
    }
  ) {
    cart {
      addresses {
        firstname
        lastname
        company
        street
        city
        postcode
        telephone
        available_shipping_methods {
          amount
          available
          base_amount
          carrier_code
          carrier_title
          error_message
          method_code
          method_title
          price_excl_tax
          price_incl_tax
        }
      }
    }
  }
}

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@@ -50,6 +61,12 @@ public function getCartAddresses(CartInterface $cart): array
if ($shippingAddress) {
$shippingData = $this->dataObjectConverter->toFlatArray($shippingAddress, [], AddressInterface::class);
$shippingData['address_type'] = 'SHIPPING';
if ($includeShippingMethods) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using second parameter-flag we can move this logic to separate class

return $this->addressDataProvider->getCartAddresses($cart, $this->includeShippingMethods($info));
}

private function includeShippingMethods(ResolveInfo $info): bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we declare separate resolver for available_shipping_methods in a scheme we don't need this class

@@ -112,7 +112,7 @@ type CartAddress {
telephone: String
address_type: AdressTypeEnum
selected_shipping_method: CheckoutShippingMethod
available_shipping_methods: [CheckoutShippingMethod]
available_shipping_methods: [CheckoutAvailableShippingMethod]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can split logic between different resolvers
Like addresses: [CartAddress]! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartAddresses")
It will simplify our code and relations

@pmclain
Copy link
Contributor Author

pmclain commented Feb 6, 2019

@naydav Thanks for checking this out. I've separated the resolver for the shipping methods 2f7237a

@pmclain pmclain force-pushed the feature/shipping-rates branch from 2f7237a to 6d6d5d5 Compare February 6, 2019 23:13
@magento-engcom-team magento-engcom-team merged commit 5ef26f7 into magento:2.3-develop Feb 15, 2019
@ghost
Copy link

ghost commented Feb 15, 2019

Hi @pmclain, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@keharper
Copy link
Contributor

Documented as part of magento/devdocs#4502

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants