1 <?php
2
3 4 5 6 7 8
9 class CatalogSiteConfig 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 'CatalogDefaultFilter' => 'Varchar(255)',
22 'ProductShowInTree' => 'Boolean',
23 ),
24 'defaults' => array(
25 'ProductPerPage' => 20,
26 'CatalogCurrency' => 'руб.',
27 'CatalogDiscountCeil' => true,
28 'CatalogDefaultSort' => 'title',
29 'CatalogDefaultView' => 'table',
30 'CatalogDefaultFilter' => 'Title,Price',
31 'ProductShowInTree' => false,
32 )
33 );
34 }
35
36 public function updateCMSFields(FieldSet &$fields) {
37 $tab = self::get_config_tab($fields, 'Catalog');
38
39 $tab->push(new NumericField('ProductPerPage', $this->owner->FieldLabel('ProductPerPage')));
40 $tab->push(new TextField('CatalogCurrency', $this->owner->FieldLabel('CatalogCurrency')));
41 $tab->push(new CheckboxField('CatalogDiscountCeil', $this->owner->FieldLabel('CatalogDiscountCeil')));
42
43 if (count(Product::get_sort_options()) > 1)
44 $tab->push(new DropDownField('CatalogDefaultSort', $this->owner->FieldLabel('CatalogDefaultSort'), Product::sort_options_dropdown_map()));
45
46 if (count(Catalog::get_view_options()) > 1)
47 $tab->push(new DropDownField('CatalogDefaultView', $this->owner->FieldLabel('CatalogDefaultView'), Catalog::view_options_dropdown_map()));
48
49 if (Product::filter_fields_list())
50 $tab->push(new CheckboxSetField('CatalogDefaultFilter', $this->owner->fieldLabel('CatalogDefaultFilter'), Product::filter_fields_list()));
51
52 if (Director::IsDev())
53 $tab->push(new CheckboxField('ProductShowInTree', $this->owner->FieldLabel('ProductShowInTree')));
54
55 $this->hideUnselectedFields($fields);
56 }
57
58 59 60
61 public function onBeforeWrite() {
62 parent::onBeforeWrite();
63 if ($this->owner->isChanged('ProductShowInTree')) {
64 $state = (1 - $this->owner->ProductShowInTree);
65
66 DB::query("UPDATE `Page` SET `ShowOnlyInTab` = {$state} WHERE `ID` in (SELECT `ID` FROM `Product`)");
67
68 DB::query("UPDATE `Page_Live` SET `ShowOnlyInTab` = {$state} WHERE `ID` in (SELECT `ID` FROM `Product_Live`)");
69 }
70 }
71 }
72
[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.
-