|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This page manages searching for products. |
|
4
|
|
|
* |
|
5
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
6
|
|
|
* @package: ecommerce |
|
7
|
|
|
* @sub-package: Pages |
|
8
|
|
|
**/ |
|
9
|
|
|
class ProductGroupSearchPage extends ProductGroup |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* standard SS variable. |
|
13
|
|
|
* |
|
14
|
|
|
* @static String | Array |
|
15
|
|
|
*/ |
|
16
|
|
|
private static $icon = 'ecommerce/images/icons/productgroupsearchpage'; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Standard SS variable. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private static $description = 'This page allowing the user to search for products.'; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Standard SS variable. |
|
27
|
|
|
*/ |
|
28
|
|
|
private static $singular_name = 'Product Search Page'; |
|
|
|
|
|
|
29
|
|
|
public function i18n_singular_name() |
|
30
|
|
|
{ |
|
31
|
|
|
return _t('ProductGroupSearchPage.SINGULARNAME', 'Product Search Page'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Standard SS variable. |
|
36
|
|
|
*/ |
|
37
|
|
|
private static $plural_name = 'Product Search Pages'; |
|
|
|
|
|
|
38
|
|
|
public function i18n_plural_name() |
|
39
|
|
|
{ |
|
40
|
|
|
return _t('ProductGroupSearchPage.PLURALNAME', 'Product Search Pages'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Standard SS function, we only allow for one Product Search Page to exist |
|
45
|
|
|
* but we do allow for extensions to exist at the same time. |
|
46
|
|
|
* |
|
47
|
|
|
* @param Member $member |
|
|
|
|
|
|
48
|
|
|
* |
|
49
|
|
|
* @return bool |
|
50
|
|
|
*/ |
|
51
|
|
|
public function canCreate($member = null) |
|
52
|
|
|
{ |
|
53
|
|
|
return ProductGroupSearchPage::get()->filter(array('ClassName' => 'ProductGroupSearchPage'))->Count() ? false : $this->canEdit($member); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Can product list (and related) be cached at all? |
|
58
|
|
|
* |
|
59
|
|
|
* @var bool |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $allowCaching = false; |
|
62
|
|
|
|
|
63
|
|
|
public function getGroupFilter() |
|
64
|
|
|
{ |
|
65
|
|
|
$resultArray = $this->searchResultsArrayFromSession(); |
|
66
|
|
|
$this->allProducts = $this->allProducts->filter(array('ID' => $resultArray)); |
|
67
|
|
|
|
|
68
|
|
|
return $this->allProducts; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* returns the SORT part of the final selection of products. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string | Array |
|
|
|
|
|
|
75
|
|
|
*/ |
|
76
|
|
|
protected function currentSortSQL() |
|
77
|
|
|
{ |
|
78
|
|
|
$sortKey = $this->getCurrentUserPreferences('SORT'); |
|
79
|
|
|
$defaultSortKey = $this->getMyUserPreferencesDefault('SORT'); |
|
80
|
|
|
if ($sortKey == $defaultSortKey) { |
|
81
|
|
|
$resultArray = $this->searchResultsArrayFromSession(); |
|
82
|
|
|
|
|
83
|
|
|
return $this->createSortStatementFromIDArray($resultArray); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $this->getUserSettingsOptionSQL('SORT', $sortKey); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function childGroups($maxRecursiveLevel, $filter = null, $numberOfRecursions = 0) |
|
90
|
|
|
{ |
|
91
|
|
|
return ArrayList::create(); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
class ProductGroupSearchPage_Controller extends ProductGroup_Controller |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
/** |
|
98
|
|
|
* standard SS variable. |
|
99
|
|
|
* |
|
100
|
|
|
* @var array |
|
101
|
|
|
*/ |
|
102
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
103
|
|
|
'debug' => 'ADMIN', |
|
104
|
|
|
'filterforgroup' => true, |
|
105
|
|
|
'ProductSearchForm' => true, |
|
106
|
|
|
'searchresults' => true, |
|
107
|
|
|
'resetfilter' => true, |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
|
|
public function init() |
|
111
|
|
|
{ |
|
112
|
|
|
parent::init(); |
|
113
|
|
|
$array = $this->searchResultsArrayFromSession(); |
|
114
|
|
|
if (count($array) > 1) { |
|
115
|
|
|
$this->isSearchResults = true; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* returns child product groups for use in |
|
122
|
|
|
* 'in this section'. For example the vegetable Product Group |
|
123
|
|
|
* May have listed here: Carrot, Cabbage, etc... |
|
124
|
|
|
* |
|
125
|
|
|
* @return ArrayList (ProductGroups) |
|
|
|
|
|
|
126
|
|
|
*/ |
|
127
|
|
|
public function MenuChildGroups() |
|
128
|
|
|
{ |
|
129
|
|
|
return; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* The link that Google et al. need to index. |
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function CanonicalLink() |
|
137
|
|
|
{ |
|
138
|
|
|
$link = $this->Link(); |
|
139
|
|
|
$this->extend('UpdateCanonicalLink', $link); |
|
140
|
|
|
|
|
141
|
|
|
return $link; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
|
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.