【问题标题】:getting error when try to save shipping information for user using magento 2 api尝试使用 magento 2 api 为用户保存运输信息时出错
【发布时间】:2017-05-06 15:54:18
【问题描述】:

在从购物车到结帐的过程后无法保存运输信息。我们正在使用 magento 2 api。我的post信息是这样的

{
"addressInformation": {
"shipping_address": {
"id": 0,
"region": "IND",
"region_id": 0,
"region_code": "string",
"country_id": "IN",
"street": [
"string"
],
"company": "string",
"telephone": "123456789",
"fax": "string",
"postcode": "700091",
"city": "Kolkata",
"firstname": "Sauptik",
"lastname": "Basak",
"middlename": "string",
"prefix": "string",
"suffix": "string",
"vat_id": "string",
"customer_id": 2,
"email": "test1@test1.com",
"same_as_billing": 0,
"customer_address_id": 0,
"save_in_address_book": 1,      
"custom_attributes": [
{
"attribute_code": "string",
"value": "string"
}
]
},
"billing_address": {
"id": 0,
"region": "string",
"region_id": 0,
"region_code": "string",
"country_id": "IN",
"street": [
"string"
],
"company": "string",
"telephone": "123456789",
"fax": "string",
"postcode": "700091",
"city": "Kolkata",
"firstname": "Sauptik",
"lastname": "Basak",
"middlename": "string",
"prefix": "string",
"suffix": "string",
"vat_id": "string",
"customer_id": 2,
"email": "string",
"same_as_billing": 0,
"customer_address_id": 0,
"save_in_address_book": 0,      
"custom_attributes": [
{
"attribute_code": "string",
"value": "string"
}
]
},
"shipping_method_code": "string",
"shipping_carrier_code": "string",
"extension_attributes": {},
"custom_attributes": [
{
"attribute_code": "string",
"value": "string"
}
]
}
}

我的终点是http://192.168.0.61/WallisFudge/index.php/rest/V1/carts/3/shipping-information

我遇到了这个错误

"message": "无法保存发货信息。请检查输入数据。"

无法通过 magento 2 api 处理结帐

【问题讨论】:

    标签: php api magento2


    【解决方案1】:

    我在注册客户的发货步骤的结帐页面上遇到此错误消息。查看异常日志后,捕获了以下内容:

    report.CRITICAL: Invalid customer address id ##### {"exception":"[object] (Magento\\Framework\\Exception\\NoSuchEntityException(code: 0): Invalid customer address id ##### at /app/vlegfavdpg4my/vendor/magento/module-quote/Model/QuoteAddressValidator.php:77)"}
    

    检查代码后,第 77 行是客户 ID 检查抛出的异常:

    //Existing address cannot belong to a guest
    if (!$customerId) {
      throw new NoSuchEntityException(__('Invalid customer address id %1', $address->getCustomerAddressId()));
    }
    

    这是一个由类中的公共函数调用的私有函数:

    public function validate(AddressInterface $addressData): bool
    {
      $this->doValidate($addressData, $addressData->getCustomerId());
      return true;
    }
    

    此时,地址对象中引用的客户 ID 似乎为 null 或空。事实证明,关联的客人报价与该注册客户相关联。

    要纠正这种行为,首先查询遭受这种症状的报价:

    SELECT entity_id, customer_id FROM quote WHERE customer_id != 0 AND customer_is_guest = 1;
    

    如果客户 ID 在结果集中返回,则将所有已注册客户报价的报价更新为 NOT guest customer:

    UPDATE quote SET customer_is_guest = 0 WHERE customer_id != 0 AND customer_is_guest = 1;
    

    这解决了我客户的问题。订单现在可以进行付款步骤。

    我当前的版本是 2.2.9,但可能存在于早期版本 2.2.x 中。

    【讨论】:

    • 这个答案帮助我进行了数小时的搜索。它似乎与持久结帐有关。如果有人打开了它,它至少会导致 2.3.3 出现问题。
    • 我确实喜欢你在几个月后更改数据库数据。 DB 变回 1。为什么会这样?
    【解决方案2】:

    您能否尝试通过致电http://192.168.0.61/WallisFudge/index.php/rest/V1/carts/3/shipping-methods 检索您可用的“运输方式”。然后获取数据并将代码分配给以下内容:

    "shipping_method_code": "your_shipping_method_code_here", "shipping_carrier_code": "your_shipping_carrier_code_here",

    希望这会有所帮助。

    乔马尔

    【讨论】:

      【解决方案3】:

      我在将 Magento 版本从 2.1.9 升级到 2.2.3 后遇到了这个问题

      它发生在以下地方之一:

      • 我将产品添加到购物车。
      • 在结帐页面上,如果我点击“下订单”按钮

      所以它会抛出以下错误:

      Unable to save address. Please check input data.
      

      我在服务器上做了以下操作: 在 Plesk 上,我必须从

      更改 php 的 include_path

      .:/opt/plesk/php/7.0/share/pear

      .:/var/www/vhosts/mysitehomedir/vendor/magento/zendframework1/library

      保存更改,然后重新启动 apache。 然后刷新了Magento Cache,然后我的问题就解决了。

      希望对你也有帮助!

      【讨论】:

        猜你喜欢
        • 2019-05-06
        • 1970-01-01
        • 2020-04-05
        • 2013-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多