Hi,
1. If you disable the HikaShop cart notification plugin, AND you don't have the HikaShop cart module displayed on the page, the system will automatically redirect to the checkout after an add to cart.
Alternatively, you can also configure the settings of the HikaShop cart notification plugin to redirect to the checkout on success. This approach is recommended to better handle error messages when a problem happens during the add to cart process (for example, if the product can't be added because of a limit rule).
2. In the Products>Limits menu, you can configure limits on purchases. So, for example, you can configure a limit rule to restrict the cart to a quantity of 1. When you do so, if a user tries to add a product to his cart and he already has a product in his cart, the add to cart will be refused and he will see an error message explaining that he can only have 1 product in his cart.
3. Now, what I said in point 2 is not exactly what you want.
To get that, you'll have to develop a small plugin. I would recommend implementing the event onBeforeCartLoad(&$cachedCart, &$options)
In it:
- Check the URL of the current page. If it's not an add to cart request, skip.
- Then, also use a static variable so that you only do your process once ( because after the product is add to the cart in the database, the cart in memory is cleared and reloaded, and you don't want to delete the product from it at that point ).
- Then, get the cart id from HikaShop:
$cartClass = hikashop_get('class.cart');
$id = $cartClass->getCurrentCartId();
If the id returned is empty, skip.
- Finally, you can run a MySQL query on the hikashop_cart_product table to delete the entries where the cart_id is equal to what you have in $id. It is important to directly run a MySQL query with Joomla's functions, and not use the save process of class.cart to avoid a potential loop of the code.
That way, the add to cart process will go like that:
- the cart controller get the request
- the method addProduct of class.cart is called
- the current cart starts loading. If no cart, it is created in the database in the hikashop_cart table
- onBeforeCartLoad is called
- your plugin delete existing products already in the cart
- the cart loading process continues the loading of the cart by loading the products of the current cart if any
- the product being added, is actually added to the cart in the database
Your plugin should only have a dozen lines of code, so, if you're a developer, it should not be a problem. And in that case, you don't want to use the limits system in HikaShop.