2

From a controller I redirect to a configurable product's page by

$productUrl = $this->_customSearch();
$url = Mage::getBaseUrl().$productUrl.'.html';
header('Location: '.$url);
die();

The children products can be searched by specific attribute (corresponding to their color group) and I want when the user is redirected to the product page - the attribute "Color" (a drop-down menu) to already have the certain color selected, depending on the searched value.

Now, what I cannot wrap my mind around is how to make the attribute auto-selected when the page loads. In the controller I can get the color of the product from the product object, but what next? I guess I have to deal with Ajax here, but the URL of the product's page has nothing that can give me a hint.

Any ideas?

2 Answers 2

3

Magento supports for the configurable product page, the selected options in the url. See this example on demo: http://demo.magentocommerce.com/men/shirts/french-cuff-cotton-twill-oxford-477.html#92=22&180=79

You can specify after # the attribute ids and selected values:

#attr_id1=value1&attr_id2=value2&...

SO if you know the attribute id and the color value you should be able to build your url easily before redirecting to it.

1
  • Oh, that is so simple and useful! Thank you very much!
    – Syspect
    Commented Jul 22, 2014 at 8:47
1

You can add some identifier in the url and use this identifier to change the configurable option at the product page as in the following code

/** see http://www.magentocommerce.com/magento-connect/configurable-preselect-by-amasty.html
*/

var amasty_configurable_pre_select = new Class.create();

amasty_configurable_pre_select.prototype = {
initialize: function()    {},

select: function()
{
    var args = $A(arguments);
    $$('.product-options .super-attribute-select').each(function(select, i){
        if (args[i])
        {
            select.value = args[i];
            spConfig.configureElement(select);
        }
    });
}
};

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.