remove products from cart when checking out programmatically

  • Posts: 252
  • Thank you received: 1
6 years 10 months ago #294064

-- HikaShop version -- : 3.4.0

hi,
In our shop, when user buy more than $500, he could choose a free gift into cart.
While in checking out, user remove the products from cart we need to check if the gift need to be removed,
Could you tell me which program and how to achieve that?

Thanks

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
6 years 10 months ago #294065

Hi,

You have these triggers which are called each time a product is added or removed from the cart:
onAfterProductCheckQuantities(&$products, &$cart, $options)
onBeforeCartSave( &$cart, &$do)
onAfterCartSave( &$cart)
so you can implement a trigger in a plugin of the group "hikashop" and do the code you want there.
Beware of the fact that if you update the cart with the functions of class.cart while you are in these triggers, you might risk creating a loop which will crash the processing of the page.

The following user(s) said Thank You: twscott

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

  • Posts: 252
  • Thank you received: 1
6 years 10 months ago #294203

Thanks, Nicolas, It works.
But there is a new issue that, the product is removed from the cart in database, but in the front end, the product is still there.
How can I refresh cart in the front end?

Thanks again

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
6 years 10 months ago #294210

Hi,

You'll need to clear the cache of the cart in class.cart and in the checkoutHelper after you change the cart data in the database. I think something like that should help :

hikashop_get('helper.checkout');
$checkoutHelper = hikashopCheckoutHelper::get();
$cartClass = hikashop_get('class.cart');
$cachedCart = $checkoutHelper->getCart();
$cartClass->get('reset_cache',$cachedCart->cart_id);
$checkoutHelper->getCart(true);

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

Time to create page: 0.059 seconds
Powered by Kunena Forum