3

Note: This is a X-Post from StackOverflow, I put it there before remembering this subexchange existed so apologies for the double-up.

My issue is surrounding the Add To Card method for configurable products and whether a configurable product via URL / querystring is possible.

The Magento Wiki has a resource for adding a product to cart via Query String for Magento < 1.3 HERE

This quotes a method using this example:

http://www.your_domain.com/checkout/cart/add?product=68&qty=1&super_attribute[528]=55&super_attribute[525]=56

It also mentions that this was valid up to version 1.3.

I have been playing around with this in 1.7 and have noticed a Major difference in 1.7 is the encrypted key in the ->getAddUrl() method for the Form Action Attribtue so now the URLs look more like

http://www.your_domain.com.au/checkout/cart/add/uenc/aHR0cDovL3d3dy5jdWx0dXJla2luZ3MuY29tLmF1L2FjY2Vzc29yaWVzL3NvbC1yZXB1YmxpYy90cmFja3Mtb24tZWFyLWJsYWNrLTM1OTg5Lmh0bWw_X19fU0lEPVU,/product/35900/

With the product ID being the 35900.

If I use this URL in the browser it will direct me to the product page with a message saying Please specify the product's option(s).

I have been trying to pass the desired attribute options value in the URL to add the product to the cart with no success. (For the sake of saving space I'm omitting the URL up to and including the encrypted key) I've tried methods these to no avail:

/product/35900/super_attribute/49265/4834
/product/35900/super_attribute/49265=4834
/product/35900/49265=4834
/product/35900/49265/4834

My question is: Is it possible to add a configurable product via URL to the cart in Magento and if so, what is the format for passing the super_attribute id and Attribute Option Value?

2
  • can you please tell me what is [272] and 22... and how to get this
    – user2684
    Commented Jul 16, 2013 at 17:09
  • 272 is the 'Super Attribute' which is found in the catalog_product_super_attribute tables. This is the ID for the attribute you're using. Example if you are a clothing store and EVERY item has a size attribute and that id is 272. Then every configurable item would need Super Attribute 272 assigned. The 22 is the ID of value of that super attribute. So if in your clothing store the size 'Medium' had an ID of 22 the query string would be super_attribute[272]=22 which really means super_attribute[size]=medium. Does this help?
    – James
    Commented Jul 16, 2013 at 22:36

2 Answers 2

8

This has worked for me on CE 1.7.0.2 (with sample data):

/checkout/cart/add/product/126?super_attribute[525]=100&super_attribute[272]=22

NOTE (this puzzles me a bit):
There is a difference between calling:

/checkout/cart/add/product/126?super_attribute[525]=100&super_attribute[272]=22

and

/checkout/cart/add/product/126?super_attribute[272]=22&super_attribute[525]=100

I mean the order of the super_attribute parameters is important. After calling the 2 URLs above I ended up with 2 cart lines of the same product with the same options. one looked like this:

Size Small Color Green

and the other was

Color Green Size Small

I guess if you add the products to cart via URL you should keep the order of the attributes as shown in the product view page for consistency.

2
  • Is there any option to avoid form key while calling this URL? Commented Oct 31, 2017 at 7:30
  • @VIPINAROY I don't know.
    – Marius
    Commented Oct 31, 2017 at 7:47
0

In latest magento versions we need to add form key also.

https://{site-name}/checkout/cart/add/product/{product_id}/form_key/{form_key}?super_attribute[{attribute_id}]={attribute_value}&super_attribute[{attribute_id}]={attribute_value}

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.