1 <?php
2 3 4 5 6
7 class CatalogProductLinkedDecorator extends DataObjectDecorator {
8
9 static function add_extension($class='Product') {
10 Object::add_extension($class, 'CatalogProductLinkedDecorator');
11 }
12
13 function () {
14 return array(
15 'many_many' => array(
16 'LinkedCatalogs' => 'Catalog',
17 )
18 );
19 }
20
21 function updateCMSFields(FieldSet &$fields) {
22 $m = new ManyManyComplexTableField(
23 $this->owner,
24 'LinkedCatalogs',
25 'Catalog',
26 array('Title' => 'Каталог'),
27 null,
28 '"ClassName" = \'Catalog\' AND "SiteTree"."ID" <> ' . $this->owner->ParentID
29 );
30 $m->setPermissions(array());
31 $m->setPageSize(300);
32 $fields->findOrMakeTab('Root.Content.LinkedCatalogs', 'Связанные рубрики');
33 $fields->addFieldToTab("Root.Content.LinkedCatalogs", $m);
34 }
35
36 static $showProductCount = 10;
37
38 static function setShowProductCount($value) {
39 self::$showProductCount = $value;
40 }
41
42 static function getShowProductCount() {
43 return self::$showProductCount;
44 }
45
46 47 48 49 50
51 function LinkedProducts() {
52 $rs = false;
53 if (($rubrics = $this->owner->Parent()->LinkedCatalogs()) && $rubrics->Count()) {
54 $IDs = array();
55 foreach($rubrics as $rubric) {
56 $IDs[] = $rubric->ID;
57 $descendantIDs = $rubric->getDescendantIDList();
58 $IDs = array_merge($IDs, $descendantIDs);
59 }
60 $IDs = array_unique($IDs);
61
62 $rs = Dataobject::get('Product', "ParentID IN (".implode(',', $IDs).")", 'RAND()', "", self::$showProductCount);
63 }
64 return $rs;
65 }
66 }
[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.
-