Magento 2 API不返回总价和结帐项



我有一个完全工作的Magento 2网站,现在我想使用API来创建一个移动应用程序,所以我使用rest API来结帐和下单。

shipping-informationAPI中的问题,它不返回订单项目和订单总数,因此我可以在移动应用程序结帐页面中显示它们。我使用的流程是这样的:

  1. 使用此API获取客户令牌POST {{base_url}}/integration/customer/token
  2. 使用此apiPOST {{base_url}}/carts/mine为客户创建报价,返回quote_id
  3. 使用此APIPOST {{base_url}}/carts/mine/items添加商品到购物车,请求正文为
{
"cartItem":{
"qty":1,
"quoteId":"87846",
"sku":"8681124614421"
}
}

,响应是

{
"item_id": 48508,
"sku": "8681124614421",
"qty": 2,
"name": "MUSK Eau De Parfum 100 ml",
"price": 644.07,
"product_type": "simple",
"quote_id": "87846"
}
  1. 调用预估运输方法如下POST {{base_url}}/carts/mine/estimate-shipping-methods请求主体:
{
"address": {
"street": [
"dsfsdf"
],
"city": "aaasdd",
"region": "",
"country_id": "TR",
"postcode": "12345",
"firstname": "aaa",
"lastname": "bbb",
"telephone": "3213510",
"custom_attributes": [
{
"attribute_code": "student",
"value": "",
"label": " "
}
],
"save_in_address_book": 1
}
}

,响应为:

[
{
"carrier_code": "dhl",
"method_code": null,
"carrier_title": "DHL",
"amount": 0,
"base_amount": null,
"available": false,
"error_message": "This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.",
"price_excl_tax": 0,
"price_incl_tax": 0
},
{
"carrier_code": "flatrate",
"method_code": "flatrate",
"carrier_title": "Flat Rate",
"method_title": "Fixed",
"amount": 10,
"base_amount": 10,
"available": true,
"error_message": "",
"price_excl_tax": 8.47,
"price_incl_tax": 10
}
]
  1. 最后的问题是,我叫POST {{base_url}}/carts/mine/shipping-information
{
"addressInformation": {
"shipping_address": {
"countryId": "TR",
"region": "",
"street": [
"dsfsdf"
],
"telephone": "3213510",
"postcode": "12345",
"city": "aaasdd",
"firstname": "owais",
"lastname": "hamouda",
"saveInAddressBook": 1,
"customAttributes": [
{
"attribute_code": "student",
"value": "",
"label": " "
}
]
},
"billing_address": {
"customerAddressId": "206",
"countryId": "TR",
"regionId": "43",
"regionCode": null,
"region": "Turkey",
"customerId": "492",
"street": [
"160 1st St."
],
"company": "Sawaftech",
"telephone": "516-555-1111",
"fax": null,
"postcode": "11501",
"city": "Mineola",
"firstname": "Jane",
"lastname": "Doe",
"middlename": null,
"prefix": null,
"suffix": null,
"vatId": null,
"customAttributes": []
},
"shipping_method_code": "flatrate",
"shipping_carrier_code": "flatrate",
"extension_attributes": {}
}
}

,响应是:

{
"payment_methods": [
{
"code": "iyzipay",
"title": "Kredi/Banka Kartı ile Ödeme"
},
{
"code": "banktransfer",
"title": "Banka Havalesi Ödeme"
},
{
"code": "cashondelivery",
"title": "Cash On Delivery"
},
{
"code": "stripe_payments",
"title": "Stripe"
}
],
"totals": {
"grand_total": 0,
"weee_tax_applied_amount": null,
"items": [],
"total_segments": [
{
"code": "subtotal",
"title": "Subtotal",
"value": 0
},
{
"code": "shipping",
"title": "Shipping & Handling",
"value": null
},
{
"code": "tax",
"title": "Tax",
"value": 0,
"extension_attributes": {
"tax_grandtotal_details": []
}
},
{
"code": "grand_total",
"title": "Grand Total",
"value": null,
"area": "footer"
}
]
}
}

在这里,您可以看到未从API返回的合计和小合计、合计和项目。我还尝试调用collect-totals API和totalapi,但没有得到任何值。我被困在这个问题上两个星期了,请帮助和建议什么可能是问题,或者我怎么能跟踪它或调试它,如果它是从一个安装的插件,例如。

请注意我用头授权Bearer <customer token>调用它的所有API调用请注意,从网站的流程是正常工作的。

我也一直在使用相同的api。我还没有遇到过这些问题。但是我已经手动更新了总价格。我建议您尝试以下步骤之一:

  1. 检查是否有其他模块覆盖了总计数据。例如,检查是否其中一个方法被称为

    $quote->setTriggerRecollect(1);
    $quote->collectTotals()->save();
    $quote->save();
    
  2. 因为你得到的价格当你添加到购物车,添加一个插件或创建自己的API,看看你是否可以手动设置每次POST/PUT/DELETE请求后的总数。我创建了一个GET请求,该请求显示基于报价ID的自定义购物车数据。类似的事情也可以被复制。

问题是先前开发人员对核心模块的修改,我不得不将源代码与新安装的Magento进行比较以解决问题。

相关内容

  • 没有找到相关文章

最新更新