public function ExchangeRateSettingsForm()
 {
     $shopConfig = ShopConfig::get()->First();
     if (singleton($this->modelClass)->hasMethod('getCMSValidator')) {
         $detailValidator = singleton($this->modelClass)->getCMSValidator();
         $listField->getConfig()->getComponentByType('GridFieldDetailForm')->setValidator($detailValidator);
     }
     $config = GridFieldConfig_HasManyRelationEditor::create();
     $detailForm = $config->getComponentByType('GridFieldDetailForm')->setValidator(singleton('ExchangeRate')->getCMSValidator());
     if (class_exists('GridFieldSortableRows')) {
         $config->addComponent(new GridFieldSortableRows('SortOrder'));
     }
     $fields = new FieldList($rootTab = new TabSet('Root', $tabMain = new Tab('ExchangeRates', GridField::create('ExchangeRates', 'ExchangeRates', $shopConfig->ExchangeRates(), $config))));
     $actions = new FieldList();
     $actions->push(FormAction::create('saveExchangeRateSettings', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add'));
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->setTemplate('ShopAdminSettings_EditForm');
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $form->addExtraClass('cms-content cms-edit-form center ss-tabset');
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->setFormAction(Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'ExchangeRate/ExchangeRateSettingsForm'));
     $form->loadDataFrom($shopConfig);
     return $form;
 }
Example #2
0
 public function AttributeSettingsForm()
 {
     $shopConfig = ShopConfig::get()->First();
     $fields = new FieldList($rootTab = new TabSet('Root', $tabMain = new Tab('Attribute', GridField::create('Attributes', 'Attributes', $shopConfig->Attributes(), GridFieldConfig_HasManyRelationEditor::create()))));
     $actions = new FieldList();
     $actions->push(FormAction::create('saveAttributeSettings', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add'));
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->setTemplate('ShopAdminSettings_EditForm');
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $form->addExtraClass('cms-content cms-edit-form center ss-tabset');
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->setFormAction(Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'Attribute/AttributeSettingsForm'));
     $form->loadDataFrom($shopConfig);
     return $form;
 }
Example #3
0
 /**
  * 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;
 }