I'm trying to clear the cart, but i want to keep the last added item.
fn_clear_cart();
Posted 29 November 2020 - 05:29 AM #1
I'm trying to clear the cart, but i want to keep the last added item.
fn_clear_cart();
Posted 29 November 2020 - 08:50 PM #2
function fn_alter_cart_products(&$cart, $leave_items=0) { $item_count = count($cart['products']); if( $item_count > $leave_items ) { $_products = array_reverse($cart['products'], true); foreach($_products as $cartid => $item) { if( $leave_items > 0 ) { $leave_items--; continue; // leave this item } unset($_products[$cart_id]); } $cart['products'] = array_reverse($_products,true); } }
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 05 December 2020 - 09:43 AM #3
function fn_alter_cart_products(&$cart, $leave_items=0) { $item_count = count($cart['products']); if( $item_count > $leave_items ) { $_products = array_reverse($cart['products'], true); foreach($_products as $cartid => $item) { if( $leave_items > 0 ) { $leave_items--; continue; // leave this item } unset($_products[$cart_id]); } $cart['products'] = array_reverse($_products,true); } }I couldn't get this to work bro
Posted 05 December 2020 - 09:02 PM #4
How are you calling it and from where?
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 06 December 2020 - 01:43 AM #5
I don't even know when and how to call it, I tried calling from smarty and controller but it didn't work, how can i call it? Thanks
Posted 06 December 2020 - 07:55 PM #6
I can't answer that for you since I don't know under what conditions you want it to act on the cart. You could call it from a checkout post controller, you could call it from one of the hooks in fn_clear_cart(). Without knowing your business logic it's impossible to say.
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 06 December 2020 - 10:29 PM #7
I can't answer that for you since I don't know under what conditions you want it to act on the cart. You could call it from a checkout post controller, you could call it from one of the hooks in fn_clear_cart(). Without knowing your business logic it's impossible to say.
do i call it like this fn_alter_cart_products(); or just place the code in the controller?
Posted 07 December 2020 - 08:12 PM #8
You would call it with the first parameter being the active $cart and the 2nd argument being the number of items you want left in the cart. It sounds like you do not have any development experience. Suggest you contact a developer (maybe me) with the scenario you want to achieve and let them help you implement it.
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 15 December 2020 - 09:42 PM #9
No, your code is not correct because it's throwing a php error
Posted 16 December 2020 - 08:48 PM #10
No, your code is not correct because it's throwing a php error
Given that it was free and stated as untested, suggest you resolve the php error (since you didn't post it).
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 20 December 2020 - 02:58 PM #11
I'm trying to do this on checkout page, please find a fix, thank you
Posted 21 December 2020 - 09:08 PM #12
If you want help with development, please provide your requirements by clicking the get a quote link in my signature.
EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.
Posted 08 January 2021 - 11:20 AM #13
We have been using this for several weeks now and it seems to be going nicely.
Posted 11 January 2021 - 11:06 AM #14
We have been using this for several weeks now and it seems to be going nicely.
Where did you put the code buddy?
how did you get it to work?