Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Connect custom “add to cart” button to magento cart
 
hasan89
Jr. Member
 
Total Posts:  7
Joined:  2012-12-06
 

hello guys!!
suppose i have non magento based website from where i want sell product .i click the product a get its detail page.i want to add there “ ADD TO CART” button and when i click that button i want it to route me to magento cart just like i have clik magento add to cart butoon.is this possible in any way??
thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
davidmanne
Jr. Member
 
Avatar
Total Posts:  5
Joined:  2012-02-03
Frankfurt am Main, Germany
 

Hi,

You should be able to add a product to the cart by a url. Something like http://magentostoreurl.com/index.php/checkout/cart/add/product/{product_id}/qty/{product_quantity} should work. If the product has options then it gets a bit more complex but the example should work for simple products.

Hope this helps

 
Magento Community Magento Community
Magento Community
Magento Community
 
hasan89
Jr. Member
 
Total Posts:  7
Joined:  2012-12-06
 

thanks David for the reply.
i did this
<button onclick=”location.href =’{{config path=”localhost:8080/magento/index.php”}}/checkout/cart/add?product=1&qty;=1′”>Buy It Now</button>
the button is there but its not working on the click.

 
Magento Community Magento Community
Magento Community
Magento Community
 
davidmanne
Jr. Member
 
Avatar
Total Posts:  5
Joined:  2012-02-03
Frankfurt am Main, Germany
 

Try using the following code:

<button onclick=”location.href =’{{config path=”localhost:8080/magento/index.php”}}/checkout/cart/add/product_id/1/qty/1′”>Buy It Now</button>

The previous url you posted may only work with older versions of Magento.

Let me know if this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
hasan89
Jr. Member
 
Total Posts:  7
Joined:  2012-12-06
 

David..i have tried this earlier but it too didn’t work.
let me tell you complete scenerio.i am having a html file where i have list of all the products with their price and other data.and these all products are being fetched from magento database but the html is non magento and it is not in magento folder.
what i want is when i click the product from the list and it goes to product detail page where there is a add to cart button which should take me directly to the magento cart with product added in it..
Hope you get it.
THANKS

 
Magento Community Magento Community
Magento Community
Magento Community
 
gskacha
Jr. Member
 
Total Posts:  21
Joined:  2011-01-06
 

Hi
Here is button code
<button onclick="location.href =’http://MAGENTO_HOST_URL/checkout/cart/add?product=PRODUCT_ID&qty;=1’">Buy It Now</button>
you need to hard code magento host url and pass product id in button url.

 
Magento Community Magento Community
Magento Community
Magento Community
 
gskacha
Jr. Member
 
Total Posts:  21
Joined:  2011-01-06
 

Hi
Here is button code
<button onclick="location.href =’http://MAGENTO_HOST_URL/checkout/cart/add?product=PRODUCT_ID&qty;=1’">Buy It Now</button>
you need to hard code magento host url and pass product id in button url.

 
Magento Community Magento Community
Magento Community
Magento Community
 
davidmanne
Jr. Member
 
Avatar
Total Posts:  5
Joined:  2012-02-03
Frankfurt am Main, Germany
 

Ah ok,

If the html is not inside the Magento structure then you will need to hard code the url or you could read it from the magento db core_config_data table since you are already reading the products from the database. If you use /checkout/cart/add?product=PRODUCT_ID&qty;=1 or /checkout/cart/add/product_id/123456/qty/1 only matters on what version of Magento you have.

 
Magento Community Magento Community
Magento Community
Magento Community
 
expertsindia
Jr. Member
 
Total Posts:  7
Joined:  2012-09-27
 

I am also getting this type of condition. So please help me out and provide necessary solution…

 
Magento Community Magento Community
Magento Community
Magento Community
 
hasan89
Jr. Member
 
Total Posts:  7
Joined:  2012-12-06
 

Hey David your post was very helpful
one more thing i want to ask is there a way that when i click that button it do its job i.e it add product to the cart but remain on the same page,only give a alert kind of thing that the product is added to the cart. I came to know that there is the option of setting cart button behaviour we can do from magento admin panel but i what about for custom button??
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
davidmanne
Jr. Member
 
Avatar
Total Posts:  5
Joined:  2012-02-03
Frankfurt am Main, Germany
 

Glad I could help you out,

As far as staying on the same page with a custom button. I would suggest creating a some JavaScript that will call the url via Ajax, check for success/failure and then display the message on you page. I have not done this with Magento myself but it should not be too difficult.

 
Magento Community Magento Community
Magento Community
Magento Community
 
hasan89
Jr. Member
 
Total Posts:  7
Joined:  2012-12-06
 

i would b thankful if u could help me with code plz. b/c i am new to javascripting.
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

you don’t have to do it with javascript, it can be a form or a link, as long as you know the params you need to send to magento cart controller

 
Magento Community Magento Community
Magento Community
Magento Community
 
hasan89
Jr. Member
 
Total Posts:  7
Joined:  2012-12-06
 

Dear RYAN i didn’t get your point.Please make it clear for me
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
hasan89
Jr. Member
 
Total Posts:  7
Joined:  2012-12-06
 

David i am waiting for your reply.Its about my project PLZ.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top