Hi - I am new to Magento, so please bear with me!
I am trying to put an "Add To Cart" button on a CMS page...any ideas on how I can do this?
I have found a few sites that claim to have the solution, but no luck...
Thanks in advance to anyone who can help!
You can easily build up the Add to Cart URL but the tricky part would be FormKey. But you can make use of Javascript to read the value onLoad and inject it to the addToCart Form.
Hope this gives you some hint.
Hi @nvae88,
Follow below steps to add product from cms page.
1.Well start off with making a new CMS page.
2.Then make a new .phtml file in your template directory example: demo.com/app/design/frontend/mytheme/default/template/catalog/product/newfile.phtml"
3.Point your CMS page in the magento backend to this new file with the following line:
{{block type="core/template" name="newfilename" template="catalog/product/newfile.phtml"}}
Make sure you are in "the hide editor mode" of the CMS page
4. Everything you show on the phtml file should now be visable in on the frontend.
Now to add the product and add to cart function to the .phtml file
5. Add this code
// 17 is the product ID
$params_arr = array('product'=>17,'qty'=>1); $url = 'checkout/cart/add?'; foreach($params_arr as $paramKey => $paramVal) $url_arr[] = $paramKey.'='.$paramVal; $url .= implode('&',$url_arr); ?> <form action="<?php echo Mage::getUrl($url) ?>" method="post"> <input type="hidden" name="product" value="1" /> <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /> //getting unique form key <fieldset class="add-to-cart-box"> <input type="submit" title="<?php echo $this->__('Add to Cart') ?>" class="addtocart" /> </fieldset> </form>
Above code will display a Add to cart button on cms page with unique form_key.
This my simple cms page, add to cart not working could you pls help me solve this issue -> code https://justpaste.it/40ryd
Did you get solution?