Hi,
Well, I'm not sure about the code.
I suppose it should be something like that:
function onAfterCartSave(&$cart) {
$oldcoupons = array();
$newcoupons = array();
if(!empty($cart->old->cart_params->additional)) {
foreach($cart->old->cart_params->additional as $additional) {
$oldcoupons[] = $additional->name;
}
}
if(!empty($cart->cart_params->additional)) {
foreach($cart->cart_params->additional as $additional) {
$newcoupons[] = $additional->name;
}
}
if(count($newcoupons) < count($oldcoupons)) {
// a coupon has been deleted, add your code there
}
}
Note that this will probably not work as I haven't tested it.
The first thing I would do is to have only hikashop_writeToLog($cart);
in the function, run my test and check the "payment log file" of the HikaShop configuration. At the end I should have a cart object with the data of the cart, including $cart->cart_params and $cart->old->cart_params
That way, I could make sure that the data in these indeed reflect the coupon being removed, and that they are in the correct format as you actually might need to json_decode the params before running the foreach on them.
$cart->additional is where the additionals are added to the $cart object when a cart is loaded. There is no "additional" column in the hikashop_cart table in the database. cart_params is the name of the column of hikahsop_cart where all extra data regarding a cart is stored in the database, including the additionals.