There are loads of articles and posts about doing this in previous versions using several different URL strings, all of which none work in Magento 1.8

Has anyone actually figured out a way to do it yet?

For example, this is listed on the Magento Wiki and was added in 2010: http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/adding_a_product_to_the_cart_via_querystring


However when clicked, this link just refreshes the cart.

Just incase anyone wants to see how I'm trying to code it:

<button type="button" title="Add Loan Phone" class="button" onclick="setLocation('URL HERE')"><span class="green">Add a Loan Phone (+£10)</span></button>

1 Answer 1


You can use the checkout's cart helper for that

echo (string)Mage::helper('checkout/cart')->getAddUrl($_product);

Make sure $_product is an instance of the class Mage_Catalog_Model_Product

So putting it all together as requested

<?php $_product = Mage::getModel('catalog/product')->load([product id]);?>

<button type="button" title="Add Loan Phone" class="button" onclick="setLocation('<?php echo (string)Mage::helper('checkout/cart')->getAddUrl($_product);?>')"><span class="green">Add a Loan Phone (+£10)</span></button>
  • Where can I enter what product ID i want to add? Oct 17, 2013 at 11:21
  • Also, when I add your line in the URL HERE part, it just breaks and doesn't show anything below that line. I then removed the setLocation bit, and pasted it with opening and closing PHP tags in the onclick value.. and it still does the same thing. How am I supposed to place that text? Oct 17, 2013 at 11:24
  • Can you use the line i pasted in m question, and put your code where it should be please? Many thanks :) Oct 17, 2013 at 11:25
  • Updated the answer with the full code as requested! Oct 17, 2013 at 11:32
  • Can you define a quantity using this method? Jan 21, 2014 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.