Jump to content

Add product in a order via php


auroncaos

Recommended Posts

Hello there, I have a list of control / function for add by php a "new" product (not listed) in a new cart if cart not already exists, otherwise just add the product in the current cart of the selected users with

$cart->updateQty(1, $ID_PRODUCT);

I have included the following:
 

require_once('config/config.inc.php');
require_once('init.php');

 

 

Now I need a function for add a product in a actual order (after a check if the order is still avaiable for editing, like "waiting for payment" etc) 
No problem on the check, but in the adding, there is some function I can use? 


Somebody can help me with some hint?

 

for now I have this:

//for example, my order have id 10, so I use 10

$order= new Order(10);
$id_cart = $order->id_cart;

$cart = new Cart($id_cart);

//I have an ID product to add called $id_product
$cart -> updateQty(1,$id_product);
$cart->update();
$cart->save();
$id_carrier = $order->id_carrier;
 
$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();	

this give an updated cart of references, an updated total price and so on, but the "internal cart" aka the order details are not updated.
i tried several ways but I can't find anything.

I got the order detail at least (always with 10 as ID) 
 $list= OrderDetail::getList(10);

 

 

 

Edited by auroncaos (see edit history)
Link to comment
Share on other sites

  • 1 year later...

I have the exactly same issue, any ideas?

I found out that this is related to OrderDetail . The products in the order details are not getting updated.

 

$orderDetail = OrderDetail::getList((int)$order->NumarComanda);
$detailedOrder = (object)$orderDetail[0];
$products = $cart->getProducts(); $id_order_state = 4; // hardcoded 4 for testing purposes.
$detailedOrder->createList($prestashopOrder, $cart, $id_order_state, $products);

Currently this returns an error, I am trying to update the orderdetail.

Edited by andtrx (see edit history)
Link to comment
Share on other sites

  • 1 month later...

try :

where $order is the order object from prestashop then

    $cart = new Cart($order->id_cart);
    $product_list = $cart->getProducts();

 

 

$order_detail = new OrderDetail(null, null, null);
$order_detail->createList($order, $cart, 1, $product_list, 0, true, 0);
$order_detail_list[] = $order_detail;
      

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...