magento / graphql-ce

[ARCHIVED] Please use magento/magento2 project
https://github.com/magento/magento2
Open Software License 3.0
131 stars 156 forks source link

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

Closed TomashKhamlai closed 5 years ago

TomashKhamlai commented 5 years ago

Preconditions (*)

  1. No preconditions

Steps to reproduce (*)

  1. Step 1: No headers. No variables

    mutation {
    createEmptyCart
    }
  2. 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
    }
  3. 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"
    }
  4. 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 }}"
    }
  5. 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"
            }
          }
        ]
  6. Pay attention to "selected_payment_method": null

  7. 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 commented 5 years ago

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

TomashKhamlai commented 5 years ago

665

TomashKhamlai commented 5 years ago

Still reproducible

pmclain commented 5 years ago

Added a functional test reproducing https://github.com/pmclain/graphql-ce/commit/d4d9fae9bb085aca91745b3163676fac5780e593 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.