Configurable Product – How to Link with Pre-Selected Values

configurable-productcustom-options

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)

Best Answer

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:

http://demo.magentocommerce.com/men/new-arrivals/linen-blazer.html#92=22&180=77

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>

with

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

Related Topic