frankmullenger/silverstripe-swipestripe — pull request #40 by LimeWub (2014-04-17 17:13:38+00:00)
Title: Product variation dropdown fixes

ProductForm.php:
Add a check to the constructor to check that the variations passed to javascipt have a status of enabled in the admin.

This prevents disabled variations from appearing on the frontend via json, which then get added to the nth dropdown (where n>=2).
(The first drop down doesn't get modified)
Eg:
Variations:
ID	Size	Style	Colour	Status
1	L	T-shirt	Green	Enabled
2	M	T-shirt	Green	Enabled
3	M	T-shirt	Black	Enabled
4	M	T-shirt	Pink	Disabled
The last variation shouldn't be added to the json / shown in the dropdowns:
The php that builds the first select (Size) includes L and M.
The php that builds the json data-map then includes the last variation (M:T-shirt:Pink:Disabled) because the size M is selectable for other variations despite this variation being disabled.

Attribute_OptionField.js
Add a check to prevent multiple instances of the same option being added to a given dropdown by javascript.

Description of problem:
With the above dataset, and with M selected for size, T-shirt gets added to the Style dropdown 2 or 3 times. 2 times if the previous fix is added, and 3 times if not.
The number of times the option is repeated is equal to the number of variations that include it after the set is filtered by the first dropdown.
So in this example, when M is selected for Size, there are:
2 'T-shirt' options added to the Style select (one for each of variations 2-3) when the ProductForm.php fix above is applied, and
3 'T-shirt' options added to the Style select (one for each of variations 2-4) when the ProductForm.php fix above is not applied.