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.

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:

You can get the options id and value by viewing the source of the simple product page and it’s dropdowns.

21 thoughts on “Magento – Add a product with custom options to the cart through URL Querystring”

  1. 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 !!

  2. Thanks – any idea how to do this with configurable products? I’ve tried by adding the configurable option IDs but no dice πŸ™‚

  3. 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!

  4. 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

  5. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *