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

region.code inside shipping_addresses resets to null if error occured during setShippingMethodsOnCart #658

Closed
TomashKhamlai opened this issue May 2, 2019 · 4 comments
Assignees
Labels
bug Something isn't working Checkout Component: QuoteGraphQl Contribution Day Tickets is good for start on Contribution Day good first issue Good for newcomers

Comments

@TomashKhamlai
Copy link
Contributor

TomashKhamlai commented May 2, 2019

Preconditions (*)

  1. No preconditions

Steps to reproduce (*)

  1. Step 1: No headers. No variables
mutation {
  createEmptyCart
}
  1. Step 2: Add simple product to cart. Simplify the query. Custom options do not cause the problem here.
mutation addSimpleProductsToCart(
  $cart_id: String!
  $qty: Float!
  $sku: String!
  $customizable_options: CustomizableOptionInput
) {
  addSimpleProductsToCart(
    input: {
      cart_id: $cart_id
      cartItems: {
        customizable_options: [
          $customizable_options
        ]
        data: {
          quantity: $qty
          sku: $sku
        }
      }
    }
  ) {
    cart {
      available_payment_methods {
        code
        title
      }
      items {
        id
        product {
          sku
          stock_status
        }
        quantity
      }
    }
  }
}

Variables:

{
      "sku" : "Simple-Product-261556815261890",
      "customizable_options" : {
         "id" : {{ ID_of_the_Field_Option }},
         "value" : "String"
      },
      "cart_id" : "{{ cart_id }}",
      "qty" : 1
   }
  1. Step 3:
mutation setShippingAddressesOnCart(
  $cart_id: String!
  $firstname: String!
  $lastname: String!
  $street_lines: [String]!
  $city: String!
  $region: String!
  $postcode: String!
  $country_code: String!
  $telephone: String!
) {
  setShippingAddressesOnCart(
    input: {
      cart_id: $cart_id
      shipping_addresses: [
        {
          address: {
            firstname: $firstname
            lastname: $lastname
            street: $street_lines
            city: $city
            region: $region
            postcode: $postcode
            country_code: $country_code
            telephone: $telephone
            save_in_address_book: false
          }
        }
      ]
    }
  ) {
    cart {
      shipping_addresses {
        firstname
        lastname
        city
        postcode
        region {
          label
          code
        }
        selected_shipping_method {
          carrier_code
          method_code
        }
        available_shipping_methods {
          carrier_code
          method_code
          carrier_title
          method_title
        }
      }
    }
  }
}

Variables:

{
      "telephone" : "555-555-55-55",
      "postcode" : "90230",
      "country_code" : "us",
      "cart_id" : "{{ cart_id }}",
      "lastname" : "Doe",
      "street_lines" : [
         "6161 West Centinella Avenue"
      ],
      "region" : "CA",
      "city" : "Culver City",
      "firstname" : "John"
   }
  1. Step 4: Set shipping method. I believe that only Payment Method cannon be set at the moment.
mutation setShippingMethodsOnCart(
  $cart_id: String!
  $carrier_code: String!
  $method_code: String!
) {
  setShippingMethodsOnCart(
    input: {
      cart_id: $cart_id
      shipping_methods: {
        carrier_code: $carrier_code
        method_code: $method_code
      }
    }
  ) {
    cart {
      shipping_addresses {
        postcode
        region {
          label
          code
        }
        selected_shipping_method {
          carrier_code
          method_code
        }
      }
      billing_address {
        postcode
      }
      selected_payment_method {
        code
      }
      available_payment_methods {
        code
        title
      }
    }
  }
}

Variables:

{
      "carrier_code" : "flatrate",
      "method_code" : "flatrate",
      "cart_id" : "{{ cart_id }}"
   }
  1. Step 5: Pay attention to shipping_addresses. It looks great despite of the fact that we already have "The payment method you requested is not available." even not trying to do this.
"shipping_addresses": [
          {
            "postcode": "90230",
            "region": {
              "label": "CA",
              "code": "CA"
            },
            "selected_shipping_method": {
              "carrier_code": "flatrate",
              "method_code": "flatrate"
            }
          }
        ]
  1. Pay attention to
    "selected_payment_method": null

  2. Get information by using query { cart ...
    or
    repeat "Step 4"

Expected result (*)

  1. shipping_addresses[0].region.code is equal to CA

Actual result (*)

  1. shipping_addresses[0].region.code is equal to null
@TomashKhamlai
Copy link
Contributor Author

The same problem in #657. Look to the actual result section of the mentioned issue

@TomashKhamlai
Copy link
Contributor Author

#665

@TomashKhamlai
Copy link
Contributor Author

Still reproducible

@TomashKhamlai TomashKhamlai added the Progress: ready for work Issue was verified and is reproducible by the given description. label May 30, 2019
@m2-community-project m2-community-project bot added Progress: dev in progress and removed Progress: ready for work Issue was verified and is reproducible by the given description. labels Jun 10, 2019
pmclain added a commit to pmclain/graphql-ce that referenced this issue Jun 15, 2019
@pmclain
Copy link
Contributor

pmclain commented Jun 15, 2019

Added a functional test reproducing pmclain@d4d9fae and am working on a fix. It only reproduces when setting the region via mutation and doesn't reproduce when using a quote address set via test data fixture. I'm assuming the issue is somewhere in how the set address resolver is setting the region.

pmclain added a commit to pmclain/graphql-ce that referenced this issue Jun 15, 2019
Fixes magento#658

Magento countryIds are uppercase and storing country_id as lowercase in quote
address items can cause undesired behavior when the Directory module determines
if a region is allowed for a given country.

Specifically this check fails when fetching the region code for a quote
address:
https://github.com/magento/graphql-ce/blob/a2fc3b98bf52ff7741579d16042b9c6376ecebfc/app/code/Magento/Customer/Model/Address/AbstractAddress.php#L400
pmclain added a commit to pmclain/graphql-ce that referenced this issue Jun 15, 2019
naydav added a commit to pmclain/graphql-ce that referenced this issue Jun 20, 2019
…error occured during setShippingMethodsOnCart
@naydav naydav closed this as completed Jun 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working Checkout Component: QuoteGraphQl Contribution Day Tickets is good for start on Contribution Day good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants