Post by soydemadrid » Fri Dec 13, 2024 12:42 am

Hi guys, I hope you can please help.

I've been having a lot of problems where I'm constantly refunding customers for duplicate orders because they don't notice that they already have items in their cart from previously browsing my shop.

This bug has come up in the past with Opencart, and I realise it is a "design decision" and is happening on purpose, but it's really costly and frustrating being asked to send refunds all the time. Especially as the payment merchants I use won't refund payment processing fees which are paid on these duplicates.

Does anyone know of a clean way to get Opencart to not save the cart and remove any warnings from the logout that does mention this? You would think it's pretty obvious the cart is saved and customers would see they're paying for more than one of the same item, but what's obvious to the shop owner or dev is often not obvious to the end user. As I'm being asked for refunds regularly for duplicate items by mistake, then it must not be as obvious as it seems.

Many thanks for your help to fix this.

New member

Posts

Joined
Thu May 07, 2015 3:03 pm

Post by Johnathan » Fri Dec 13, 2024 6:44 am

I had the same problem on my own website years ago so I just stopped re-adding products to the cart when someone logs in. You'd be surprised at how many people (even web developers) don't check their cart before paying.

The following edit should stop the saved cart data from coming back when a customer logs in, but obviously that means customers can't store things in their cart. If you want to stop saving cart data then you can do this in OpenCart 3.0:

------------------------------------------------------------------------------
IN:
/system/library/cart/cart.php

REPLACE:
$this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);

WITH:
//$this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
------------------------------------------------------------------------------

I don't really recommend this solution for all stores, but it may be less annoying that having to process refunds for customers that don't pay attention.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Joe1234 » Fri Dec 13, 2024 11:08 am

There's an idea for an extension if someone wants to take it on.
A/ To do something like amazon and you have to check the items in your cart before you checkout.
B/ After 24 hours in the cart you have to check a checkbox for items you want to checkout.
C/ 24 hours passes contents of the cart are moved to a secondary cart or save for later which the customer can clearly see from the "main" checkout cart.

New idea for an extension for the marketplace instead of all those redundant extensions in there.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by paulfeakins » Fri Dec 13, 2024 8:26 pm

Joe1234 wrote:
Fri Dec 13, 2024 11:08 am
New idea for an extension for the marketplace instead of all those redundant extensions in there.
Why don't you develop it?

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by soydemadrid » Fri Jan 03, 2025 8:27 pm

Thanks guys, I added the modification Johnathan kindly posted. But for some reason I'm still having to process refunds for customers fairly regularly, so persistent carts seem to still remain despite the code hack... Could this just be due to customers having old cookies in their browsers from when they visited the site before the change?

New member

Posts

Joined
Thu May 07, 2015 3:03 pm

Post by nonnedelectari » Sat Jan 04, 2025 8:55 am

The cart code uses this:

Code: Select all

		// Remove all the expired carts with no customer ID
		$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE (api_id > '0' OR customer_id = '0') AND date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");

		if ($this->customer->getId()) {
			// We want to change the session ID on all the old items in the customers cart
			$this->db->query("UPDATE " . DB_PREFIX . "cart SET session_id = '" . $this->db->escape($this->session->getId()) . "' WHERE api_id = '0' AND customer_id = '" . (int)$this->customer->getId() . "'");

			// Once the customer is logged in we want to update the customers cart
			$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '0' AND customer_id = '0' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");

			foreach ($cart_query->rows as $cart) {
				$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart['cart_id'] . "'");

				// The advantage of using $this->add is that it will check if the products already exist and increaser the quantity if necessary.
				$this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
			}
		}
so

1) it deletes all cart items after 1 hour unless it belongs to a registered customer .
2) then it sets the current session id to all old (saved) cart items of the current signed in customer.
3) then it selects all cart items the customer added to his cart prior to signing in, deletes them and adds them again one by one.

so, commenting out the addition of step 3 does not prevent the addition of the old saved customer cart items back into his current cart as that is done in step 2.
It does delete all items the customer added as a guest before signing in which is not what you want.

In other words, either don't save customer carts, i.e. delete them just like all the others or give a warning and optionally a choice to add those saved cart items to their current cart or delete them. For that you would first have to check whether there are any cart items with the customer's id and a session id not equal to his/her current one.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm
Who is online

Users browsing this forum: No registered users and 13 guests