public function getCMSFields() { $fields = new FieldList($rootTab = new TabSet('Root', $tabMain = new Tab('Country', TextField::create('Code', _t('Country.CODE', 'Code')), TextField::create('Title', _t('Country.TITLE', 'Title'))))); if ($this->isInDB()) { $config = GridFieldConfig_BasicSortable::create(); // $detailForm = $config->getComponentByType('GridFieldDetailForm'); // $detailForm->setItemRequestClass('GridFieldDetailForm_HasManyItemRequest'); $listField = new GridField('Regions', 'Regions', $this->Regions(), $config); $fields->addFieldToTab('Root.Regions', $listField); } return $fields; }
/** * Add some fields to the CMS for managing Attributes. * * @see DataObject::getCMSFields() * @return FieldList */ function getCMSFields() { $fields = new FieldList($rootTab = new TabSet('Root', $tabMain = new Tab('Attribute', TextField::create('Title')->setRightTitle('For displaying on the product page'), TextField::create('Description')->setRightTitle('For displaying on the order'), HiddenField::create('ProductID')))); if (!$this->ID) { $defaultAttributes = Attribute_Default::get(); if ($defaultAttributes && $defaultAttributes->exists()) { $fields->addFieldToTab('Root.Attribute', DropdownField::create('DefaultAttributeID', 'Use existing attribute', $defaultAttributes->map('ID', 'TitleOptionSummary')->toArray())->setHasEmptyDefault(true), 'Title'); $fields->addFieldToTab('Root.Attribute', new HeaderField('AttributeOr', 'Or create new one...', 5), 'Title'); } } if ($this->ID) { $fields->addFieldToTab('Root.Options', GridField::create('Options', 'Options', $this->Options(), GridFieldConfig_BasicSortable::create())); } $this->extend('updateCMSFields', $fields); return $fields; }
/** * Set some CMS fields for managing Products * * @see Page::getCMSFields() * @return FieldList */ public function getCMSFields() { $shopConfig = ShopConfig::current_shop_config(); $fields = parent::getCMSFields(); //Main Product Image $fields->addFieldToTab("Root.Main", $uploadField = new UploadField("MainProductImage", "Main Product Image")); $uploadField->setFolderName('Store'); $uploadField->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); // Use SortableUploadField instead of UploadField! $imageField = new SortableUploadField('OtherImages', 'Other Product Images'); $imageField->setFolderName('Store'); $imageField->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); $fields->addFieldToTab('Root.Main', $imageField); //Product fields $fields->addFieldToTab('Root.Main', new PriceField('Price'), 'Content'); //Replace URL Segment field if ($this->ParentID == -1) { $urlsegment = new SiteTreeURLSegmentField("URLSegment", 'URLSegment'); $baseLink = Controller::join_links(Director::absoluteBaseURL(), 'product/'); $url = strlen($baseLink) > 36 ? "..." . substr($baseLink, -32) : $baseLink; $urlsegment->setURLPrefix($url); $fields->replaceField('URLSegment', $urlsegment); } if ($this->isInDB()) { //Product attributes $listField = new GridField('Attributes', 'Attributes', $this->Attributes(), GridFieldConfig_BasicSortable::create()); $fields->addFieldToTab('Root.Attributes', $listField); //Product variations $attributes = $this->Attributes(); if ($attributes && $attributes->exists()) { //Remove the stock level field if there are variations, each variation has a stock field $fields->removeByName('Stock'); $variationFieldList = array(); foreach ($attributes as $attribute) { $variationFieldList['AttributeValue_' . $attribute->ID] = $attribute->Title; } $variationFieldList = array_merge($variationFieldList, singleton('Variation')->summaryFields()); $config = GridFieldConfig_HasManyRelationEditor::create(); $dataColumns = $config->getComponentByType('GridFieldDataColumns'); $dataColumns->setDisplayFields($variationFieldList); $listField = new GridField('Variations', 'Variations', $this->Variations(), $config); $fields->addFieldToTab('Root.Variations', $listField); } } //Ability to edit fields added to CMS here $this->extend('updateProductCMSFields', $fields); if ($warning = ShopConfig::base_currency_warning()) { $fields->addFieldToTab('Root.Main', new LiteralField('BaseCurrencyWarning', '<p class="message warning">' . $warning . '</p>'), 'Title'); } return $fields; }