Page 1 of 1

shopping cart x not working

Posted: Sun Apr 23, 2017 7:51 pm
by ianhaney
Hi

I have noticed a bug on my shopping cart page, when adding a product to the shopping cart, I click on the X to remove it but it does not remove it from the page, it removes it from the mini cart in the header but not on the actual page, I am using opencart 2.0.3.1. Has anyone had this issue before or got a solution.

The URL is https://www.broadwaymediadesigns.co.uk/store/ - add any product and try and remove it on the page and will see the issue

UPDATE: I have SEO URL'S enabled and looking on Google it could be to do with the SEO URL's feature being on and that is the issue, I'll keep looking and post a solution if manage to find one

Thank you in advance

Re: shopping cart x not working

Posted: Wed Apr 26, 2017 4:05 pm
by imdevlper18
Its not a bug but because you have added seo keyword to your cart and checkout page.
The refresh has stopped on above pages. Before seo keyword entered there must be refresh happening when you changed anything on this page.
You need to edit common.js file of your theme for this fix.

For default theme its present on this path:

Code: Select all

catalog/view/javascript/common.js
If using custom theme you shall need to edit your common.js file which has below code in it.

In this file, look for this line:

Code: Select all

if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
The above line says that if its checkout/cart or checkout/checkout page then do the refresh.
But after your seo keyword entry this urls have changed.

So you add this line instead of above line:

Code: Select all

if ($(location).attr('href') == 'Your shopping cart url' || $(location).attr('href') == 'Your checkout url') {
With this change it shall now refresh the page.
For more help contact directly via email: support@cartbinder.com

Re: shopping cart x not working

Posted: Wed Apr 26, 2017 5:05 pm
by ianhaney
Hi

I have done the change in the two common.js files as had one in the theme js folder as well but is still not refreshing

below is the coding I have

this is what it was

Code: Select all

if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
I changed it to below

Code: Select all

if ($(location).attr('href') == 'cart' || $(location).attr('href') == 'checkout/checkout') {
the original code was appearing three times so changed it 3 times

I will email you now or you on skype?

Re: shopping cart x not working

Posted: Sat Jun 03, 2017 11:37 pm
by thekrotek
ianhaney wrote:
Wed Apr 26, 2017 5:05 pm
I have done the change in the two common.js files as had one in the theme js folder as well but is still not refreshing
It's not working, because $(location).attr('href') is a FULL URL, not just part of it. And you only put "cart". Should be something like "http://yourstore.com/cart".

If you want to use only part of the URL without domain, use "pathname" instead of "href". Here's a better code for this:

Code: Select all

if (($(location).attr('pathname') == '/cart') || ($(location).attr('pathname') == '/checkout')) {
	location = $(location).attr('href');
}
But the best approach is to expand "update" and "remove" functions like this:

Code: Select all

(function($) {
	var originalRemove = cart.remove;
    
	cart.remove = function(product_id) {
		$.ajax(originalRemove(product_id)).done(function() {
			cart_url = "/cart";
			checkout_url = "/checkout";

			if (!getURLVar('route') && ((cart_url && (($(location).attr('pathname') == cart_url) || ($(location).attr('pathname') == cart_url + "/"))) || (checkout_url && (($(location).attr('pathname') == checkout_url) || ($(location).attr('pathname') == checkout_url + "/"))))) {
				location = $(location).attr('href');
			}
		});
	};
})(jQuery);
First this code takes original cart.remove() function, wraps it in ajax() function, calls it, waits for function to complete and only then reloads the page, if necessary. To avoid multiple reloads it checks for lack of "route" variable in URL. Plus I've added a check for URL with trailing slash.

It should work with all themes, not just with default one, since this code allows original function to do its job.

Re: shopping cart x not working

Posted: Thu Mar 14, 2019 9:55 pm
by legitdev
Hi, please see the attached two screenshot image.
When I click on "Buy Now" bottom, it will add it to the Shopping Cart, but when I click "Continue Shopping" I don't see a "View Cart" on the Top Menu or the site or anywhere. Please help with this issue as soon as you can. I have version 2.2.0.0

Thank you