I'm using PrestaShop 1.7.x and I'd like to find a way to automatically add a product to the cart and redirect to the checkout at the same time.

It works for Woocommerce (e.g. https://example.com/checkout/?add-to-cart=36) but I'd like the same on PrestaShop.

I tried to call a link like this but it does not seem to work: http://localhost/s/en/women/2-9-brown-bear-printed-sweater.html#/1-size-s/cart?action=add-to-cart

1 Answers

Bruno Leveque On

Hi @Ashish Sharawat and Welcome to SO!

This is not the default behavior in PrestaShop 1.7.x, however you can do the following:

  1. Create a new Front Controller with a autoAddToCart() method inside
  2. In this method, call $this->context->cart->updateQty($quantity, $id_product, $id_product_attribute) and then Tools::redirect('index.php?controller=order&step=2');
  3. Place the link to your new controller inside your .tpl files on product links. The link should look like this https://<shop_domain>/en/module/mymodule/autoaddtocart?quantity=1&id_product=1&id_product_attribute=1

Alternately, if you use PrestaShop 1.6.x, you can turn on an option to automatically redirect a customer to the checkout after adding a product to the cart:

  1. Configure your Cart block module from the Admin panel and turn off the Ajax option
  2. Edit your Product Preferences and enable the redirection to the checkout after a product has been added to the cart
  3. Edit your Order preferences and turn on the One page checkout
  4. You can now use the regular links to add a product to the cart, buyers will be automatically redirected to checkout

I hope this helps!