Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Dynamically filtering product attribute options so it's impossible to select certain combinations
Post Body

A client wants it so that it's not possible for customers to select product attribute pulldown combinations that refer to either non-existent or out of stock variations (they don't like customers making a selection from four pulldowns only to be told it's invalid). I took a stab at coding a solution that mostly works. https://gist.github.com/rhaglennydd/b7a3ed4102811f613ecb614e3b7082c7

From functions.php the class SingleProduct is instantiated and the setup method is called to kick things off. The JavaScript is in the productVariationFooterScript method. Every time the user selects an option from an attribute pulldown an AJAX request is made, which is handled by the method ajaxFilterProductAttributeOptions (it returns valid options for all the other pulldowns, which then get updated by JavaScript). Like I say it mostly works, the attribute pulldown options are filtered properly for the most part, the only hitch I've found is that if the user makes selections from the first three pulldowns sometimes they can hit a combination for which any of the options for the last pulldown results in an out of stock variation. (There are variations like this in the system.) Thus no options are returned for that pulldown via AJAX, so its options are unchanged. I suspect this code needs to be reworked substantially to be more intelligent, maybe involving recursion, but I'm not sure how I would go about it.

Author
Account Strength
100%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
5,125
Link Karma
983
Comment Karma
4,129
Profile updated: 3 days ago
Posts updated: 7 hours ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago