How can I auto-select the configurable options on a product details page?
I have certain configurable products on my store. What I want to do is automatically select the first values i开发者_运维百科n the drop-downs on the details page. I don't want to see Choose Option...
as the default.
The JS variable "spConfig" may help you get the solution.
You can use Firebug to investigate the structure of this variable in the product detail page of a configurable product.
"spConfig.config.attributes" records all the attributes for the current product and more importantly, the order of them is the same as the one presenting on the website. You can just get the DOM elements of the selects one by one and choose their first value and mimic a prototype "select change" action.
For more reference:
"spConfig.config.attributes[attribute_id].options" stores the possible attribute value for a certain attribute.
"spConfig.config.attributes[attribute_id].options[x].products" lists all the products belong to the certain attribute and value.
精彩评论