Create order with current cart

  • Posts: 3
  • Thank you received: 0
  • Hikashop Essential
6 years 8 months ago #274652

Hi

I'm developing a simple plugin and I need to get the current cart and create an order. How can I add the cart product array to the new order.

function onCheckoutWorkflowLoad(&$checkout_workflow, &$shop_closed, $cart_id){

//Get the cart product array
$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart();
$products = $cart->products;

//create the order and set default settings
$order = new stdClass();
$order->order_status = confirmed;
$order->products= array($products);
$orderClass = hikashop_get('class.order');
$orderClass->save($order);

The order is created but the product list does not update. How can i do it?


Thank you!

Please Log in or Create an account to join the conversation.

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
6 years 8 months ago #274653

Hello,

Please indicate the HikaShop version number you're using.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 0
  • Hikashop Essential
6 years 8 months ago #274708

We are using HikaShop Business: 3.1.1

Regards

Please Log in or Create an account to join the conversation.

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
6 years 8 months ago #274723

Hello,

By using HikaShop 3, you can use the new Cart and Order features and also the new API.
The HikaShop Order Class now have a function : createFromCart($cart_id) which allow to process a cart (from its id) and make an order. It will also call all required triggers regarding the shipping and payment methods, perform the redirection to the payment platform if required, etc.

You can use that function if you want ; but you can also use the code in that function if you want to handle all elements when you want to create an order from a cart.
Please note that if you pass the $cart_id " 0 ", the system will load the customer current cart.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum