开发者

How can I auto-select the configurable options on a product details page?

开发者 https://www.devze.com 2023-04-03 18:43 出处:网络
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...

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号