Pierre SKLI Posted March 3, 2011 Share Posted March 3, 2011 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 More sharing options...
bliscar Posted September 2, 2011 Share Posted September 2, 2011 Hi I would like to implement the same thing ("add to cart" button in CMS page). Did you succeed in finding a good solution ? Thank you in advance. Link to comment Share on other sites More sharing options...
bellini13 Posted September 4, 2011 Share Posted September 4, 2011 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 More sharing options...
vervemedia Posted November 23, 2011 Share Posted November 23, 2011 (edited) 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 November 23, 2011 by vervemedia (see edit history) Link to comment Share on other sites More sharing options...
featurex Posted December 19, 2011 Share Posted December 19, 2011 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 More sharing options...
BWT Posted May 18, 2012 Share Posted May 18, 2012 (edited) 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 May 18, 2012 by tjg (see edit history) Link to comment Share on other sites More sharing options...
PF22 Posted February 26, 2013 Share Posted February 26, 2013 Hi there. I would like to add a "add to cart button" on a CMS page. Is anyone found an easy way? Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now