Add to cart link. Ajax or Stay same page POSSIBLE?

  • Posts: 50
  • Thank you received: 4
13 years 9 months ago #8572

Hi.

In item (product) card there is a button Add to cart HTML link
After clicking on this link (in content) is redirected to checkout.

1. Is it possible to add product from content with ajax ?
2. Do not redirect to checkout, Stay at same page (content) and display a popup notice ? (HikaShop->System->Configuration->Checkout->After a product is added to the cart: any setting does not affect)

Thanks.

Last edit: 13 years 9 months ago by korkunov.

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 9 months ago #8583

The add to cart HTML link is just a simple link which add a product and redirect to the cart.
Making it ajax is possible if you know javascript...Instead of having your link directly as an href attribute of a link, you could add some JS in your article to trigger that URL. The popup notice could be possible as well but it's also difficult.

In that case, the easiest would be to create a category for your product and add that category to your product. Then, create a new module in the menu Display->Content modules and set the parent category as that category and set it to display the add to cart button and us the layout "title". You can also add some CSS to remove the name and the price if you don't want it. Then, you can insert your module in your article using the loadposition plugin of joomla.

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

  • Posts: 2
  • Thank you received: 0
13 years 8 months ago #11983

This is something I would be very interested to know as well.

How can you make the "add to cart html link" simply add the product to the cart without redirecting? I would like to be able to add multiple items before checkout.

AJAX would be great if we could get an example.

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 8 months ago #11987

If you want to make it AJAX, first, you need to include the mootools.js library of joomla in your template:
forum.joomla.org/viewtopic.php?p=1533434

Then, you need to have your links like this:

<a href="ADD_TO_CART_LINK" onclick="try{ new Ajax('ADD_TO_CART_LINK',  { method: 'get' }).request(); }catch(err){ new Request({url:'ADD_TO_CART_LINK', method: 'get'}).send(); } return false;">Add to cart</a>

You need to replace ADD_TO_CART_LINK with your link.

Last edit: 13 years 8 months ago by nicolas.

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

  • Posts: 2
  • Thank you received: 0
13 years 8 months ago #12017

Is the Add to Cart HTML link stored in the db anywhere?

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 8 months ago #12022

No, it's generated based on the product id.

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

  • Posts: 26
  • Thank you received: 1
13 years 7 months ago #12950

I would like the same function.
Selling a lot of cheap items and if is add one item to a cart i have to browse all the way back to the product category.

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12960

You can already have add to cart buttons on the listing of products. You just need to turn on the corresponding option in the modules/menus hikashop options.

What this thread is about is the add to cart link when you want to use joomla articles as product pages and that you need to add your add to cart link manually in the HTML of the article.

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

  • Posts: 217
  • Thank you received: 1
13 years 1 month ago #27569

So that ajax works but now I would like it to refresh the checkout. Any thoughts how to do that?

Also with the cart itself you can edit the quantity - how can that be done with ajax?

Last edit: 13 years 1 month ago by Mat.

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27582

You can refresh the quantity by calling the URL like that:
www.demo.hikashop.com/index.php?option=c...kout=1&product_id=ZZ
where YY is the new quantity of the product in the cart and ZZ is the id of the product.
You can also use it to remove the product with a quantity of 0.

Refresh the checkout ? You can just do a window.location = 'URL_OF_THE_CHECKOUT'; in javascript.

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

  • Posts: 217
  • Thank you received: 1
13 years 1 month ago #27636

nicolas wrote:

You can refresh the quantity by calling the URL like that:
www.demo.hikashop.com/index.php?option=c...kout=1&product_id=ZZ
where YY is the new quantity of the product in the cart and ZZ is the id of the product.
You can also use it to remove the product with a quantity of 0.

Refresh the checkout ? You can just do a window.location = 'URL_OF_THE_CHECKOUT'; in javascript.


My checkout is a module. Will that work?
I want to press the add to cart button like above and get the shopping cart to update via ajax as well. Is there a way?

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27649

The checkout cannot be a module. It's always displayed on the main area of your website.
You must be talking about refreshing the cart module right ?
Then you should use the functions of the file administrator/components/com_hikashop/helpers/cart.php which already do that for normal add to cart buttons of HikaShop.

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

  • Posts: 217
  • Thank you received: 1
13 years 1 month ago #27746

nicolas wrote:

The checkout cannot be a module. It's always displayed on the main area of your website.
You must be talking about refreshing the cart module right ?
Then you should use the functions of the file administrator/components/com_hikashop/helpers/cart.php which already do that for normal add to cart buttons of HikaShop.


Yes I mean the cart. Thanks for your help so far.

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

  • Posts: 10
  • Thank you received: 1
12 years 1 month ago #72148

Is this topic active and different under Joomla 2.5? None of the suggestions above work for me.

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
12 years 1 month ago #72421

You don't need to change anything anymore to have add to cart buttons in joomla content stay on the same page.
There are two plugins called "HikaShop Product TAG insertion" and "HikaShop Product TAG translation" which have to be published for that.
Once done, you can use the "product" button below the HTML editor to add the add to cart buttons in your articles and they will use the behavior that you select in the "when a product is added to the cart" option of the Checkout tab of the configuration.

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

  • Posts: 10
  • Thank you received: 0
11 years 2 months ago #124050

Sorry to Necro an old thread... But I was wondering if there has been an update on this?

I can use the Ajax link provided, but I am wondering if there is an amendment to that A HREF to allow us to specify a quantity?

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

  • Posts: 13201
  • Thank you received: 2322
11 years 2 months ago #124087

Hi,

In the link you have the quantity parameter "&quantity=1" you just have to replace 1 by the desired quantity.

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

  • Posts: 10
  • Thank you received: 0
11 years 2 months ago #124103

Ahh in the Product page 'Link to HTML', there... Jeeze... So blind sometimes :(

Thanks Xavier

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

  • Posts: 120
  • Thank you received: 2
8 years 9 months ago #228189

Hi
Thank you dear nicolas
It's work very well.

<a href="ADD_TO_CART_LINK" onclick="try{ new Ajax('ADD_TO_CART_LINK',  { method: 'get' }).request(); }catch(err){ new Request({url:'ADD_TO_CART_LINK', method: 'get'}).send(); } return false;">Add to cart</a>
Now if want remove a product from cart how can use ajax?

Last edit: 8 years 9 months ago by kaya.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 9 months ago #228218

Hi,

With that kind of code ; you cannot.
But it will be possible in HikaShop 3.

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.134 seconds
Powered by Kunena Forum