/**
  * Adds or modifies the fields for the Main tab
  *
  * @param FieldList $fields FieldList to add fields to
  * 
  * @return void
  */
 public function getFieldsForMain($fields)
 {
     $fields->dataFieldByName('StockQuantityOverbookable')->setTitle($this->fieldLabel('StockQuantityOverbookableShort'));
     $fields->dataFieldByName('StockQuantityExpirationDate')->addExtraClass("date");
     $fields->dataFieldByName('StockQuantityExpirationDate')->setConfig('showcalendar', true);
     $fields->dataFieldByName('StockQuantityExpirationDate')->FieldHolder();
     $purchaseTimeUnitSource = array('Days' => _t('Silvercart.DAYS', 'Days'), 'Weeks' => _t('Silvercart.WEEKS', 'Weeks'), 'Months' => _t('Silvercart.MONTHS', 'Months'));
     $fields->dataFieldByName('PurchaseTimeUnit')->setSource($purchaseTimeUnitSource);
     $fields->dataFieldByName('ReleaseDate')->getDateField()->addExtraClass("date")->setConfig('showcalendar', true);
     $fields->dataFieldByName('LaunchDate')->getDateField()->addExtraClass("date")->setConfig('showcalendar', true);
     $fields->dataFieldByName('SalesBanDate')->getDateField()->addExtraClass("date")->setConfig('showcalendar', true);
     $productNumberGroup = new SilvercartFieldGroup('ProductNumberGroup', '', $fields);
     $productNumberGroup->push($fields->dataFieldByName('ProductNumberShop'));
     $productNumberGroup->push($fields->dataFieldByName('ProductNumberManufacturer'));
     $productNumberGroup->push($fields->dataFieldByName('EANCode'));
     $baseDataToggle = ToggleCompositeField::create('ProductBaseDataToggle', $this->fieldLabel('BasicData'), array($fields->dataFieldByName('isActive'), $fields->dataFieldByName('IsNotBuyable'), $productNumberGroup))->setHeadingLevel(4)->setStartClosed(false);
     $fields->removeByName('isActive');
     $fields->removeByName('IsNotBuyable');
     $fields->insertBefore($baseDataToggle, 'Title');
     if ($this->exists()) {
         $fields->insertAfter(new CheckboxField('RefreshCache', $this->fieldLabel('RefreshCache')), 'isActive');
     }
     $descriptionToggle = ToggleCompositeField::create('ProductDescriptionToggle', $this->fieldLabel('LongDescription'), array($fields->dataFieldByName('Title'), $fields->dataFieldByName('ShortDescription'), $fields->dataFieldByName('LongDescription')))->setHeadingLevel(4)->setStartClosed(false);
     $fields->removeByName('Title');
     $fields->removeByName('ShortDescription');
     $fields->removeByName('LongDescription');
     $fields->insertAfter($descriptionToggle, 'ProductBaseDataToggle');
     $availabilityGroup = new SilvercartFieldGroup('AvailabilityGroup', '', $fields);
     $availabilityGroup->push($fields->dataFieldByName('SilvercartAvailabilityStatusID'));
     $availabilityGroup->breakAndPush($fields->dataFieldByName('PurchaseMinDuration'));
     $availabilityGroup->push($fields->dataFieldByName('PurchaseMaxDuration'));
     $availabilityGroup->push($fields->dataFieldByName('PurchaseTimeUnit'));
     $availabilityGroup->breakAndPush($fields->dataFieldByName('StockQuantity'));
     $availabilityGroup->push($fields->dataFieldByName('StockQuantityOverbookable'));
     $availabilityGroup->push($fields->dataFieldByName('StockQuantityExpirationDate'));
     $availabilityGroupToggle = ToggleCompositeField::create('AvailabilityGroupToggle', $this->fieldLabel('SilvercartAvailabilityStatus'), array($availabilityGroup))->setHeadingLevel(4)->setStartClosed(true);
     $fields->insertAfter($availabilityGroupToggle, 'ProductDescriptionToggle');
     $timeGroup = new SilvercartFieldGroup('TimeGroup', '', $fields);
     $timeGroup->push($fields->dataFieldByName('ReleaseDate'));
     $timeGroup->pushAndBreak(new LabelField('ReleaseDateInfo', '<br/><br/><br/>' . $this->fieldLabel('ReleaseDateInfo')));
     $timeGroup->push($fields->dataFieldByName('LaunchDate'));
     $timeGroup->pushAndBreak(new LabelField('LaunchDateInfo', '<br/><br/><br/>' . $this->fieldLabel('LaunchDateInfo')));
     $timeGroup->push($fields->dataFieldByName('SalesBanDate'));
     $timeGroup->pushAndBreak(new LabelField('SalesBanDateInfo', '<br/><br/><br/>' . $this->fieldLabel('SalesBanDateInfo')));
     $timeGroupToggle = ToggleCompositeField::create('TimeGroupToggle', $this->fieldLabel('TimeGroup'), array($timeGroup))->setHeadingLevel(4)->setStartClosed(true);
     $fields->insertAfter($timeGroupToggle, 'AvailabilityGroupToggle');
     $miscGroup = new SilvercartFieldGroup('MiscGroup', '', $fields);
     if ($fields->hasField('SilvercartManufacturerID')) {
         $miscGroup->pushAndBreak($fields->dataFieldByName('SilvercartManufacturerID'));
     }
     $miscGroup->breakAndPush($fields->dataFieldByName('ExcludeFromPaymentDiscounts'));
     $miscGroup->breakAndPush($fields->dataFieldByName('PackagingQuantity'));
     $miscGroup->pushAndBreak($fields->dataFieldByName('SilvercartQuantityUnitID'));
     $miscGroup->breakAndPush($fields->dataFieldByName('Weight'));
     $miscGroup->breakAndPush($fields->dataFieldByName('SilvercartProductConditionID'));
     $miscGroupToggle = ToggleCompositeField::create('AvailabilityGroupToggle', $this->fieldLabel('MiscGroup'), array($miscGroup))->setHeadingLevel(4)->setStartClosed(true);
     $fields->insertAfter($miscGroupToggle, 'TimeGroupToggle');
 }
 /**
  * Customizes the backends fields, mainly for ModelAdmin
  *
  * @return FieldList the fields for the backend
  * 
  * @author Roland Lehmann <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 13.02.2013
  */
 public function getCMSFields()
 {
     $this->getCMSFieldsIsCalled = true;
     $fields = parent::getCMSFields();
     $postPricingField = $fields->dataFieldByName('PostPricing');
     $postPricingField->setTitle($postPricingField->Title() . ' (' . $this->fieldLabel('PostPricingInfo') . ')');
     SilvercartTax::presetDropdownWithDefault($fields->dataFieldByName('SilvercartTaxID'), $this);
     $fieldGroup = new SilvercartFieldGroup('ShippingFeeGroup', '', $fields);
     $fieldGroup->push($fields->dataFieldByName('MaximumWeight'));
     $fieldGroup->pushAndBreak($fields->dataFieldByName('UnlimitedWeight'));
     $fieldGroup->push($fields->dataFieldByName('Price'));
     $fieldGroup->pushAndBreak($fields->dataFieldByName('SilvercartTaxID'));
     $fieldGroup->pushAndBreak($postPricingField);
     // only the carriers zones must be selectable
     $leftJoinTable = 'SilvercartZone_SilvercartCarriers';
     $leftJoinOn = '"SilvercartZone"."ID" = "SilvercartZone_SilvercartCarriers"."SilvercartZoneID"';
     $where = sprintf("\"SilvercartZone_SilvercartCarriers\".\"SilvercartCarrierID\" = %s", $this->SilvercartShippingMethod()->SilvercartCarrier()->ID);
     $zones = SilvercartZone::get()->leftJoin($leftJoinTable, $leftJoinOn)->where($where);
     if ($zones->exists()) {
         $zonesMap = $zones->map('ID', 'Title');
         $zonesField = new DropdownField('SilvercartZoneID', _t('SilvercartShippingFee.ZONE_WITH_DESCRIPTION', 'zone (only carrier\'s zones available)'), $zonesMap->toArray());
         $fieldGroup->push($zonesField);
     }
     $fieldGroup->breakAndPush($fields->dataFieldByName('freeOfShippingCostsDisabled'));
     $fieldGroup->breakAndPush($fields->dataFieldByName('freeOfShippingCostsFrom'));
     $fields->dataFieldByName('DeliveryTimeMin')->setRightTitle($this->fieldLabel('DeliveryTimeMinDesc'));
     $fields->dataFieldByName('DeliveryTimeMax')->setRightTitle($this->fieldLabel('DeliveryTimeMaxDesc'));
     $fields->dataFieldByName('DeliveryTimeText')->setRightTitle($this->fieldLabel('DeliveryTimeTextDesc'));
     $parentDeliveryTime = '';
     if ($this->SilvercartShippingMethod()->exists()) {
         $parentDeliveryTime = '<br/>(' . SilvercartShippingMethod::get_delivery_time($this->SilvercartShippingMethod(), true) . ')';
     }
     $fieldGroup->pushAndBreak(new LiteralField('DeliveryTimeHint', '<strong>' . $this->fieldLabel('DeliveryTimeHint') . $parentDeliveryTime . '</strong>'));
     $fieldGroup->push($fields->dataFieldByName('DeliveryTimeMin'));
     $fieldGroup->pushAndBreak($fields->dataFieldByName('DeliveryTimeMax'));
     $fieldGroup->pushAndBreak($fields->dataFieldByName('DeliveryTimeText'));
     $fields->addFieldToTab('Root.Main', $fieldGroup);
     return $fields;
 }
 /**
  * Return all fields of the backend.
  *
  * @return FieldList Fields of the CMS
  */
 public function getCMSFields()
 {
     $this->getCMSFieldsIsCalled = true;
     $fields = parent::getCMSFields();
     $useOnlydefaultGroupviewSource = array('inherit' => _t('SilvercartProductGroupPage.DEFAULTGROUPVIEW_DEFAULT'), 'yes' => _t('Silvercart.YES'), 'no' => _t('Silvercart.NO'));
     $useContentField = new CheckboxField('useContentFromParent', $this->fieldLabel('useContentFromParent'));
     $doNotShowProductsField = new CheckboxField('DoNotShowProducts', $this->fieldLabel('DoNotShowProducts'));
     $productsPerPageField = new TextField('productsPerPage', $this->fieldLabel('productsPerPage'));
     $defaultGroupViewField = SilvercartGroupViewHandler::getGroupViewDropdownField('DefaultGroupView', $this->fieldLabel('DefaultGroupView'), $this->DefaultGroupView, _t('SilvercartProductGroupPage.DEFAULTGROUPVIEW_DEFAULT'));
     $useOnlyDefaultGroupViewField = new DropdownField('UseOnlyDefaultGroupView', $this->fieldLabel('UseOnlyDefaultGroupView'), $useOnlydefaultGroupviewSource, $this->UseOnlyDefaultGroupView);
     $productGroupsPerPageField = new TextField('productGroupsPerPage', $this->fieldLabel('productGroupsPerPage'));
     $defaultGroupHolderViewField = SilvercartGroupViewHandler::getGroupViewDropdownField('DefaultGroupHolderView', $this->fieldLabel('DefaultGroupHolderView'), $this->DefaultGroupHolderView, _t('SilvercartProductGroupPage.DEFAULTGROUPVIEW_DEFAULT'));
     $useOnlyDefaultGroupHolderViewField = new DropdownField('UseOnlyDefaultGroupHolderView', $this->fieldLabel('UseOnlyDefaultGroupHolderView'), $useOnlydefaultGroupviewSource, $this->UseOnlyDefaultGroupHolderView);
     $fieldGroup = new SilvercartFieldGroup('FieldGroup', '', $fields);
     $productsPerPageField->setRightTitle(_t('SilvercartProductGroupPage.PRODUCTSPERPAGEHINT'));
     $productGroupsPerPageField->setRightTitle(_t('SilvercartProductGroupPage.PRODUCTSPERPAGEHINT'));
     $fieldGroup->push($useContentField);
     $fieldGroup->breakAndPush($doNotShowProductsField);
     $fieldGroup->breakAndPush($productsPerPageField);
     $fieldGroup->breakAndPush($defaultGroupViewField);
     $fieldGroup->push($useOnlyDefaultGroupViewField);
     $fieldGroup->breakAndPush($productGroupsPerPageField);
     $fieldGroup->breakAndPush($defaultGroupHolderViewField);
     $fieldGroup->push($useOnlyDefaultGroupHolderViewField);
     $displaySettingsToggle = ToggleCompositeField::create('DisplaySettingsToggle', $this->fieldLabel('DisplaySettings'), array($fieldGroup))->setHeadingLevel(4)->setStartClosed(true);
     $fields->insertAfter($displaySettingsToggle, 'Content');
     $mirroredProductIdList = '';
     $mirroredProductIDs = $this->getMirroredProductIDs();
     foreach ($mirroredProductIDs as $mirroredProductID) {
         $mirroredProductIdList .= sprintf("'%s',", $mirroredProductID);
     }
     if (!empty($mirroredProductIdList)) {
         $mirroredProductIdList = substr($mirroredProductIdList, 0, -1);
         $filter = sprintf("SilvercartProductGroupID = %d OR\n                 \"SilvercartProduct\".\"ID\" IN (%s)", $this->ID, $mirroredProductIdList);
     } else {
         $filter = sprintf("SilvercartProductGroupID = %d", $this->ID);
     }
     if ($this->drawCMSFields()) {
         $config = GridFieldConfig_RecordViewer::create(100);
         $productsTableField = new GridField('SilvercartProducts', $this->fieldLabel('SilvercartProducts'), SilvercartProduct::get()->filter(array('SilvercartProductGroupID' => $this->ID)), $config);
         $tabPARAM = "Root." . _t('SilvercartProduct.TITLE', 'product');
         $fields->addFieldToTab($tabPARAM, $productsTableField);
         $productAdminLink = Director::baseURL() . 'admin/silvercart-products';
         $manageProductsButton = new LiteralField('ManageProductsButton', sprintf("<a href=\"%s\">%s</a>", $productAdminLink, _t('SilvercartProductGroupPage.MANAGE_PRODUCTS_BUTTON')));
         $fields->addFieldToTab($tabPARAM, $manageProductsButton);
         $fields->addFieldToTab('Root.Main', new UploadField('GroupPicture', _t('SilvercartProductGroupPage.GROUP_PICTURE')), 'Content');
     }
     $widgetSetContent = $fields->fieldByName('Root.Widgets.WidgetSetContent');
     if ($widgetSetContent) {
         $widgetSetAdminLink = Director::baseURL() . 'admin/silvercart-widget-sets';
         $manageWidgetsButton = new LiteralField('ManageWidgetsButton', sprintf("<a href=\"%s\">%s</a>", $widgetSetAdminLink, _t('SilvercartWidgetSet.MANAGE_WIDGETS_BUTTON')));
         $fields->insertAfter($manageWidgetsButton, 'WidgetSetContent');
     }
     $this->extend('extendCMSFields', $fields);
     return $fields;
 }
 /**
  * Return all fields of the backend.
  *
  * @return FieldList Fields of the CMS
  */
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $useOnlydefaultGroupviewSource = array('inherit' => _t('SilvercartProductGroupPage.DEFAULTGROUPVIEW_DEFAULT'), 'yes' => $this->fieldLabel('Yes'), 'no' => $this->fieldLabel('No'));
     $defaultGroupViewField = SilvercartGroupViewHandler::getGroupViewDropdownField('DefaultGroupView', $this->fieldLabel('DefaultGroupView'), $this->DefaultGroupView, _t('SilvercartProductGroupPage.DEFAULTGROUPVIEW_DEFAULT'));
     $useOnlyDefaultGroupViewField = new DropdownField('UseOnlyDefaultGroupView', $this->fieldLabel('UseOnlyDefaultGroupView'), $useOnlydefaultGroupviewSource, $this->UseOnlyDefaultGroupView);
     $productGroupsPerPageField = new TextField('productGroupsPerPage', $this->fieldLabel('productGroupsPerPage'));
     $defaultGroupHolderViewField = SilvercartGroupViewHandler::getGroupViewDropdownField('DefaultGroupHolderView', $this->fieldLabel('DefaultGroupHolderView'), $this->DefaultGroupHolderView, $this->fieldLabel('DefaultGroupView'));
     $useOnlyDefaultGroupHolderViewField = new DropdownField('UseOnlyDefaultGroupHolderView', $this->fieldLabel('UseOnlyDefaultGroupHolderView'), $useOnlydefaultGroupviewSource, $this->UseOnlyDefaultGroupHolderView);
     $fieldGroup = new SilvercartFieldGroup('FieldGroup', '', $fields);
     $redirectionFieldGroup = new SilvercartFieldGroup('RedirectionFieldGroup', '', $fields);
     $redirectToProductGroupField = new CheckboxField('RedirectToProductGroup', $this->fieldLabel('RedirectToProductGroup'));
     $linkToField = new TreeDropdownField('LinkToID', $this->fieldLabel('LinkTo'), 'SiteTree');
     $productGroupsPerPageField->setRightTitle(_t('SilvercartProductGroupPage.PRODUCTSPERPAGEHINT'));
     $fieldGroup->push($defaultGroupViewField);
     $fieldGroup->push($useOnlyDefaultGroupViewField);
     $fieldGroup->breakAndPush($productGroupsPerPageField);
     $fieldGroup->breakAndPush($defaultGroupHolderViewField);
     $fieldGroup->push($useOnlyDefaultGroupHolderViewField);
     $redirectionFieldGroup->push($redirectToProductGroupField);
     if ($this->exists()) {
         $linkToField->setTreeBaseID($this->ID);
         $redirectionFieldGroup->breakAndPush($linkToField);
     }
     $displaySettingsToggle = ToggleCompositeField::create('DisplaySettingsToggle', $this->fieldLabel('DisplaySettings'), array($fieldGroup))->setHeadingLevel(4)->setStartClosed(true);
     $redirectionSettingsToggle = ToggleCompositeField::create('RedirectionSettingsToggle', $this->fieldLabel('RedirectionSettings'), array($redirectionFieldGroup))->setHeadingLevel(4)->setStartClosed(true);
     $fields->insertAfter($redirectionSettingsToggle, 'Content');
     $fields->insertAfter($displaySettingsToggle, 'Content');
     $this->extend('extendCMSFields', $fields);
     return $fields;
 }