why region_code not storing properly?

299 views Asked by At

I am using Magento GraphQL api in my project. To create a customer address I used createCustomerAddress mutation(createCustomerAddress).

Below is the mutation that I have called to create the customer address :

mutation createAddress {
  createCustomerAddress(
    input: {
      firstname: "test"
      lastname: "name"
      company: "networld"
      telephone: "1231231231"
      street: ["test address line 1", "test address line 2"]
      city: "Rajkot"
      region: { region:"Gujarat", region_code: "GJ" }
      postcode: "360001"
      country_code: IN
    }
  ) {
    id
    prefix
    firstname
    lastname
    middlename
    city
    company
    country_code
    default_billing
    default_shipping
    postcode
    region {
      region
      region_code
    }
    street
    suffix
    telephone
    vat_id
  }
}

This is working properly and returning me the result as below :

{
  "data": {
    "createCustomerAddress": {
      "id": 44,
      "prefix": null,
      "firstname": "test",
      "lastname": "name",
      "middlename": null,
      "city": "Rajkot",
      "company": "networld",
      "country_code": "IN",
      "default_billing": false,
      "default_shipping": false,
      "postcode": "360001",
      "region": {
        "region": "Gujarat",
        "region_code": "GJ"
      },
      "street": [
        "test address line 1",
        "test address line 2"
      ],
      "suffix": null,
      "telephone": "1231231231",
      "vat_id": null
    }
  }
}

But, now when I query to get the customer address, it returning wrong region_code.

Here is the query I written to get the customer address :

query{
  customer{
    addresses{
      id
      firstname
      lastname
      street
      city
      region{
        region
        region_code
      }
      country_code
      postcode
      telephone
    }
  }
}

Result :

{
  "data": {
    "customer": {
      "addresses": [
        {
          "id": 44,
          "firstname": "test",
          "lastname": "name",
          "street": [
            "test address line 1",
            "test address line 2"
          ],
          "city": "Rajkot",
          "region": {
            "region": "Gujarat",
            "region_code": "Gujarat"
          },
          "country_code": "IN",
          "postcode": "360001",
          "telephone": "1231231231"
        }
      ]
    }
  }
}

As you can see, region_code in this query result and region_code in mutation result was different. Query not returning region_code that generated from the mutation. Mutation generated region_code was GJ and query returned region_code was Gujarat.

Can anyone help me why this is happening ? How to solve it ?

1

There are 1 answers

0
hestajoe On

I just stumbled upon this bug myself in Magento 2.3.4 and it looks like it's buggy with the region_code. There's a workaround for this, try to send the region_id instead of region_code, like this:

mutation {
  createCustomerAddress(input: {
    region: {
      region: "VendeƩ"
      region_id: 799
    }
    country_code: FR
    street: ["123 Main Street"]
    telephone: "7777777777"
    postcode: "77777"
    city: "Phoenix"
    firstname: "Bob"
    lastname: "Loblaw"
    default_shipping: true
    default_billing: false
  }) {
    id
    region {
      region
      region_code
    }
    country_code
    street
    telephone
    postcode
    city
    default_shipping
    default_billing
  }
}

After this, if you retrieve the region_code, it will show fine. It looks like it has problems identifying the region by the region_code.