I'm building a couple fairly large configurable products under the Products category with about 175 products that basically have the same content, just different options (& they need their own SKU's). Unfortunately those products also show up under their respective Brands sub-categories.

Here's my question...

Is it possible to link to the configurable product & have an option selected depending on where they came from?

For example, if I have them coming from the Nike brand category, is it possible to have those options selected already on the configurable product so they don't have to select it again? I know it's possible to have options pre-selected from the configurable product backend side, but there's multiple ways people get to this page...and I would like them to have the options selected appropriate to where they came from.

(ie - if they went to Nike > Atheletic Wear > Hoodies...they would click on Hoodies, which would lead them to the configurable product page where 'Nike' under the 'Brands' would be selected and so on & so forth)

1 Answer 1


This is not a full answer but could be a nudge in the right direction.
You can autoselect configurable product options using an url hash.
Take a look for example here:


If you add #attribute_id=value_id to the URL Magento will select automatically the options you specify.
Now all you need to do is to find a way to append to the URL of the configurable products these values depending on the page you are on.
If you have only the brand as a configurable attribute then it should be easy.
You already know the id of of the brand attribute.
And for the value just create a new attribute for categories, with a custom source model that returns as options all the brands.
Let's call it brand.
Select for each category the brand you want autoselected.
Then in the product list page add something like this:

$urlSuffix = '';
if (Mage::registry('current_category')) {
    $urlSuffix = '#'.'brand attr id here'.'='.Mage::registry('current_category')->getBrand(); //find a way so you don't hard code the brand attribute id.

Then replace all occurrences of

<a href="<?php echo $_product->getUrl()?>">...</a>


<a href="<?php echo $_product->getUrl().$urlSuffix;?>">...</a>

If you have more attributes that need to be autoselected I think you can do the same as for brand attribute.

  • Is it possible to do this with the labels or codes rather than ids?
    – NotJay
    Jan 27, 2016 at 14:09
  • @NotJay. Not that I know of.
    – Marius
    Jan 27, 2016 at 14:13
  • Suppose I have the attribute code shirt_size and I can get the value of it when looping through the products like $subproduct->getAttributeText('shirt_size'); --- in this case how can I easily get the #attribute_id=value_id as per your example? Mabe we can add this to the answer ... super thanks!
    – snh_nl
    Aug 29, 2016 at 12:03
  • You can get the value using $subproduct->getShirtSize() and the attribute id with Mage::getModel('eav/config')->getAttribute('catalog_product', 'shirt_size')->getId()
    – Marius
    Aug 29, 2016 at 12:06
  • 1
    Anything like this for Magento 2?
    – thaddeusmt
    Dec 15, 2017 at 21:51

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.