This Product Is Already In The Cart / Clear Cart Before Adding Product To It

Hello,

I am facing a problem when the following steps are followed:

1. I add a product to a cart and proceed to checkout.

2. I go back to the product page without completing the checkout

3. If I try to add the same product with the exact same options at the cart I get a notification "This product is already in the cart".

- Is there a way to skip that check?

I want to allow the customers to add the same product.

Actually the case for the shop is that only one product will be placed at the cart at a time, so if there is way to empty the cart before any other check is made when the "buy now" button is pressed, I guess my problem will be solved.

- I empty the cart before the add to cart but I guess that that function is called after the check that results to the notification is called.

function fn_addonName_pre_add_to_cart( $product_data, &$cart, &$auth, $update){
//clear cart before adding new items
fn_clear_cart($cart, true, true);
}

Any help is appreciated.

Hello, please try to move this function (fn_clear_cart) to the pre controller (app/addons/addonName/controllers/frontend/checkout.pre.php). For example in this way:

$cart = & Tygh::$app[‘session’][‘cart’];

if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
if ($mode == ‘add’) {
fn_clear_cart($cart);
}
}

Hello, please try to move this function (fn_clear_cart) to the pre controller (app/addons/addonName/controllers/frontend/checkout.pre.php). For example in this way:

$cart = & Tygh::$app[‘session’][‘cart’];

if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
if ($mode == ‘add’) {
fn_clear_cart($cart);
}
}

Thank you very much!

This worked for me with a small change.

I replaced $cart = & Tygh::$app['session']['cart']; with $cart = &$_SESSION['cart'];

Not sure if it has something to do with missing "use" statements in my part, but it works now.

Thanks!