Url where you will be redirected when cart is empty no longer working

  • Posts: 165
  • Thank you received: 3
7 years 4 months ago #274619

-- HikaShop version -- : 3.1.1
-- Joomla version -- : 3.7.3
-- PHP version -- : 7.0.21

Hi, the URL where you will be redirected when the cart is empty is no longer working when using the new ajax checkout and version 3.1.1. I have this setting set to redirect to a certain url buy-now.html after the cart is empty, but instead since it is using ajax it just empties the cart, but never actually redirects to the url I have set. Instead it leaves you in the cart and shows you a total of zero. Also, I deleted out all of my layout overrides just to check and it still does this so this has to be some sort of bug.

The redirect does however work if after I empty the cart and i manually refresh my browser page. It appears the ajax is just not calling the redirect after deleting the product out. How do I fix this?

Also, attached is my back end settings and what it looks like on the front end instead of redirecting you out of the cart to the buy-now.html like it should.





Thanks,

Josh

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 4 months ago #274621

Hello,

I'm afraid that you do have some customization in your website.
pasteboard.co/GCsUGqL.png

When the checkout cart is refreshed in ajax, HikaShop can add a JS trigger in order to indicate that the cart is empty and that the customer need to be redirected.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 4 months ago #274673

Hi, you are correct I added the customization back. Sorry if I did not mention this previously, but I deleted these layouts out and tested with the default layout and the issue still occurs. It is nothing to do with my customization. This happens with default layouts and with my customization.

Again how do I get it to redirect? There has to be some sort of bug here because it is not redirecting after the cart is emptied.

Thanks,

Josh

Last edit: 7 years 4 months ago by jschroeder.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 4 months ago #274679

Hello,

In the "cart / show" you will find that code :

window.Oby.registerAjax("cart.empty",function(params){ setTimeout(function(){ window.location.reload(); },150); });

It's a JS event that you can get from the checkout modules.
When the checkout cart block is updated, it check if the cart is now empty:
if(empty($cart->products)) {
	$checkoutHelper->redirectBeforeDisplay = JText::_('CART_EMPTY');
}
And that variable in the checkout Helper is used to generated the JS event within the "submitblock" action.
if(!empty($checkoutHelper->redirectBeforeDisplay)) {
	//...
	$checkoutHelper->addEvent('cart.empty', null);
}
So, when a checkout block is submitted and it result that the cart is empty ; the page will be reloaded by javascript and the customer will be then redirected to the "cart empty" page.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 4 months ago #274789

Jerome wrote: Hello,

In the "cart / show" you will find that code :

window.Oby.registerAjax("cart.empty",function(params){ setTimeout(function(){ window.location.reload(); },150); });

I am on version 3.1.1 and the piece of code you are mentioning does not exist in the cart/show file. I just looked it up in fact I am not seeing any of the code you listed above. This is all the javascript that is in the cart /show.php file
<script type="text/javascript">
window.hikashop.ready(function(){
	setTimeout(function(){window.hikashop.dlTitle('hikashop_show_cart_form')},1000);
});
if(!window.cartMgr) window.cartMgr = {};
window.cartMgr.moveProductsTo = function(id, type) {
	var d = document, form = d.getElementById('hikashop_show_cart_form');
	if(!form)
		form = d.forms['hikashop_show_cart_form'];
	if(!form)
		return false;
	form.task.value = 'addtocart';
	form.addto_type.value = type;
	form.addto_id.value = parseInt(id);
	if(typeof form.onsubmit == 'function')
		form.onsubmit();
	form.submit();
	return false;
};
window.cartMgr.checkQuantity = function(el) {
	var value = parseInt(el.value),
		min = parseInt(el.getAttribute('data-hk-qty-min')),
		max = parseInt(el.getAttribute('data-hk-qty-max'));
	if(isNaN(value)) {
		el.value = isNaN(min) ? 1 : min;
		return false;
	}
	if(isNaN(min) || isNaN(max))
		return false;
	if((value <= max || max == 0) && value >= min)
		return true;

	if(max > 0 && value > max) {
		msg = '<?php echo JText::_('TOO_MUCH_QTY_FOR_PRODUCT', true); ?>';
		el.value = max;
	} else if(value < min) {
		msg = '<?php echo JText::_('NOT_ENOUGH_QTY_FOR_PRODUCT', true); ?>';
		el.value = min;
	}
	name = el.getAttribute('data-hk-product-name');
	if(msg && name)
		alert(msg.replace('%s', name));
	return true;
};
window.cartMgr.moveProductsToCart = function(id) { return window.cartMgr.moveProductsTo(id, 'cart'); };
window.cartMgr.moveProductsToWishlist = function(id) { return window.cartMgr.moveProductsTo(id, 'wishlist'); };
</script>

