Php Prestashop-在订单中添加产品,更新订单详细信息

Php Prestashop-在订单中添加产品,更新订单详细信息,php,prestashop,script,Php,Prestashop,Script,我正在尝试“更新”订单(在检查状态后,确保它仍在等待付款),我需要添加新产品。我可以在后台完成,但出于长期的原因,我尝试使用外部脚本 现在我已经创建了一个带有图像和它所需的所有信息的产品,我已经有了一个脚本,可以将其添加到购物车或创建一个新购物车等 现在,我正在尝试按当前订单添加产品: //for example, my order have id 10, get it after some check of eligibility, so I use 10 in this case $ord

我正在尝试“更新”订单(在检查状态后,确保它仍在等待付款),我需要添加新产品。我可以在后台完成,但出于长期的原因,我尝试使用外部脚本

现在我已经创建了一个带有图像和它所需的所有信息的产品,我已经有了一个脚本,可以将其添加到购物车或创建一个新购物车等

现在,我正在尝试按当前订单添加产品:

//for example, my order have id 10, get it after some check of eligibility, so I use 10 in this case

$order= new Order(10);
$id_cart = $order->id_cart;
//I get the cart id references
$cart = new Cart($id_cart);

//I have an ID product to add called $id_product (again after creation of product etc)
$cart -> updateQty(1,$id_product);
$cart->update();
$cart->save();
$id_carrier = $order->id_carrier;
 // then after updated my cart (just for references, as backoffice do) I update all price in my order
$order->total_products = (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier);
$order->total_products_wt = (float)$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier);
$order->total_discounts_tax_excl = (float)abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier));
$order->total_discounts_tax_incl = (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier));
$order->total_discounts = $order->total_discounts_tax_incl;

$order->total_shipping_tax_excl = (float)$cart->getPackageShippingCost((int)$id_carrier, false, null, $order->product_list);
$order->total_shipping_tax_incl = (float)$cart->getPackageShippingCost((int)$id_carrier, true, null, $order->product_list);
$order->total_shipping = $order->total_shipping_tax_incl;


$order->total_wrapping_tax_excl = (float)abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier));
$order->total_wrapping_tax_incl = (float)abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier));
$order->total_wrapping = $order->total_wrapping_tax_incl;

$order->total_paid_tax_excl = (float)Tools::ps_round((float)$cart->getOrderTotal(false, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_incl = (float)Tools::ps_round((float)$cart->getOrderTotal(true, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid = $order->total_paid_tax_incl;
$order->round_mode = Configuration::get('PS_PRICE_ROUND_MODE');
$order->round_type = Configuration::get('PS_ROUND_TYPE');

 $order->update();
  $order->save();   
现在我只错过了“添加”订单详细信息的部分,我可以直接在数据库上使用sql来完成,但我更喜欢使用prestashop的类和脚本来确保没有错误

其中:$list=OrderDetail::getList(10);我得到了订单列表(它可以工作),但我找不到任何东西来设置它

我在网上搜索,发现如下内容:

$order_detail = new OrderDetail(null, null, $this->context);
$order_detail->createList($order, $cart, $id_order_state, $order->product_list, 0, true, $package_list[$id_address][$id_package]['id_warehouse']);
$order_detail_list[] = $order_detail;
但是我找不到一个方法来适应它。有什么帮助吗?谢谢

Ps:使用该单个部分的直接sql,因此仅表order\u details中的产品在每个部分都可以正常工作,我可以解决这个问题,但如果我可以通过类或方法来完成,我不喜欢使用直接sql,但我找不到它。:-)