add to cart link - return url

  • Posts: 40
  • Thank you received: 1
  • Hikashop Business
8 years 6 months ago #238952

-- HikaShop version -- : HikaShop Business: 2.6.2
-- Joomla version -- : 3.5.1
-- PHP version -- : 5.3

Hello!

I'm tring to configure custom add to cart html link to make component return me to original page.

First, I make a hidden input with the value containing current url:

<?php
$thisUrl = urlencode(base64_encode("http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']));
?>
<input type = "hidden" id="urlbase64" value="<?php echo $thisUrl; ?>">
I checked, url is correct before encoding.

Then I generate my quantity input and adding link:
<input type="number" min="1" max="100" value="1" class="quantityinput" id="q6724" />
<a class="add2cart" id="6724" href="#"><img src="/images/icons/cart_put.png" align="absmiddle" /></a>
In this example <a>'s id is a hikashop product id.

Finally, I process the link:
$(".add2cart").click
	(
	function(e)
		{	
		e.preventDefault();
		var id = $(this).attr('id');
		var quantity = $("#q" + id).val();
		var returnURL = $("#urlbase64").val();
								
		document.location.href = "index.php?option=com_hikashop&ctrl=product&task=updatecart&quantity="+quantity+"&product_id="+id+"return_url="+returnURL;				
		}			
	);

As a result, my good is added to cart, the quantity is right, but I dont return to original page. Instead I go to checkout.
What am I doing wrong?..

Thank you!

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
8 years 6 months ago #239009

Hi,

You're missing a & before

return_url="+returnURL
in your code

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

  • Posts: 40
  • Thank you received: 1
  • Hikashop Business
8 years 6 months ago #239055

Oh my, I'm a fool. Thank you a lot. It's working perfect.

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

  • Posts: 40
  • Thank you received: 1
  • Hikashop Business
8 years 6 months ago #239056

Nikolas,

It is working, but I noticed that if I have, for example, five products in cart (I mean, one name, and quantity = 5), and after that add one more using this method, then I have only one product in cart instead of six.

Is there a quick sollution to fix it, or should I manually analize the cart contents and add up corresponding quantities?..

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
8 years 6 months ago #239064

Hi,

You just want to add the parameter &add=1 to the add to cart URL. Otherwise, the system will assign that you are updating the quantity in the cart instead of adding to it.

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

Time to create page: 0.065 seconds
Powered by Kunena Forum