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
|
|
|
/** |
13
|
|
|
* standard SS variable. |
14
|
|
|
* |
15
|
|
|
* @static String | Array |
16
|
|
|
*/ |
17
|
|
|
private static $icon = 'ecommerce/images/icons/productgroupsearchpage'; |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Standard SS variable. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private static $description = 'This page allowing the user to search for products.'; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Standard SS variable. |
28
|
|
|
*/ |
29
|
|
|
private static $singular_name = 'Product Search Page'; |
|
|
|
|
30
|
|
|
public function i18n_singular_name() |
31
|
|
|
{ |
32
|
|
|
return _t('ProductGroupSearchPage.SINGULARNAME', 'Product Search Page'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Standard SS variable. |
37
|
|
|
*/ |
38
|
|
|
private static $plural_name = 'Product Search Pages'; |
|
|
|
|
39
|
|
|
public function i18n_plural_name() |
40
|
|
|
{ |
41
|
|
|
return _t('ProductGroupSearchPage.PLURALNAME', 'Product Search Pages'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Standard SS function, we only allow for one Product Search Page to exist |
46
|
|
|
* but we do allow for extensions to exist at the same time. |
47
|
|
|
* |
48
|
|
|
* @param Member $member |
|
|
|
|
49
|
|
|
* |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
|
|
public function canCreate($member = null) |
53
|
|
|
{ |
54
|
|
|
return ProductGroupSearchPage::get()->filter(array('ClassName' => 'ProductGroupSearchPage'))->Count() ? false : $this->canEdit($member); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Can product list (and related) be cached at all? |
59
|
|
|
* |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
protected $allowCaching = false; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* This is a KEY method that overrides the standard method! |
66
|
|
|
* @return [type] [description] |
|
|
|
|
67
|
|
|
*/ |
68
|
|
|
public function getGroupFilter() |
69
|
|
|
{ |
70
|
|
|
$resultArray = $this->searchResultsArrayFromSession(); |
71
|
|
|
$this->allProducts = $this->allProducts->filter(array('ID' => $resultArray)); |
72
|
|
|
|
73
|
|
|
return $this->allProducts; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* returns the SORT part of the final selection of products. |
79
|
|
|
* |
80
|
|
|
* @return string | Array |
|
|
|
|
81
|
|
|
*/ |
82
|
|
|
protected function currentSortSQL() |
83
|
|
|
{ |
84
|
|
|
$sortKey = $this->getCurrentUserPreferences('SORT'); |
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
|
|
|
* returns child product groups for use in |
121
|
|
|
* 'in this section'. For example the vegetable Product Group |
122
|
|
|
* May have listed here: Carrot, Cabbage, etc... |
123
|
|
|
* |
124
|
|
|
* @return ArrayList (ProductGroups) |
|
|
|
|
125
|
|
|
*/ |
126
|
|
|
public function MenuChildGroups() |
127
|
|
|
{ |
128
|
|
|
return; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function ProductsShowable($extraFilter = null, $alternativeSort = null, $alternativeFilterKey = '') |
|
|
|
|
132
|
|
|
{ |
133
|
|
|
$alternativeSort = $this->getSearchResultsDefaultSort($this->searchResultsArrayFromSession(), $alternativeSort); |
134
|
|
|
|
135
|
|
|
$this->allProducts = parent::ProductsShowable($extraFilter, $alternativeSort, $alternativeFilterKey); |
136
|
|
|
|
137
|
|
|
return $this->allProducts; |
138
|
|
|
} |
139
|
|
|
/** |
140
|
|
|
* The link that Google et al. need to index. |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function CanonicalLink() |
144
|
|
|
{ |
145
|
|
|
$link = $this->Link(); |
146
|
|
|
$this->extend('UpdateCanonicalLink', $link); |
147
|
|
|
|
148
|
|
|
return $link; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|