/** * 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; }