public static function importTaxPercent(&$obj, $val, $record)
 {
     $tax_rate = TaxRate::get()->filter("Amount", $val)->first();
     if ($tax_rate) {
         $obj->TaxRateID = $tax_rate->ID;
     }
 }
 public function updateCMSFields(FieldList $fields)
 {
     // Add config sets
     $fields->addFieldToTab('Root.Catalogue', UploadField::create('DefaultProductImage', _t("Catalogue.DefaultProductImage", 'Default product image')));
     // Add config sets
     $fields->addFieldToTab('Root.Catalogue', GridField::create('TaxRates', _t("Catalogue.TaxRates", "Tax Rates"), TaxRate::get(), GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldAddNewButton('toolbar-header-right'), new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(5), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm())));
 }
 public function requireDefaultRecords()
 {
     // If no tax rates, setup some defaults
     if (!TaxRate::get()->exists()) {
         $vat = TaxRate::create();
         $vat->Title = "VAT";
         $vat->Amount = 20;
         $vat->Code = "T1";
         $vat->write();
         DB::alteration_message('VAT tax rate created.', 'created');
         $reduced = TaxRate::create();
         $reduced->Title = "Reduced rate";
         $reduced->Amount = 5;
         $reduced->Code = "T2";
         $reduced->write();
         DB::alteration_message('Reduced tax rate created.', 'created');
         $zero = TaxRate::create();
         $zero->Title = "Zero rate";
         $zero->Amount = 0;
         $zero->Code = "T4";
         $zero->write();
         DB::alteration_message('Zero tax rate created.', 'created');
     }
     parent::requireDefaultRecords();
 }
 public function getCMSFields()
 {
     // Get a list of available product classes
     $classnames = array_values(ClassInfo::subclassesFor("Product"));
     $product_types = array();
     foreach ($classnames as $classname) {
         $instance = singleton($classname);
         $product_types[$classname] = $instance->i18n_singular_name();
     }
     // If CMS Installed, use URLSegmentField, otherwise use text
     // field for URL
     if (class_exists('SiteTreeURLSegmentField')) {
         $baseLink = Controller::join_links(Director::absoluteBaseURL());
         $url_field = SiteTreeURLSegmentField::create("URLSegment");
         $url_field->setURLPrefix($baseLink);
     } else {
         $url_field = TextField::create("URLSegment");
     }
     $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', TextField::create("Title", $this->fieldLabel('Title')), $url_field, HTMLEditorField::create('Content', $this->fieldLabel('Content'))->setRows(20)->addExtraClass('stacked'), ToggleCompositeField::create('Metadata', _t('CatalogueAdmin.MetadataToggle', 'Metadata'), array($metaFieldDesc = TextareaField::create("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = TextareaField::create("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4)), $tabSettings = new Tab('Settings', NumericField::create("BasePrice", _t("Catalogue.Price", "Price")), TextField::create("StockID", $this->fieldLabel('StockID'))->setRightTitle(_t("Catalogue.StockIDHelp", "For example, a product SKU")), DropdownField::create("TaxRateID", $this->fieldLabel('TaxRate'), TaxRate::get()->map())->setEmptyString(_t("Catalogue.None", "None")), TreeMultiSelectField::create("Categories", null, "CatalogueCategory"), DropdownField::create("ClassName", _t("CatalogueAdmin.ProductType", "Type of product"), $product_types))));
     // Help text for MetaData on page content editor
     $metaFieldDesc->setRightTitle(_t('CatalogueAdmin.MetaDescHelp', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help');
     $metaFieldExtra->setRightTitle(_t('CatalogueAdmin.MetaExtraHelp', "HTML tags for additional meta information. For example <meta name=\"customName\" content=\"your custom content here\" />"))->addExtraClass('help');
     if ($this->ID) {
         $fields->addFieldToTab('Root.Images', SortableUploadField::create('Images', $this->fieldLabel('Images'), $this->Images()));
         $fields->addFieldToTab('Root.Related', GridField::create('RelatedProducts', "", $this->RelatedProducts(), new GridFieldConfig_CatalogueRelated("Product", null, 'SortOrder')));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 public function getCMSFields()
 {
     // Get a list of available product classes
     $classnames = ClassInfo::getValidSubClasses("CatalogueProduct");
     $product_array = array();
     foreach ($classnames as $classname) {
         if ($classname != "CatalogueProduct") {
             $description = Config::inst()->get($classname, 'description');
             if ($classname == 'Product' && !$description) {
                 $description = self::config()->description;
             }
             $description = $description ? $classname . ' - ' . $description : $classname;
             $product_array[$classname] = $description;
         }
     }
     // If we are creating a product, let us choose the product type
     if (!$this->ID) {
         $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', HiddenField::create("Title")->setValue(_t("Catalogue.NewProduct", "New Product")), ProductTypeField::create("ClassName", _t("Catalogue.SelectProductType", "Select a type of Product"), $product_array))));
     } else {
         // If CMS Installed, use URLSegmentField, otherwise use text
         // field for URL
         if (class_exists('SiteTreeURLSegmentField')) {
             $baseLink = Controller::join_links(Director::absoluteBaseURL());
             $url_field = SiteTreeURLSegmentField::create("URLSegment");
             $url_field->setURLPrefix($baseLink);
         } else {
             $url_field = TextField::create("URLSegment");
         }
         $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', TextField::create("Title", $this->fieldLabel('Title')), $url_field, HTMLEditorField::create('Content', $this->fieldLabel('Content'))->setRows(20)->addExtraClass('stacked'), ToggleCompositeField::create('Metadata', _t('CatalogueAdmin.MetadataToggle', 'Metadata'), array($metaFieldDesc = TextareaField::create("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = TextareaField::create("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4)), $tabSettings = new Tab('Settings', NumericField::create("BasePrice", _t("Catalogue.Price", "Price")), TextField::create("StockID", $this->fieldLabel('StockID'))->setRightTitle(_t("Catalogue.StockIDHelp", "For example, a product SKU")), DropdownField::create("TaxRateID", $this->fieldLabel('TaxRate'), TaxRate::get()->map())->setEmptyString(_t("Catalogue.None", "None")), TreeMultiSelectField::create("Categories", null, "CatalogueCategory"), CheckboxField::create("Disabled", _t("Catalogue.DisableProduct", "Disable this product (will not appear on shopfront)")), DropdownField::create("ClassName", _t("CatalogueAdmin.ProductType", "Type of product"), $product_array)), $tabImages = new Tab('Images', SortableUploadField::create('Images', $this->fieldLabel('Images'), $this->Images()))));
         // Help text for MetaData on page content editor
         $metaFieldDesc->setRightTitle(_t('CatalogueAdmin.MetaDescHelp', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help');
         $metaFieldExtra->setRightTitle(_t('CatalogueAdmin.MetaExtraHelp', "HTML tags for additional meta information. For example <meta name=\"customName\" content=\"your custom content here\" />"))->addExtraClass('help');
         $fields->addFieldToTab('Root.Related', GridField::create('RelatedProducts', "", $this->RelatedProducts(), GridFieldConfig_RelationEditor::create()));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }