Jump to content

How To Make Cart Accept Only One Product (1.7.x)


ZiedDams

Recommended Posts

I want to make the Cart accept only one product in a way that:

when i add a product to the cart it erase the old one and put the new product in place ,

I actually found some content on this topic, But it's so old, And they give a solution that display an error in the front office if a user add more then one product to the cart, Which is not my case .

I know that i have to Override controllers/front/CartController.php

But i don't know what function i should modify and what to write in place

Link to comment
Share on other sites

You can use the "actionCartUpdateQuantityBefore" hook, check in parameters which product is added to the cart, and if it is different, you can delete the current product. But I think it would be okay to delete directly through a query, not to use a method, so as not to call that hook again.

  • Like 1
Link to comment
Share on other sites

16 hours ago, Ress said:

You can use the "actionCartUpdateQuantityBefore" hook, check in parameters which product is added to the cart, and if it is different, you can delete the current product. But I think it would be okay to delete directly through a query, not to use a method, so as not to call that hook again.

Thank you for this solution, yeah it's a good idea, without even overriding the CartController.php Great

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...