Page 1 of 1
cart page doesn't refresh when remove item with SEO mods.
Posted: Thu Jun 01, 2017 7:04 am
by qtwrk
Hi , I'm on 2.3.0.2 and I installed , and tried sevaral SEO mods that makes URL from
into , for example,
but one problem I noticed is that , with SEO URL changed , when you remove items in cart , the page doesn't refresh itself to show the change.
I guess is that "remove button" doesn't know the new URL to redirect/refresh.
so could anyone please tell me how to do it ?
I mean , when click "remove" button , page will refresh in default opencart , so where is that part of code located ? because I guess I could manually change it to new URL to make it work ?
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Sat Jun 03, 2017 8:06 pm
by imdevlper18
I have answered this question here:
viewtopic.php?f=191&t=183622#p672322
You need to change your shopping cart link in common.js file.
And it shall be fixed. You can read above topic.
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Mon Jun 05, 2017 3:43 am
by qtwrk
thanks for the help
just tried , and it didn't work.
I changed the line you mentioned in that thread , into this
Code: Select all
if (($(location).attr('pathname') == '/checkout-cart.html') || ($(location).attr('pathname') == '/checkout-processing.html')) {
location = $(location).attr('href');
}
but unfortunately nothing happens ...
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Mon Jun 05, 2017 3:47 am
by qtwrk
the code you mentioned there
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);
should I replace it from
Code: Select all
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
?
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Mon Jun 05, 2017 6:24 am
by thekrotek
qtwrk wrote: ↑Mon Jun 05, 2017 3:43 am
but unfortunately nothing happens ...
You keep failing, because you blindly copy the code without even trying to understand it. If you want to do coding yourself, you at least should learn the basics of debugging. So wrap location['href'] or location['pathname'] in alert() and see the actual value of these variables on cart and checkout pages, instead of constantly putting something you think is right.
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Mon Jun 05, 2017 2:40 pm
by imdevlper18
Krotek is correct. When you are copying a code, just try to read little so you can do it correct.
See the code below:
Code: Select all
if ($(location).attr('href') == 'Your shopping cart url' || $(location).attr('href') == 'Your checkout url') {
Here can you see "Your shopping cart url". In this add your shopping cart url. So it shall be:
Code: Select all
if ($(location).attr('href') == 'https://www.store.com/cart' || $(location).attr('href') == 'https://www.store.com/checkout) {
You can see above i added example store url in place of "Your shopping cart url". Kindly add your store url here.
Hope this helps. You can also do this based on krotek answer i.e via pathname.
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Tue Jun 06, 2017 6:04 am
by qtwrk
sorry for my stupidity , I don't really understand the PHP nor HTML , as matter of fact I don't even speak very well English...
but I did read through that post...
I tried that
Code: Select all
if (($(location).attr('pathname') == '/checkout-cart.html') || ($(location).attr('pathname') == '/checkout-processing.html')) {
and
Code: Select all
if ($(location).attr('href') == 'https://xxx/checkout-cart.html' || $(location).attr('href') == 'https://xxx/checkout-processing.html') {
but .... both of them failed...
I also clicked "refresh" button in extension page.
but one thing I do noticed and which is weird is that, even I disabled SEO URL and with modified common.js file , the default route index.php?route=checkout/cart still works
so can I assume somehow , the change I did in common.js didn't affect anything ?
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Tue Jun 06, 2017 5:53 pm
by imdevlper18
Hi,
Your store url ?
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Thu Jun 08, 2017 6:35 am
by qtwrk
imdevlper18 wrote: ↑Tue Jun 06, 2017 5:53 pm
Hi,
Your store url ?
Hi , I've PM'ed you the URL.
and suddenly something comes to my mind , I have Cloudflare , maybe the cached JS in Cloudflare is what causing me the problem for common.js doesn't have affect , I'm gonna try it again and see how it goes.
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Thu Jun 08, 2017 6:52 am
by qtwrk
Hi , sorry again , for my stupidity
problem is solved.
I posted here in case someone got same problem as I did.
prior to the code mentioned before,
this line of code
Code: Select all
location = 'index.php?route=checkout/cart';
just under the line mentioned in early of the thread
Code: Select all
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
should also be changed into new URL.
otherwise , the new URL will turn back to old URL and stop working.
for example , new URL is
http://xxx/cart.html
the first click on remove will refresh the page into
http://xxx/index.php?route=checkout/cart and then second time to remove item will NOT refresh the page on its own.
and be aware of CACHE.
I also forgot to clear my browser cache alone with Cloudflare cache.
there is a good way to determinate if JS file is changed by access directly
http://xxx/catalog/view/javascript/common.js to see the file is changed or not.
thanks for you help

Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Thu Jun 08, 2017 1:45 pm
by imdevlper18
Great !!
Sometimes Cache is the main issue despite fixing things.
It is good to clear cache if using some cache software or cloudfare.
Re: cart page doesn't refresh when remove item with SEO mods.
Posted: Fri Jun 09, 2017 1:56 am
by qtwrk
imdevlper18 wrote: ↑Thu Jun 08, 2017 1:45 pm
Great !!
Sometimes Cache is the main issue despite fixing things.
It is good to clear cache if using some cache software or cloudfare.
just wondering here ,
viewtopic.php?f=191&t=183622#p672322 this thread last post , there is seems a better approach
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);
how am i to do that ? replace the line with it ?
Code: Select all
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {