Magento is truly a powerful and flexible platform! I enjoy working with it more and more every day. I recently came across the need to add a product to the cart VIA the Querystring/URL. Guess what? Magento can do it and I’ll show you how!
Simple products are the easiest to add because there are fewer options that need to be passed. The basic structure is as follows.
1 |
http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty] |
Where [id] is the Magento ID of the product and [qty] is the Quantity you wish to add.
To add a simple product with custom options simply add options[id]=[value] to the end. The basic structure is:
1 |
http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]&options[id]=[value] |
You can get the options id and value by viewing the source of the simple product page and it’s dropdowns.
Hey, that’s pretty awesome. Would you know if you can reuse option sets for a whole category of simple products?
I just tried this to add products with custom options through url in cart, but it didnt worked 🙁 .
Could you please give me a working url or example url.
This is the code of my custom options on product details page.
Height
Width
Thanks in advance !!
code is eliminated from last post ..
i am posting it again
Thanks – any idea how to do this with configurable products? I’ve tried by adding the configurable option IDs but no dice 🙂
Thanks! Exactly what I was looking for.
Thank you for that share!
@molecule , YES its absolutely possible, Here’s an example:
http://www.website.com/checkout/cart/add?product=%5BproductID%5D&qty=1&options%5B98%5D=text&super_attribute%5B102%5D=157
to break this down:
Product ID: Your configurable product ID, found in managing products through the backend
options[98]: The “98” is an option I added for the user to write something in a text area, you can find this number by inspecting the element on the product view page through firefox’s firebug tool. Look at the element and look for it’s name, for this text area it was “options[98]”
super_attribute[102]: same as above, although this is the associated product, not an option, the “157” is the defined selection in the dropdown, also found using firebug.
Thats it!
This is very handy. Do you know if it’s possible to remove an item from the cart via querystring as well?
Is there a way to add products via query string using the SKU without modifying any code? I have tried various methods with no luck.
I am working on a Magento theme using this method to add things to a cart as well. I just figured I would add this URL to further help people that found this useful blog post, thanks!
http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/adding_a_product_to_the_cart_via_querystring
I actually just want to set the option via url and display that product with all the options set… is that possible?
Thanks. It worked for me.
Hello ,
The above code does not works for price.
I added a product with price 0
and custom options with price 100, but it is passing only the product price not the option price
Help me with this please.
Thanks
Hi,
I’m doing a project in magento. I want that users can add to cart configurable products directly from category page. They no need to go to product view page. When i disable product view page and addtocart on category page, i get an error message “options required”. How can i make this? Please help me.