1 <?php
2
3 4 5 6 7 8
9 class ProductCatalogSiteConfig extends SiteConfigDecorator {
10
11 static $hidden_fields = array();
12
13 function () {
14 return array(
15 'db' => array(
16 'ProductPerPage' => 'Int',
17 'CatalogCurrency' => 'Varchar',
18 'CatalogDiscountCeil' => 'Boolean',
19 'CatalogDefaultSort' => 'Varchar',
20 'CatalogDefaultView' => 'Varchar',
21 'ProductShowInTree' => 'Boolean',
22 'ShowProductsFromSubCategories' => 'Boolean',
23 'UseOnlyAllowPurchaseVariations' => 'Boolean',
24 ),
25 'defaults' => array(
26 'ProductPerPage' => 20,
27 'CatalogCurrency' => 'руб.',
28 'CatalogDiscountCeil' => true,
29 'CatalogDefaultSort' => 'title',
30 'CatalogDefaultView' => 'table',
31 'CatalogDefaultFilter' => 'Title,Price',
32 'ProductShowInTree' => false,
33 'ShowProductsFromSubCategories' => false,
34 'UseOnlyAllowPurchaseVariations' => false,
35 ),
36 'has_one' => array(
37 'DefaultVAT' => 'VAT',
38 )
39 );
40 }
41
42 public function updateCMSFields(FieldSet &$fields) {
43 $tab = self::get_config_tab($fields, 'Catalog.Settings');
44
45 if (count(Catalog::pagesize_dropdown_map()) > 1) {
46 $tab->push(new DropdownField('ProductPerPage', $this->owner->FieldLabel('ProductPerPage'), Catalog::pagesize_dropdown_map()));
47 }
48 else {
49 $tab->push(new NumericField('ProductPerPage', $this->owner->FieldLabel('ProductPerPage')));
50 }
51 $tab->push(new TextField('CatalogCurrency', $this->owner->FieldLabel('CatalogCurrency')));
52 $tab->push(new CheckboxField('CatalogDiscountCeil', $this->owner->FieldLabel('CatalogDiscountCeil')));
53 $tab->push(new CheckboxField('ShowProductsFromSubCategories', $this->owner->FieldLabel('ShowProductsFromSubCategories')));
54 if (Catalog::$use_variations) {
55 $tab->push(new CheckboxField('UseOnlyAllowPurchaseVariations', $this->owner->FieldLabel('UseOnlyAllowPurchaseVariations')));
56 }
57 $tab->push(new DropDownField('CatalogDefaultSort', $this->owner->FieldLabel('CatalogDefaultSort'), Product::sort_options_dropdown_map()));
58 $tab->push(new DropDownField('CatalogDefaultView', $this->owner->FieldLabel('CatalogDefaultView'), Catalog::view_options_dropdown_map()));
59 if ($allVATs = DataObject::get('VAT')) {
60 $tab->push(new DropDownField('DefaultVATID', $this->owner->FieldLabel('DefaultVAT'), $allVATs->map('ID', 'Title', _t('VAT.SelectVAT'))));
61 }
62
63 if (Director::IsDev())
64 $tab->push(new CheckboxField('ProductShowInTree', $this->owner->FieldLabel('ProductShowInTree')));
65
66 $this->hideUnselectedFields($fields);
67
68 if (Catalog::$use_additional_params) {
69 $tab = self::get_config_tab($fields, 'Catalog.Params');
70 $ctf = new ComplexTableField(
71 $this,
72 'ProductParams',
73 'ProductParam',
74 null,
75 null,
76 'ParentCatalogID = 0'
77 );
78 $ctf->setRelationAutoSetting(true);
79 $ctf->setPagesize(20);
80 $tab->push($ctf);
81 }
82
83 if (Catalog::$use_additional_filters) {
84 $tab = self::get_config_tab($fields, 'Catalog.Filters');
85 $ctf = new ComplexTableField(
86 $this,
87 'CatalogFilters',
88 'CatalogFilter',
89 null,
90 null,
91 'ParentCatalogID = 0'
92 );
93 $ctf->setRelationAutoSetting(true);
94 $ctf->setPagesize(20);
95 $tab->push($ctf);
96 }
97 }
98
99 100 101
102 public function onBeforeWrite() {
103 parent::onBeforeWrite();
104 if ($this->owner->isChanged('ProductShowInTree')) {
105 $state = (1 - $this->owner->ProductShowInTree);
106
107 DB::query("UPDATE `Page` SET `ShowOnlyInTab` = {$state} WHERE `ID` in (SELECT `ID` FROM `Product`)");
108
109 DB::query("UPDATE `Page_Live` SET `ShowOnlyInTab` = {$state} WHERE `ID` in (SELECT `ID` FROM `Product_Live`)");
110 }
111 }
112 }
113
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-