1 <?php
2
3 4 5 6 7 8 9
10 class SpecialCatalog extends Catalog {
11
12 static $icon = 'catalog/images/special';
13 static $allowed_children = 'none';
14
15 static $db = array(
16 'Discount' => 'Int',
17 );
18
19 static $defaults = array(
20 'AutoChild' => 0,
21 'Discount' => 0,
22 'ShowInSearch' => 0,
23 'ShowInSiteMap' => 0,
24 );
25
26 static $many_many = array(
27 'LinkedProducts' => 'Product',
28 );
29
30 function getCMSFields() {
31 $fields = parent::getCMSFields();
32
33 $fields->removeByName('Copy');
34 $fields->removeByName('Subpages');
35 $fields->removeByName('Virtual');
36
37 if (class_exists('Cart'))
38 $fields->addFieldToTab('Root.Content.Main', new NumericField('Discount', $this->fieldLabel('Discount')), 'Description');
39
40 $products = new ManyManyDataObjectManager(
41 $this,
42 'LinkedProducts',
43 'Product',
44 array('Title'=>'Title', 'RealPrice'=>'Price', 'Vendor'=>'Vendor', 'ProductAdminLink' => 'Ссылка')
45 );
46 $products->setOnlyRelated(true);
47 $products->setPermissions(array('delete'));
48 $products->setPluralTitle(_t('SpecialCatalog.Products', 'Product list'));
49
50 $fields->addFieldToTab('Root.Content.tabSubPages', $products);
51
52 return $fields;
53 }
54
55 56 57 58 59 60
61 public function Subcats() {
62 return false;
63 }
64
65 public function CountItems() {
66 return $this->LinkedProducts()->Count();
67 }
68
69 public function Widget($id, $count=1) {
70
71 if (!$special = DataObject::get_by_id('SpecialCatalog', $id))
72 return false;
73
74 return $special->LinkedProducts(null, 'RAND()', null, $count);
75 }
76
77 function getProductsListQuery($orderby, $limit) {
78 $query = $this->getManyManyComponentsQuery('LinkedProducts', "", $orderby, "", $limit);
79 return $query;
80 }
81 }
82
83 class SpecialCatalog_Controller extends Catalog_Controller {
84 }
85
[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.
-