1 <?php
2
3 4 5 6 7 8
9 class ExtendProductSpecialCatalog extends DataObjectDecorator {
10
11 function () {
12 return array(
13 'belongs_many_many' => array(
14 'SpecialCatalogs' => 'SpecialCatalog',
15 ),
16
17 );
18 }
19
20 function updateCMSFields(&$fields) {
21
22 if ($specials = DataObject::get('SpecialCatalog')) {
23 $fields->addFieldToTab('Root.Content', new Tab("Catalogs", _t('Product.tab_Catalogs', 'Other catalogs')), 'Metadata');
24 $fields->addFieldToTab("Root.Content.Catalogs", new CheckboxSetField('SpecialCatalogs', _t('Product.many_many_SpecialCatalogs', 'Special Catalogs'), $specials));
25 }
26 }
27
28 function updateDiscount(&$percent) {
29 if ($this->owner->SpecialCatalogs()) {
30 foreach ($this->owner->SpecialCatalogs() as $spec) {
31 if ($spec->Discount > 0 && $percent < $spec->Discount) {
32 $percent = $spec->Discount;
33 }
34 }
35 }
36 }
37
38 39 40 41 42 43
44 function InCart() {
45 return Cart::in_cart($this->owner->ID);
46 }
47
48 49 50 51 52 53 54
55 function InSpecialCatalog($specialCatalogID) {
56 if (($catalogs = $this->owner->SpecialCatalogs()) && $catalogs->Count()) {
57 if ($catalogs->find('ID', $specialCatalogID)) {
58 return true;
59 }
60 }
61 return false;
62 }
63 }
64
[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.
-