Reputation: 35
i'm dealing with a problem, I need to change the carrier if the cart amount it > 500 , so , I'm hooking actionCartSave and checking the amount , but , when I do
$cart->id_carrier=(int)$carrier_id;
$cart->update();
The ajax stops responding , need to reload the page to see if a product has been added to the cart, but if i remove the $cart->update()
, the carrier does not get updated. How can i solve this?
Upvotes: 1
Views: 513
Reputation: 7320
Maybe you are running into a loop. when you call update
, the hook actionCartSave
gets called again.
What you need to do is avoid updating the cart if the cart carrier is the same one as in your result
if ((int)$cart->id_carrier !== (int)$carrier_id) {
$cart->id_carrier = (int)$carrier_id;
$cart->update();
}
That way, you will avoid the infinite loop
Another (better) solution would be to use $cart->save();
because it doesn't call actionCartSave
Upvotes: 1