Add to cart without Ajax and redirect user to checkout

  • Posts: 48
  • Thank you received: 4
  • Hikashop Business
2 years 1 month ago #345792

-- HikaShop version -- : 4.6.2
-- Joomla version -- : 3.10.11
-- PHP version -- : 7.4
-- Browser(s) name and version -- : Any
-- Error-message(debug-mod must be tuned on) -- : None

Hi

Is it possible to add a product into cart without using Ajax and redirect the user to checkout rigth after?

Thanks.

Last edit: 2 years 1 month ago by pat01.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
2 years 1 month ago #345797

Hi,

Yes. In fact, if you block the javascript on the page and click on the add to cart button, it will do exactly that as a fallback to the AJAX add to cart.
Note thought that even with the AJAX add to cart, you can redirect to the checkout with the settings of the HikaShop cart notification plugin in the Joomla plugins manager.

When you edit a product in the backend, you can see the button "add to cart HTML button". If you click on it, it will open a popup where you can get the HTML for an add to cart button without javascript which works like you want. You can copy that HTML anywhere on your website or even on another website and it will work.

The following user(s) said Thank You: pat01

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

  • Posts: 48
  • Thank you received: 4
  • Hikashop Business
2 years 1 month ago #345817

nicolas wrote: When you edit a product in the backend, you can see the button "add to cart HTML button". If you click on it, it will open a popup where you can get the HTML for an add to cart button without javascript which works like you want. You can copy that HTML anywhere on your website or even on another website and it will work.


Hi and thanks for this.
This would mean to add such button manually to each product. There are many products... I'm looking for a solution that works globally.

Any idea?

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
2 years 1 month ago #345819

Hi,

You could easily turn off the AJAX add to cart with a small view override.
Edit the file product / quantity.php via the menu Display>Views and change the line:

$attributes = ' class="' . $css_button . ' ' . $css_button_cart. '" onclick="if(window.hikashop.addToCart) { return window.hikashop.addToCart(this); }" data-addToCart="'.$this->row->product_id.'" data-addTo-div="hikashop_product_form" data-addTo-class="add_in_progress"';
to:
$attributes = ' class="' . $css_button . ' ' . $css_button_cart. '" data-addToCart="'.$this->row->product_id.'" data-addTo-div="hikashop_product_form" data-addTo-class="add_in_progress"';
By removing the onclick attribute, the add to cart button will work in fallback mode, as if the javascript had been turned off.
Note that this is for the product details page. If you also have add to cart buttons on listings, you want to do the same modification in the product / add_to_cart_ajax.php view file.

The following user(s) said Thank You: pat01

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

  • Posts: 48
  • Thank you received: 4
  • Hikashop Business
2 years 1 month ago #345822

Hi

This is exactly what I was looking for. It works perfectly.

Thanks a lot.

Last edit: 2 years 1 month ago by pat01.

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

  • Posts: 17
  • Thank you received: 3
  • Hikaserial Subscription Hikashop Business
1 year 2 months ago #354896

Hi,

I have exactly the same need. I did the override but it seems to come from "layouts / button.php" (display view on front end)
Can't find where to stop ajax....
we are using hika business 4.7.5 with J3.10.12 on PHP 8.0.27

does it change recently ?

Thanks

Grégoire

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
1 year 2 months ago #354898

Hi,

No, it's still the same.
Note that this change in product / quantity is only on the product details page.
For the products listings, you want to also do the change in product / add_to_cart_ajax so that add to cart buttons on listings also have the modification.
Note that you might need to clear your website cache if you're using caching, in order to see the change.
If that doesn't help, please provide the URL of a page with the situation so that we can look at what is going on there.

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

  • Posts: 17
  • Thank you received: 3
  • Hikaserial Subscription Hikashop Business
1 year 2 months ago #354908

Modif : Actually I forgot that I have a custom plugin doing some custom redirect "onBeforeCartSave". It is probably not compatible with this version.
I need to go further

Don't consider below

Several years I practice Hika. Sure it should be "obvious" but can't find it...

The site is a dev one to check our ability to bring our prod site from J3/PHP 7.3/ Hika 4.2.2 to a pre-J4 version (php8 uptodate)
So the dev is an upgraded clone of our prod site (which may have "bring" some custom hack/override I may have forgotten).
Here is the page display product :

This message contains confidential information


Our purpose is to send the customer to the checkout directly as soon as he clicks on "add to cart".
Most of our products need to be logged in for that.
It works well "out of the box" when you are connected (if I disable the cart notification plugin)
But if the user is not connected (guest), instead of redirecting to the login page is throws a "cart_id was not returned in addToCart AJAX call" message in the browser console.

Last edit: 1 year 2 months ago by gvitry.
The following user(s) said Thank You: nicolas

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

Time to create page: 0.084 seconds
Powered by Kunena Forum