Last edit: 7 years 4 months ago by jschroeder.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 3 months ago #274791

Hello,

I made a typo by typing too fast ; it's the "checkout / show" view..
But anyway, you need to be sure that you're using the latest packages.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 3 months ago #274867

Jerome wrote: Hello,

I made a typo by typing too fast ; it's the "checkout / show" view..
But anyway, you need to be sure that you're using the latest packages.

Regards,


I am using the latest package. I removed my overrides again and I just downloaded the latest package and uploaded the latest show.php file and it still does not work. Still, when you empty the cart it just empties the cart and says total 0 and never redirects. As I said this has to be some sort of bug. How, do I fix this?

Thanks,

Josh

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 3 months ago #274872

Hello,

Well, now in you page source code I can find the line

window.Oby.registerAjax("cart.empty",function(params){ setTimeout(function(){ window.location.reload(); },150); });
But, once again, I can see that you have some custom content in the ajax returned cart view.
So I can't provide any kind of guarantee that the system is really clean and that the cart is not modified by a third party plugin.

All I can tell you is to try to replace in the file "administrator/component/com_hikashop/helpers/checkout/cart.php" the line
if(empty($cart->products)) {
By
if(empty($cart->cart_products)) {
And see if it's change something in the case where you got a third party plugin interacting with the cart...

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 3 months ago #274948

Unfortunately that makes no difference at all. This is a major issue and I have to figure out how to get his fixed. I just deleted out every layout override that I have from the site, turned off any additional plugins in the checkout. There are no javascript errors eithe and I cleared my cache and history and the same problem exists. It has nothing to do with my overrides or any 3rd party plugins. I have added my layouts back in though right now because I have other things to test.


Thanks,

Josh

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
7 years 3 months ago #275068

Hi,

I wanted to look at the problem again but I can't access your checkout:
monosnap.com/file/epE6Tn7UM1A4gSY14oCxVQrA0oC3Xz

To wrap up the situation, the issue is that the controller handling the update of the cart when you delete the last product is supposed to add the trigger cart.empty to the list of triggers that are sent back to the javascript of the browser so that it knows that the cart is empty and that the redirect should happen.
Since that trigger is not sent, it means that the system doesn't see the cart as empty after deleting the last product.

Jerome and I were thinking that it might be linked to the fact that the product is a variant.
Do you have the same problem with products that aren't variants ?
Also, could you try also changing the code:

unset($cart->cart_products[ $p['id'] ]);
to:
{
				unset($cart->cart_products[ $p['id'] ]);
				unset($cart->cart_products[ 'p'.$p['id'] ]);
			}
in the file administrator/components/com_hikashop/classes/cart.php on top of the other patch proposed by Jerome and see if that helps ?

Finally, we're not able to reproduce the issue on our end and no one else reported an issue with the redirect when empty with the new checkout since we've properly handled it months ago. So I would also be inclined in thinking that it comes from either custom code, a custom plugin, or you're using an old build of the 3.1.1 and you don't have all the latest patches.

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 3 months ago #275149

Thank you for the reply Nicolas. I downloaded the newest 3.1.1 package and installed it and I added the code as you suggest and it is still not recognizing that the cart is empty. I still have to manually refresh the cart to get it to return to the correct page. Any other suggestions?

I the mean time I am going to also do a default hikashop install on a site with no modifications and just configure the cart settings the same way as this cart and see if the issue still occurs I will report back to you what I find. If the issue still occurs I will just give you ftp access to the site and a login.


Thanks,

Josh

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
7 years 3 months ago #275193

Hi,

Yes that would greatly help if you could setup a test website so that we can look at the issue more in depth there.
Also, do you have the problem with products that don't have variants ?

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 3 months ago #275206

Hi, I did a base joomla install with base hikashop configuration and as you said it works fine and redirects like it should. I am now going to install a base install of joomla and a base install of hikashop component, but transfer the database from the site where it is not working. I deleted all overrides out of my template entirely and it was still not working previous. That is why I suspect it may be a database issue of some sort. After I test this, if it is not working I am going to give you a test site with ftp and database access.

Thanks,

Josh

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 3 months ago #275235

Nicolas I have tried everything thing I can think of and this problem still exists. I tried un-publishing every plugin, module and extension that I have on the site, I deleted all layout overrides for anything out of my template, then I unpublished every plugin and component not related to hikashop and it still will not refresh. I even unpublished my template and used the default template and this still happens.

However, if I take a fresh install of joomla and transfer the hikashop 3.1.1 database from the site that I am talking about above that does not work and then install a fresh copy of the newest version of 3.1.1 then it the refreshing of the checkout works as it should.

The only thing that is different is on the fresh install we are starting directly from version 3.1.1 and on the existing site this has been upgraded from previous 2.x.x versions and I cannot help but wonder if some files have gotten corrupted some how. That is really the only thing I can think of I sent you the log in credentials for the joomla site and the ftp. I am at a loss I don't know what else to do.

Also, it is not a problem with only variants it is with any product that goes into the cart.

This message contains confidential information

Last edit: 7 years 3 months ago by jschroeder.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
7 years 3 months ago #275298

Hi,

I'm not able to access your link. When I go to the buy now page on your new test website, I get this:
monosnap.com/file/XEMJO21azTAvK5fJeBiLyZ4H4f9whv
So I couldn't look into it.
Could you check on that problem ?
There is no such error or column name in HikaShop so I suppose that it must come from something else.

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 3 months ago #275299

Hi, Nicolas this is not happening for me. I think it might be the firewall blocking you or something. I disabled the firewall. Please let me know if you are still having this issue.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
7 years 3 months ago #275377

Hi,

When I tested this time from home I didn't get the issue.
Maybe there was indeed a problem with the firewall.

However, for some reason, on that test website, I'm not getting the same products as on the other one you had provided before. And the only one I see is "50 Ride-Thru Exterior Wash Tickets". If I try to add it to the cart, it doesn't do anything because of some error s in the customizations which breaks the add to cart button. I had to turn off the debug mode of the configuration to be able to get it to work.

But I was finally able to test and debug. The issue is indeed with customization, but not of the views. It comes from the customization of the translations.
You have set the "CART_EMPTY" message to an empty string. But the new checkout bases itself on the error message being empty or not to know if it needs to redirect.
Had you used instead

&nbsp;
it would still have work with the new system.
That's why we couldn't reproduce and you couldn't either on your tests with a clean HikaShop as you didn't had the overrides on the translations.

So I've changed the line:
if(!empty($checkoutHelper->redirectBeforeDisplay)) {
to:
if(!is_null($checkoutHelper->redirectBeforeDisplay)) {
in the file components/com_hikashop/controllers/checkout.php
That way, it now works even with an empty string for the cart empty message.
We'll add that patch on our end.

Please Log in or Create an account to join the conversation.

  • Posts: 165
  • Thank you received: 3
7 years 3 months ago #275507

Thank you Nicolas! I would have never figured out that was what was causing the issue. Will you let me know when you release the actual patch in the next version?

Thanks,

Josh

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 3 months ago #275508

Hello,

The patch will be integrated into HikaShop 3.2.0 which should be release during this month.
For the moment you can follow the Nicolas' instructions to fix that in your side.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.175 seconds
Powered by Kunena Forum