【发布时间】:2014-11-11 02:44:53
【问题描述】:
我目前正在为 OpenCart 开发提交订单 API。这个 API 的目的不是为了 OpenCart 的网页部分,而是为了我们的移动应用与 OpenCart 交互。
根据我的研究,提交订单似乎有两种方式:
方法一:
在 OpenCart 网页上,当您想实际提交订单时,您需要完成以下工作流程:
通过
checkout/cart/add将产品添加到购物车通过
checkout/payment_address/validate输入支付地址通过
checkout/shipping_address/validate输入shipping_address通过
checkout/shipping_method/validate输入送货方式通过
checkout/payment_method/validate输入支付方式通过确认/提交订单(我不知道提交订单实际请求的 URL 是什么)。
这种方法的好处似乎是,在客户已登录的条件下,并且您拥有将商品添加到购物车的 API,您不需要不需要通过 URL 中手动将产品添加到购物车的步骤。您还可以在 payment_address 和 shipping_address 中使用 existing 等字符串来表示现有地址(因此您根本不需要在 URL 中手动输入任何内容)。
方法二:
使用checkout/manual。但是,此方法需要完全手动设置所有内容的输入:
store_id
customer_id
customer_group_id
payment_country_id
payment_zone_id
payment_country_id
order_product[]
order_voucher
shipping_method[]
order_total[
contains keys such as code, title, text, value, and sort_order]支付[]
可能遗漏了什么..
checkout/manual 的使用似乎是我们需要的 API,我特别喜欢如果请求不成功它会返回警告/错误消息 - 但是,第一种方法允许客户拥有一个接口,用于将产品添加到购物车并访问现有变量,例如 shipping_address、payment_address 等,前提是他们已登录(我知道有代码可以执行 cart->clear() 和 customer->logout() 如果用户已登录)。
我的问题是 - 以前有没有人实施过手动签出?你是如何实施的?
更新:
目前正在编写一个脚本,将一些虚拟输入发布到checkout/manual:
public function submit()
{
# Our new data
$data = array(
"store_id" => 0,
"customer" => "My Name",
"customer_id" => 1,
"customer_group_id" => 1,
"payment_country_id" => 223,
"payment_zone_id" => 3663,
"order_product[0][product_id]" => 1791,
"order_product[0][quantity]" => 1,
"order_product[0][price]" => 5.01,
"order_total[0][code]" => "sub_total",
"order_total[0][title]" => "Sub-Total",
"order_total[0][text]" => "$5.01",
"order_total[0][value]" => 5.01,
"order_total[0][sort_order]" => 1,
"order_total[1][code]" => "total",
"order_total[1][title]" => "Total",
"order_total[1][text]" => "$5.01",
"order_total[1][value]" => 5.01,
"order_total[1][sort_order]" => 9,
"payment_firstname" => "My",
"payment_lastname" => "Name",
"payment_company" => "SomeCompany",
"payment_address_1" => "#123 1234 NameOf street",
"payment_address_2" => "",
"payment_postcode" => "12345",
"payment_city" => "New York",
"shipping_firstname" => "My",
"shipping_lastname" => "Name",
"shipping_company" => "SomeCompany",
"shipping_address_1" => "#123 1234 NameOf street",
"shipping_address_2" => "",
"shipping_postcode" => "12345",
"shipping_city" => "New York",
"shipping" => "free.free",
"shipping_method" => "Free Shipping",
"shipping_code" => "free.free",
"shipping_country_id" => 223,
"shipping_zone_id" => 3663,
"payment" => "cod",
"payment_method" => "Cash On Delivery",
"payment_code" => "cod",
"order_status_id" => 1
);
# Create a connection
$url = HTTP_SERVER . 'index.php?route=checkout/manual';
$ch = curl_init($url);
# Form data string
$postString = http_build_query($data, '', '&');
# Setting our options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Get the response
$response = curl_exec($ch);
echo $response;
curl_close($ch);
}
但是,返回的数据是这样的:
{"error":{"warning":"You do not have permission to access this page, please refer to your system administrator."}}
更新 2:
由于我在调用checkout/manual 时无法满足这两个条件中的任何一个而引发错误:$this->user->isLogged() && $this->user->hasPermission('modify', 'sale/order')
我通过将其替换为true 暂时将其删除,因此我始终可以手动添加订单。
使用我的输入参数,我确实得到了这个 JSON:
"success":"Order totals has been successfully re-calculated!",然而,检查行政命令列表,并没有出现新的命令被添加。
更新 3:
尽管可以创建订单,但我不知道如何提交订单。
【问题讨论】:
-
这种非常骇人听闻的方法与其他前端文件一起使用的唯一原因是它可以更轻松地访问后端不存在的总计模块。它是管理编辑顺序页面的一部分(特别是用于更新总数)。我强烈建议忽略它并创建自己的方法。