/** * Construct the field with correct ID names and values * * @param String $name * @param Product $product */ function __construct($name, $product) { $this->name = $name; $this->product = $product; //Set an extra class for the wrapper $this->addExtraClass('OptionGroupField'); //Set an ID $this->setID('ProductOptions_' . $product->ID); //Use the product to get the attributes and options and set them to the class $items = new FieldSet(); $attributes = $this->product->Attributes()->map('ID', 'Label'); if ($attributes) { foreach ($attributes as $id => $title) { $options = $this->product->getOptionsForAttribute($id); if ($options->exists()) { $optionsField = new OptionField($id, $title, $options); $items->push($optionsField); } } } parent::__construct($items); }