Search This Blog

Jul 19, 2012

Magento: Adding Add to Cart Button in CMS Page

Another good strategy to market your product in different way is through CMS pages. You can also set that cms page as a landing page for your email campaign marketing. Going to my point, it is really easy to add functionality on your cms pages by using magento cms variables like base unsecure url, base secure url , general contact name, etc.
But how about adding add to cart button in your cms page? That's simple! All you need to know is the id of your product and this snippet below.

<button onclick="location.href ='{{config path="web/unsecure/base_url"}}/checkout/cart/add?product=1&qty=1'">Add To Cart</button>

Just change the value of the query string "product" to the id of your product. You can see the product id by going to Catalog-> Manage products. Ids’ are number before the product name in the list.

That's it. Save your page and refresh your cache and try to click the "Add To Cart" button to test it.

6 comments:

Anonymous said...

what if specific product attributes are wanted?

J. Alexander Curtis said...

I am wondering the same thing. Is there a way to make a parent product with the option to select a child, or something to that effect? I tried this and it worked, only if I use one of the children products as the product id. It works if I use a parent, but it then takes me to the product page to select attributes which defeats the purpose of adding the button. My old landing pages took me to the product page and I was trying to cut out a step by adding to cart directly from the landing pages.

Sebastian said...

for configurable products an example is http://www.your_domain.com/checkout/cart/add?product=68&qty=1&super_attribute[528]=55&super_attribute[525]=56

brgds!

Sebastian said...

for configurable product with attributes the url must be in the following way http://www.your_domain.com/checkout/cart/add?product=68&qty=1&super_attribute[528]=55&super_attribute[525]=56

Peter Baio said...

I've followed these steps and when I click Add to Cart it takes me to a blank cart. Nothing was added.

Peter Baio said...

I did what was said and I still get nothing in my checkout part.