- Posts: 252
- Thank you received: 1
remove products from cart when checking out programmatically
8 years 3 months ago #294064
by twscott
-- 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
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.
8 years 3 months ago #294065
by nicolas
Replied by nicolas on topic remove products from cart when checking out programmatically
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.
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.
8 years 3 months ago #294203
by twscott
Replied by twscott on topic remove products from cart when checking out programmatically
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
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.
8 years 3 months ago #294210
by nicolas
Replied by nicolas on topic remove products from cart when checking out programmatically
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 :
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 :
Code:
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.177 seconds