Jump to content

"Add to card" button in a CMS page?


Recommended Posts

Hi there,
I'm having a bit of trouble with a CMS page I'm creating. It's a price-table, and in the footer of this table each "product" column has a "Add to card" button.

And this button give me some hard times: I need a generated TOKEN in the URL to add the product in the user's cart, so a link to cart.php?qty=1&id_product=14 is obviously not working... But because I'm working in a CMS page, and not in a dynamic .php or .tpl file, I can get the variable to write my token in the URL of the button!

So if someone has an idea for this, it might help me a lot!

Thanks for reading me!

Pierre

Link to comment
Share on other sites

  • 5 months later...

Hi there,

I'm having a bit of trouble with a CMS page I'm creating. It's a price-table, and in the footer of this table each "product" column has a "Add to card" button.

And this button give me some hard times: I need a generated TOKEN in the URL to add the product in the user's cart, so a link to cart.php?qty=1&id_product=14 is obviously not working... But because I'm working in a CMS page, and not in a dynamic .php or .tpl file, I can get the variable to write my token in the URL of the button!

So if someone has an idea for this, it might help me a lot!

Thanks for reading me!

Pierre

 

not sure it is possible to use the add to cart directly, the token is generated based on a customer cookie. you might try creating a custom php file that would redirect to the appropriate php class.

for instance, create an add.php file and link to that in your cms pages. pass in the product id and qty etc...

so add.php?qty=1&id_product=14

 

then in the add.php, you would include the necessary prestashop files like

require(dirname(__FILE__).'/config/config.inc.php');

 

and then generate the token using

$token=Tools::getToken(false)

 

then redirect to

cart.php?qty=1&id_product=14&token=$token

Link to comment
Share on other sites

  • 2 months later...

 

not sure it is possible to use the add to cart directly, the token is generated based on a customer cookie. you might try creating a custom php file that would redirect to the appropriate php class.

for instance, create an add.php file and link to that in your cms pages. pass in the product id and qty etc...

so add.php?qty=1&id_product=14

 

then in the add.php, you would include the necessary prestashop files like

require(dirname(__FILE__).'/config/config.inc.php');

 

and then generate the token using

$token=Tools::getToken(false)

 

then redirect to

cart.php?qty=1&id_product=14&token=$token

 

 

I tried the above code. But it gives me an error "Invalid token".

 

Can you guide me, if i'm wrong...

 

I was searching on this for 2 hours and found a way... (alternate method)

This will add your products in the cart using the link in CMS page where you can checkout later.

 

ajaxCart.add(product_id,attribute_id, true, null,quantity, null);

 

Go to CMS edit page, Type "Add to Basket" and add hyperlink using the button on the tool box. In the events tab, paste the above function in ON CLICK text field.

 

Thats it. Save and view. The product will be added to the cart when the Add to Basket is clicked.

Edited by vervemedia (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

 

ajaxCart.add(product_id,attribute_id, true, null,quantity, null);

 

 

Tried adding this to add this in the events section of adding link. But after saving and viewing the page nothing happens after clicking. It just gets displayed as plain text. Is there anything special I have to do? Add the product ID where it says "product_id" and ad quantity where it say "quantity" in the code?

Link to comment
Share on other sites

  • 4 months later...

Could try this you'll have to edit it a bit but it shows in the CMS page, I am just not sure about adding the token, something like...

 

 

<p><a id="ajaxButton_0" class="exclusive ajax_add_to_cart_button" title="Add to cart" href="/cart.php?qty=1&id_product=0&token=$token=Tools::getToken(true)&add" rel="ajax_id_product_0">Add to cart</a></p>

Edited by tjg (see edit history)
Link to comment
Share on other sites

  • 9 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...