为什么region_code无法正确存储?

时间:2020-08-27 11:56:01

标签: magento graphql magento2

我在项目中使用Magento GraphQL api。为了创建客户地址,我使用了createCustomerAddress突变(createCustomerAddress)。

下面是我为创建客户地址而调用的变体:

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
  }
}

这正常工作,并向我返回了以下结果:

{
  "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
    }
  }
}

但是,现在我查询获取客户地址时,它返回错误的region_code

这是我为获取客户地址而写的查询:

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

结果:

{
  "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"
        }
      ]
    }
  }
}

如您所见,该查询结果中的region_code和突变结果中的region_code是不同的。查询未返回由突变产生的region_code。产生的变异region_code GJ ,返回的查询region_code Gujarat

有人可以帮助我为什么会这样吗?如何解决?

1 个答案:

答案 0 :(得分:0)

我自己在Magento 2.3.4中偶然发现了这个bug,它似乎是使用region_code的bug。有一种解决方法,请尝试发送region_id而不是region_code,如下所示:

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
  }
}

此后,如果您检索region_code,它将显示正常。似乎无法通过region_code识别区域。

相关问题