1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
*@author nicolaas[at] |
5
|
|
|
*@description |
6
|
|
|
* |
7
|
|
|
* Provides a price list |
8
|
|
|
* |
9
|
|
|
* |
10
|
|
|
* |
11
|
|
|
* |
12
|
|
|
**/ |
13
|
|
|
|
14
|
|
|
class PriceListPage extends ProductGroup |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Standard SS variable. |
19
|
|
|
*/ |
20
|
|
|
private static $singular_name = "Price List Page"; |
|
|
|
|
21
|
|
|
public function i18n_singular_name() |
22
|
|
|
{ |
23
|
|
|
return _t("ProductGroup.PRICELISTPAGE", "Price List Page"); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Standard SS variable. |
28
|
|
|
*/ |
29
|
|
|
private static $plural_name = "Price List Pages"; |
|
|
|
|
30
|
|
|
public function i18n_plural_name() |
31
|
|
|
{ |
32
|
|
|
return _t("ProductGroup.PRICELISTPAGES", "Price List Pages"); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* standard SS variable |
37
|
|
|
* @static Array | String |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
|
|
private static $icon = "ecommerce_complex_pricing/images/treeicons/PriceListPage"; |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* standard SS variable |
44
|
|
|
* @static Array |
45
|
|
|
* |
46
|
|
|
*/ |
47
|
|
|
private static $db = array( |
|
|
|
|
48
|
|
|
"NumberOfLevelsToHide" => "Int" |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* standard SS variable |
53
|
|
|
* @static Array |
54
|
|
|
* |
55
|
|
|
*/ |
56
|
|
|
private static $defaults = array( |
|
|
|
|
57
|
|
|
"LevelOfProductsToShow" => -1, |
58
|
|
|
"NumberOfProductsPerPage" => 100, |
59
|
|
|
"NumberOfLevelsToHide" => 1 |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* standard SS variable |
65
|
|
|
* @static Array |
66
|
|
|
* |
67
|
|
|
*/ |
68
|
|
|
private static $allowed_children = "none"; |
|
|
|
|
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* standard SS Method |
73
|
|
|
* return FieldSet |
74
|
|
|
* |
75
|
|
|
*/ |
76
|
|
|
public function getCMSFields() |
77
|
|
|
{ |
78
|
|
|
$fields = parent::getCMSFields(); |
79
|
|
|
$fields->addFieldToTab('Root.ProductDisplay', new NumericField("NumberOfLevelsToHide", _t("PriceListPage.NUMBEROFLEVELSTOHIDE", "Number of levels to hide from the top down (e.g. set to one to hide main (top) product group holder). To hide all the parent product groups you can set this variable to something like 999."))); |
80
|
|
|
return $fields; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Retrieve a set of products, based on the given parameters. |
86
|
|
|
* Add Parent Group Pages to diplay within list. |
87
|
|
|
* |
88
|
|
|
* Note that you can hide the "top level" |
89
|
|
|
* @return DataObjectSet | Null |
|
|
|
|
90
|
|
|
*/ |
91
|
|
|
public function currentFinalProducts($alternativeSort = null) |
92
|
|
|
{ |
93
|
|
|
$products = parent::currentFinalProducts($alternativeSort); |
94
|
|
|
if ($products) { |
95
|
|
|
foreach ($products as $product) { |
96
|
|
|
$product->ParentSegments = null; |
97
|
|
|
if ($this->NumberOfLevelsToHide < 20) { |
98
|
|
|
$segmentArray = array(); |
99
|
|
|
$item = $product; |
100
|
|
|
while ($item && $item->ParentID) { |
101
|
|
|
$item = ProductGroup::get()->byID($item->ParentID); |
102
|
|
|
if ($item) { |
103
|
|
|
$segmentArray[] = array( |
104
|
|
|
"URLSegment" => $item->URLSegment, |
105
|
|
|
"ID" => $item->ID, |
106
|
|
|
"ClassName" => $item->ClassName, |
107
|
|
|
"Title" => $item->Title, |
108
|
|
|
"Link" => $item->Link() |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
if (count($segmentArray)) { |
113
|
|
|
$product->ParentSegments = new ArrayList(); |
114
|
|
|
$segmentArray = array_reverse($segmentArray); |
115
|
|
|
foreach ($segmentArray as $key => $segment) { |
116
|
|
|
if ($key > $this->NumberOfLevelsToHide) { |
117
|
|
|
$product->ParentSegments->push(new ArrayData($segment)); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
return $products; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
class PriceListPage_Controller extends ProductGroup_Controller |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
public function init() |
131
|
|
|
{ |
132
|
|
|
parent::init(); |
133
|
|
|
Requirements::themedCSS("PriceListPage", "ecommerce_complex_pricing"); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.