/**
  * Add fields for editing a Variation in the CMS popup.
  * 
  * @return FieldSet
  */
 public function getCMSFields_forPopup()
 {
     $fields = $this->getCMSFields(array('includeRelations' => false));
     $fields->removeByName('Image');
     $fields->removeByName('StockLevelID');
     $fields->removeByName('Version');
     $fields->addFieldToTab("Root", new Tab('Advanced'));
     $product = $this->Product();
     $attributes = $product->Attributes();
     if ($attributes && $attributes->exists()) {
         foreach ($attributes as $attribute) {
             $options = DataObject::get('Option', "ProductID = {$product->ID} AND AttributeID = {$attribute->ID}");
             $currentOptionID = ($currentOption = $this->Options()->find('AttributeID', $attribute->ID)) ? $currentOption->ID : null;
             $optionField = new OptionField($attribute->ID, $attribute->Title, $options, $currentOptionID);
             $optionField->setHasEmptyDefault(false);
             $fields->addFieldToTab('Root.Main', $optionField);
         }
     }
     //Stock level field
     $level = $this->StockLevel()->Level;
     $fields->addFieldToTab('Root.Main', new StockField('Stock', null, $level, $this));
     $fields->addFieldToTab('Root.Advanced', new DropdownField('Status', 'Status (you can disable a variation to prevent it being sold)', $this->dbObject('Status')->enumValues()));
     $amountField = new VariationMoneyField('Amount', 'Amount that this variation will increase the base product price by');
     $amountField->setAllowedCurrencies(Product::$allowed_currency);
     $fields->addFieldToTab('Root.Advanced', $amountField);
     return $fields;
 }
Esempio n. 2
0
 /**
  * Add fields for editing a Variation in the CMS popup.
  * 
  * @return FieldList
  */
 public function getCMSFields()
 {
     $fields = new FieldList($rootTab = new TabSet('Root', $tabMain = new Tab('Variation')));
     $product = $this->Product();
     $attributes = $product->Attributes();
     if ($attributes && $attributes->exists()) {
         foreach ($attributes as $attribute) {
             $options = $attribute->Options();
             $currentOptionID = ($currentOption = $this->Options()->find('AttributeID', $attribute->ID)) ? $currentOption->ID : null;
             $optionField = new OptionField($attribute->ID, $attribute->Title, $options, $currentOptionID);
             $optionField->setHasEmptyDefault(false);
             $fields->addFieldToTab('Root.Variation', $optionField);
         }
     }
     $fields->addFieldToTab('Root.Variation', PriceField::create('Price', 'Price')->setRightTitle('Amount that this variation will increase the base product price by'));
     $fields->addFieldToTab('Root.Variation', DropdownField::create('Status', 'Status', $this->dbObject('Status')->enumValues())->setRightTitle('You can disable a variation to prevent it being sold'));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }