Magento - Add a product with custom options to the cart through URL Querystring
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.
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:
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....
Hey, that's pretty awesome. Would you know if you can reuse option sets for a whole category of simple products?
John, I'm not sure…...
John, I'm not sure…
I just tried this to add...
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...
code is eliminated from last post ..
i am posting it again
Sumit, Are you missing the...
Sumit, Are you missing the Brackets? Give me a URL that I can look at.
Thanks - any idea how to do...
Thanks - any idea how to do this with configurable products? I've tried by adding the configurable option IDs but no dice
Molecule, Sorry, I do not....
Molecule, Sorry, I do not. But will look into it. You can try asking Branko Ajzele - http://activecodeline.com/
Thanks! Exactly what I was...
Thanks! Exactly what I was looking for.
MXWest,...
MXWest,
Thank you for that...
Thank you for that share!
@molecule , YES its absolutely possible, Here's an example:
http://www.website.com/checkout/cart/add?product=[productID]&qty=1&options[98]=text&super_attribute[102]=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!
Hi Brian As of Magento 1.4...
Hi Brian
As of Magento 1.4 you need to format the querystring in this way:
checkout/cart/add?product=7&super_attribute[528]=8&super_attribute[527]=5&qty=1
It is the square brackets that are the issue.
Thanks for the tip.
Thanks a lot Brian, that...
Thanks a lot Brian, that works great. Now to try and get it ajaxed up!
This is very handy. Do you...
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...
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...
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_customizatio...
I actually just want to set...
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....
Thanks. It worked for me.
Post new comment