Magento – Set Configurable Attributes and Custom Options via URL

configurable-productcustom-optionsurl

I have a Magento shop with some configurable products. Those products have 3 configurable attributes from an attribute set and 1 custom option that is set on the configurable product itself (so not from the attribute set).

What I want to do is set the attributes and custom options via an url. So when we send that url to a customer via mail, and he clicks on it, it is already configured (but he can still change it via the dropdowns if he wants).

I know you can do this by adding values to the url. For example:

http://www.shop.com/cat/product.html#132=4&140=16&139=15&3=21

But this only works for the 3 configurable product attributes, NOT for the custom option. Is this something that can be done (but am I using the wrong syntax), or is this something that needs modification of the code?

Thanks!

Best Answer

There is not a way to select a custom option based off a URL parameter. The custom options are not rendered the same as configurable attributes.

This is the code that defaults the attribute values

var separatorIndex = window.location.href.indexOf('#');
    if (separatorIndex != -1) {
        var paramsStr = window.location.href.substr(separatorIndex+1);
        var urlValues = paramsStr.toQueryParams();
        if (!this.values) {
            this.values = {};
        }
        for (var i in urlValues) {
            this.values[i] = urlValues[i];
        }
    }

    this.configureForValues();

You could write something custom to do exactly what you are looking for using jQuery.param().

http://api.jquery.com/jquery.param/

Related Topic