When creating order from cart - cart stays filled with order

  • Posts: 62
  • Thank you received: 1
5 years 3 months ago #301624

-- HikaShop version -- : 4.0.1
-- Joomla version -- : 3.9.1
-- PHP version -- : 7.2
-- Browser(s) name and version -- : Chrome latest
-- Error-message(debug-mod must be tuned on) -- : none

-- HikaShop version -- : 4.0.1
-- HikaMarket version -- : 3.0.0
-- Joomla version -- : 3.9.1
-- PHP version -- : 7.2
-- Browser(s) name and version -- : Chrome latest
-- Error-message(debug-mod must be tuned on) -- : none

I've created a cronjob checking for EDI orders and creating them when one is there. The webshop has hikashop and hikamarket.
See also www.hikashop.com/forum/23-market-how-to/...kmarket-vendors.html

It all works like a charm, but there is one annoying side-effect. When creating the order from the cart in this cronjob, the order is created but the cart is not emptied so it seems.

The code is as below:

		$cart = new stdClass();
		$cart->user_id = $user_id;
		$cart->cart_shipping_address_ids = $shipping_address;

		// Save an entry to DB to be able to get cart_id
		$cartClass->save($cart);

		$cart_id = $cartClass->getCurrentCartId('cart');

		// Add all selected products at once
		$cartClass->addProduct($cart_id, $product_data);

		// Create basic order from cart
		$orderClass = hikashop_get('class.order');
		$order = $orderClass->createFromCart($cart_id);

		// Retrieve current order to update for custom fields
		$updateOrder = new stdClass();
		$updateOrder = $orderClass->get($order->order_id);

		// Update custom field date values
(...) // some extra code for custom fields and such

		// Save order with custom field values
		$orderClass->save($updateOrder);

I am sure I am doing something wrong, any idea how to debug?

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

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
5 years 3 months ago #301638

Hi,

Well, you need to clear the cart after you've created the order out of it:

$cartClass = hikashop_get('class.cart');
$cartClass->cleanCartFromSession();

The following user(s) said Thank You: nuntius

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

  • Posts: 62
  • Thank you received: 1
5 years 3 months ago #301690

Well, that makes perfectly sense. I had the assumption it would clear itself (silly perhaps?).

Thanks for the quick reply!

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

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
5 years 3 months ago #301692

Hi,

We don't clear the cart right away usually. We do it when the customer comes back on the website after the payment. That way, if the user cancelled the payment on the payment gateway, we can easily redirect him back to the checkout with his cart after cancelling the order. It depends on how you configure the "clear cart when order is" setting of the HikaShop configuration.

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

Time to create page: 0.062 seconds
Powered by Kunena Forum