使用 PrestaShop 的 API 创建订单 [英] Create order with PrestaShop's API

查看:53
本文介绍了使用 PrestaShop 的 API 创建订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PrestaShop 1.6.0.9,我正在尝试创建一个新订单.我正在执行以下步骤:

I have a PrestaShop 1.6.0.9 and I'm trying to create a new order. I'm following the following steps:

  1. 使用我之前创建的客户的安全密钥、我想购买的产品的 ID 和数量创建一个购物车.

  1. Create a cart with the security key of the client I have previously created, the id of the product I want to buy and the quantity.

然后创建一个新订单(发送 POST 到 /api/order),传递客户端 ID、安全密钥、产品 ID、价格(含税和不含税), 等等...这是我发送的整个 XML:

Then create a new order (sending a POST to /api/order), passing the client id, the security key, the product id, the prices (with and without taxes), etc... This is the entire XML that I send:

<?xml version="1.0" encoding="UTF-8"?><prestashop><order><id_address_delivery>5</id_address_delivery><id_address_invoice>5</id_address_invoice><id_currency>1</id_currency><id_lang>1</id_lang><id_customer>2</id_customer><id_carrier>1</id_carrier><current_state>2</current_state><valid>1</valid><module>cashondelivery</module><payment>Pago en metalico</payment><conversion_rate>1</conversion_rate><security_key>1e87b5d59d7c812a9d840a548e4b8a45</security_key><associations><order_rows><order_rows><product_id>7</product_id><product_attribute_id>34</product_attribute_id><product_quantity>1</product_quantity></order_rows></order_rows></associations><id_cart>42</id_cart><total_paid>24.85</total_paid><total_paid_real>24.85</total_paid_real><total_products>20.54</total_products><total_products_wt>24.85</total_products_wt></order></prestashop>

如您所见,我正在使用现金递送"模块.我的问题是,当我将该 XML 发布到 API 时,订单已创建,但是:

As you can see, I'm using the "cashondelivery" module. My problem is that when I post that XML to the API, the order get's created, but:

  1. 不知何故,订单没有显示在订单列表中,但如果我转到客户 -> 购物车 -> "我在发布订单之前创建的购物车 ID,我可以找到该订单XML" -> 从此购物车创建的订单.

  1. Somehow the order doesn't show up in the orders list, but I can get to that order if I go to "Clients -> shopping carts -> "id of cart I created before POST-ing the order XML" -> order created from this cart.

一旦我在订单中,我就看不到客户的详细信息(因为客户的 id 没有被插入).我很确定 ID 为 2 的客户端确实存在,但我不确定为什么它没有与我发送到 API 的 POST 一起插入.

Once I'm in the order, I can't see the client details (because the id of the client doesn't get inserted). I'm pretty sure that the client with id 2 does exist, but I'm not sure why it isn't inserted with the POST I'm sending to the API.

知道为什么会发生这两个问题吗?

Any idea why any of those two problems are happening?

推荐答案

我会为所有从 Google 来到这里的人发布答案.即使 PS 文档说不需要 id,您也必须传递购物车和订单中的每个 id 字段.

I'm posting the answer for anybody who gets here from Google. Even if PS docs say ids aren't required, you must pass every id field in both the cart and the order.

这意味着,您必须在创建购物车和创建订单时提供客户 ID、地址 ID、送货地址 ID 等.

That means, you must provide a client id, an address id, delivery address id, etc... when you're creating the cart and when you're creating the order.

如果您不这样做,您的订单可能会被插入,也可能不会.而且,如果它确实被插入,则不能保证它会显示在订单"列表中.

If you fail at doing so, yourorder might get inserted, or it might not. And, if it does get inserted, it's not guaranteed that it will show up in the "Orders" listing.

这篇关于使用 PrestaShop 的 API 创建订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