Morningtime_TextfieldLayeredNav - Version 1.3.2.1

Version Notes

Stable Release

Download this release

Release Info

Developer Magento Core Team
Extension Morningtime_TextfieldLayeredNav
Version 1.3.2.1
Comparing to
See all releases


Version 1.3.2.1

Files changed (21) hide show
  1. app/code/community/Morningtime/TextfieldLayeredNav/Block/Adminhtml/Catalog/Product/Attribute/Edit/Tab/Main.php +386 -0
  2. app/code/community/Morningtime/TextfieldLayeredNav/Block/Adminhtml/Catalog/Product/Attribute/Edit/Tab/Options.php +79 -0
  3. app/code/community/Morningtime/TextfieldLayeredNav/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes.php +60 -0
  4. app/code/community/Morningtime/TextfieldLayeredNav/Block/Catalog/Product/Compare/List.php +34 -0
  5. app/code/community/Morningtime/TextfieldLayeredNav/Block/CatalogSearch/Advanced/Form.php +45 -0
  6. app/code/community/Morningtime/TextfieldLayeredNav/Model/Catalog/Entity/Attribute.php +92 -0
  7. app/code/community/Morningtime/TextfieldLayeredNav/Model/Catalog/Resource/Eav/Attribute.php +39 -0
  8. app/code/community/Morningtime/TextfieldLayeredNav/Model/Catalog/Resource/Eav/Mysql4/Product.php +138 -0
  9. app/code/community/Morningtime/TextfieldLayeredNav/Model/CatalogIndex/Indexer/Eav.php +48 -0
  10. app/code/community/Morningtime/TextfieldLayeredNav/Model/CatalogRule/Rule/Condition/Product.php +42 -0
  11. app/code/community/Morningtime/TextfieldLayeredNav/Model/CatalogSearch/Advanced.php +70 -0
  12. app/code/community/Morningtime/TextfieldLayeredNav/Model/CatalogSearch/Mysql4/Search/Collection.php +124 -0
  13. app/code/community/Morningtime/TextfieldLayeredNav/Model/Eav/Entity/Attribute.php +23 -0
  14. app/code/community/Morningtime/TextfieldLayeredNav/Model/Eav/Entity/Attribute/Frontend/Default.php +44 -0
  15. app/code/community/Morningtime/TextfieldLayeredNav/Model/Eav/Mysql4/Entity/Attribute.php +141 -0
  16. app/code/community/Morningtime/TextfieldLayeredNav/controllers/Adminhtml/Catalog/Product/AttributeController.php +57 -0
  17. app/code/community/Morningtime/TextfieldLayeredNav/etc/config.xml +92 -0
  18. app/design/adminhtml/default/default/template/morningtime/textfieldlayerednav/catalog/product/attribute/js.phtml +306 -0
  19. app/etc/modules/Morningtime_TextfieldLayeredNav.xml +25 -0
  20. lib/Varien/Data/Form/Element/Textfilter.php +77 -0
  21. package.xml +40 -0
app/code/community/Morningtime/TextfieldLayeredNav/Block/Adminhtml/Catalog/Product/Attribute/Edit/Tab/Main.php ADDED
@@ -0,0 +1,386 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Block_Adminhtml_Catalog_Product_Attribute_Edit_Tab_Main extends Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main
12
+ {
13
+
14
+ protected function _prepareForm()
15
+ {
16
+ $model = Mage::registry('entity_attribute');
17
+
18
+ $form = new Varien_Data_Form(array(
19
+ 'id' => 'edit_form',
20
+ 'action' => $this->getData('action'),
21
+ 'method' => 'post'
22
+ ));
23
+
24
+ $disableAttributeFields = array(
25
+ 'sku' => array(
26
+ 'is_global',
27
+ 'is_unique',
28
+ ),
29
+ 'url_key' => array(
30
+ 'is_unique',
31
+ ),
32
+ );
33
+
34
+ $fieldset = $form->addFieldset('base_fieldset',
35
+ array('legend'=>Mage::helper('catalog')->__('Attribute Properties'))
36
+ );
37
+ if ($model->getAttributeId()) {
38
+ $fieldset->addField('attribute_id', 'hidden', array(
39
+ 'name' => 'attribute_id',
40
+ ));
41
+ }
42
+
43
+ $this->_addElementTypes($fieldset);
44
+
45
+ $yesno = array(
46
+ array(
47
+ 'value' => 0,
48
+ 'label' => Mage::helper('catalog')->__('No')
49
+ ),
50
+ array(
51
+ 'value' => 1,
52
+ 'label' => Mage::helper('catalog')->__('Yes')
53
+ ));
54
+
55
+ $fieldset->addField('attribute_code', 'text', array(
56
+ 'name' => 'attribute_code',
57
+ 'label' => Mage::helper('catalog')->__('Attribute Code'),
58
+ 'title' => Mage::helper('catalog')->__('Attribute Code'),
59
+ 'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'),
60
+ 'class' => 'validate-code',
61
+ 'required' => true,
62
+ ));
63
+
64
+ $scopes = array(
65
+ Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
66
+ Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
67
+ Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
68
+ );
69
+
70
+ if ($model->getAttributeCode() == 'status' || $model->getAttributeCode() == 'tax_class_id') {
71
+ unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]);
72
+ }
73
+
74
+ $fieldset->addField('is_global', 'select', array(
75
+ 'name' => 'is_global',
76
+ 'label' => Mage::helper('catalog')->__('Scope'),
77
+ 'title' => Mage::helper('catalog')->__('Scope'),
78
+ 'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'),
79
+ 'values'=> $scopes
80
+ ));
81
+
82
+ $inputTypes = array(
83
+ array(
84
+ 'value' => 'text',
85
+ 'label' => Mage::helper('catalog')->__('Text Field')
86
+ ),
87
+ array(
88
+ 'value' => 'textarea',
89
+ 'label' => Mage::helper('catalog')->__('Text Area')
90
+ ),
91
+ array(
92
+ 'value' => 'date',
93
+ 'label' => Mage::helper('catalog')->__('Date')
94
+ ),
95
+ array(
96
+ 'value' => 'boolean',
97
+ 'label' => Mage::helper('catalog')->__('Yes/No')
98
+ ),
99
+ array(
100
+ 'value' => 'multiselect',
101
+ 'label' => Mage::helper('catalog')->__('Multiple Select')
102
+ ),
103
+ /* MT start */
104
+ array(
105
+ 'value' => 'textfilter',
106
+ 'label' => Mage::helper('catalog')->__('Textfield for Filter')
107
+ ),
108
+ /* MT out */
109
+ array(
110
+ 'value' => 'select',
111
+ 'label' => Mage::helper('catalog')->__('Dropdown')
112
+ ),
113
+ array(
114
+ 'value' => 'price',
115
+ 'label' => Mage::helper('catalog')->__('Price')
116
+ ),
117
+ array(
118
+ 'value' => 'gallery',
119
+ 'label' => Mage::helper('catalog')->__('Gallery')
120
+ ),
121
+ array(
122
+ 'value' => 'media_image',
123
+ 'label' => Mage::helper('catalog')->__('Media Image')
124
+ ),
125
+ );
126
+
127
+ $response = new Varien_Object();
128
+ $response->setTypes(array());
129
+ Mage::dispatchEvent('adminhtml_product_attribute_types', array('response'=>$response));
130
+
131
+ $_disabledTypes = array();
132
+ $_hiddenFields = array();
133
+ foreach ($response->getTypes() as $type) {
134
+ $inputTypes[] = $type;
135
+ if (isset($type['hide_fields'])) {
136
+ $_hiddenFields[$type['value']] = $type['hide_fields'];
137
+ }
138
+ if (isset($type['disabled_types'])) {
139
+ $_disabledTypes[$type['value']] = $type['disabled_types'];
140
+ }
141
+ }
142
+ Mage::register('attribute_type_hidden_fields', $_hiddenFields);
143
+ Mage::register('attribute_type_disabled_types', $_disabledTypes);
144
+
145
+
146
+ $fieldset->addField('frontend_input', 'select', array(
147
+ 'name' => 'frontend_input',
148
+ 'label' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'),
149
+ 'title' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'),
150
+ 'value' => 'text',
151
+ 'values'=> $inputTypes
152
+ ));
153
+
154
+ $fieldset->addField('default_value_text', 'text', array(
155
+ 'name' => 'default_value_text',
156
+ 'label' => Mage::helper('catalog')->__('Default value'),
157
+ 'title' => Mage::helper('catalog')->__('Default value'),
158
+ 'value' => $model->getDefaultValue(),
159
+ ));
160
+
161
+ $fieldset->addField('default_value_yesno', 'select', array(
162
+ 'name' => 'default_value_yesno',
163
+ 'label' => Mage::helper('catalog')->__('Default value'),
164
+ 'title' => Mage::helper('catalog')->__('Default value'),
165
+ 'values' => $yesno,
166
+ 'value' => $model->getDefaultValue(),
167
+ ));
168
+
169
+ $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
170
+ $fieldset->addField('default_value_date', 'date', array(
171
+ 'name' => 'default_value_date',
172
+ 'label' => Mage::helper('catalog')->__('Default value'),
173
+ 'title' => Mage::helper('catalog')->__('Default value'),
174
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
175
+ 'value' => $model->getDefaultValue(),
176
+ 'format' => $dateFormatIso
177
+ ));
178
+
179
+ $fieldset->addField('default_value_textarea', 'textarea', array(
180
+ 'name' => 'default_value_textarea',
181
+ 'label' => Mage::helper('catalog')->__('Default value'),
182
+ 'title' => Mage::helper('catalog')->__('Default value'),
183
+ 'value' => $model->getDefaultValue(),
184
+ ));
185
+
186
+ $fieldset->addField('is_unique', 'select', array(
187
+ 'name' => 'is_unique',
188
+ 'label' => Mage::helper('catalog')->__('Unique Value'),
189
+ 'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'),
190
+ 'note' => Mage::helper('catalog')->__('Not shared with other products'),
191
+ 'values' => $yesno,
192
+ ));
193
+
194
+ $fieldset->addField('is_required', 'select', array(
195
+ 'name' => 'is_required',
196
+ 'label' => Mage::helper('catalog')->__('Values Required'),
197
+ 'title' => Mage::helper('catalog')->__('Values Required'),
198
+ 'values' => $yesno,
199
+ ));
200
+
201
+ $fieldset->addField('frontend_class', 'select', array(
202
+ 'name' => 'frontend_class',
203
+ 'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'),
204
+ 'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'),
205
+ 'values'=> array(
206
+ array(
207
+ 'value' => '',
208
+ 'label' => Mage::helper('catalog')->__('None')
209
+ ),
210
+ array(
211
+ 'value' => 'validate-number',
212
+ 'label' => Mage::helper('catalog')->__('Decimal Number')
213
+ ),
214
+ array(
215
+ 'value' => 'validate-digits',
216
+ 'label' => Mage::helper('catalog')->__('Integer Number')
217
+ ),
218
+ array(
219
+ 'value' => 'validate-email',
220
+ 'label' => Mage::helper('catalog')->__('Email')
221
+ ),
222
+ array(
223
+ 'value' => 'validate-url',
224
+ 'label' => Mage::helper('catalog')->__('Url')
225
+ ),
226
+ array(
227
+ 'value' => 'validate-alpha',
228
+ 'label' => Mage::helper('catalog')->__('Letters')
229
+ ),
230
+ array(
231
+ 'value' => 'validate-alphanum',
232
+ 'label' => Mage::helper('catalog')->__('Letters(a-zA-Z) or Numbers(0-9)')
233
+ ),
234
+ )
235
+ ));
236
+ /*
237
+ $fieldset->addField('use_in_super_product', 'select', array(
238
+ 'name' => 'use_in_super_product',
239
+ 'label' => Mage::helper('catalog')->__('Apply To Configurable/Grouped Product'),
240
+ 'values' => $yesno,
241
+ )); */
242
+
243
+ $fieldset->addField('apply_to', 'apply', array(
244
+ 'name' => 'apply_to[]',
245
+ 'label' => Mage::helper('catalog')->__('Apply To'),
246
+ 'values' => Mage_Catalog_Model_Product_Type::getOptions(),
247
+ 'mode_labels' => array(
248
+ 'all' => Mage::helper('catalog')->__('All Product Types'),
249
+ 'custom' => Mage::helper('catalog')->__('Selected Product Types')
250
+ ),
251
+ 'required' => true
252
+ ));
253
+
254
+ $fieldset->addField('is_configurable', 'select', array(
255
+ 'name' => 'is_configurable',
256
+ 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'),
257
+ 'values' => $yesno,
258
+ ));
259
+ // -----
260
+
261
+
262
+ // frontend properties fieldset
263
+ $fieldset = $form->addFieldset('front_fieldset', array('legend'=>Mage::helper('catalog')->__('Frontend Properties')));
264
+
265
+ $fieldset->addField('is_searchable', 'select', array(
266
+ 'name' => 'is_searchable',
267
+ 'label' => Mage::helper('catalog')->__('Use in quick search'),
268
+ 'title' => Mage::helper('catalog')->__('Use in quick search'),
269
+ 'values' => $yesno,
270
+ ));
271
+
272
+ $fieldset->addField('is_visible_in_advanced_search', 'select', array(
273
+ 'name' => 'is_visible_in_advanced_search',
274
+ 'label' => Mage::helper('catalog')->__('Use in advanced search'),
275
+ 'title' => Mage::helper('catalog')->__('Use in advanced search'),
276
+ 'values' => $yesno,
277
+ ));
278
+
279
+ $fieldset->addField('is_comparable', 'select', array(
280
+ 'name' => 'is_comparable',
281
+ 'label' => Mage::helper('catalog')->__('Comparable on Front-end'),
282
+ 'title' => Mage::helper('catalog')->__('Comparable on Front-end'),
283
+ 'values' => $yesno,
284
+ ));
285
+
286
+
287
+ $fieldset->addField('is_filterable', 'select', array(
288
+ 'name' => 'is_filterable',
289
+ 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"),
290
+ 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
291
+ 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
292
+ 'values' => array(
293
+ array('value' => '0', 'label' => Mage::helper('catalog')->__('No')),
294
+ array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')),
295
+ array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)')),
296
+ ),
297
+ ));
298
+
299
+ $fieldset->addField('is_filterable_in_search', 'select', array(
300
+ 'name' => 'is_filterable_in_search',
301
+ 'label' => Mage::helper('catalog')->__("Use In Search Results Layered Navigation"),
302
+ 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
303
+ 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
304
+ 'values' => $yesno,
305
+ ));
306
+
307
+ $fieldset->addField('is_used_for_price_rules', 'select', array(
308
+ 'name' => 'is_used_for_price_rules',
309
+ 'label' => Mage::helper('catalog')->__('Use for Price Rule Conditions'),
310
+ 'title' => Mage::helper('catalog')->__('Use for Price Rule Conditions'),
311
+ 'values' => $yesno,
312
+ ));
313
+
314
+ $fieldset->addField('position', 'text', array(
315
+ 'name' => 'position',
316
+ 'label' => Mage::helper('catalog')->__('Position'),
317
+ 'title' => Mage::helper('catalog')->__('Position In Layered Navigation'),
318
+ 'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'),
319
+ 'class' => 'validate-digits',
320
+ ));
321
+
322
+ $htmlAllowed = $fieldset->addField('is_html_allowed_on_front', 'select', array(
323
+ 'name' => 'is_html_allowed_on_front',
324
+ 'label' => Mage::helper('catalog')->__('Allow HTML-tags on Front-end'),
325
+ 'title' => Mage::helper('catalog')->__('Allow HTML-tags on Front-end'),
326
+ 'values' => $yesno,
327
+ ));
328
+ if (!$model->getId()) {
329
+ $htmlAllowed->setValue(1);
330
+ }
331
+
332
+ $fieldset->addField('is_visible_on_front', 'select', array(
333
+ 'name' => 'is_visible_on_front',
334
+ 'label' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'),
335
+ 'title' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'),
336
+ 'values' => $yesno,
337
+ ));
338
+
339
+ $fieldset->addField('used_in_product_listing', 'select', array(
340
+ 'name' => 'used_in_product_listing',
341
+ 'label' => Mage::helper('catalog')->__('Used in product listing'),
342
+ 'title' => Mage::helper('catalog')->__('Used in product listing'),
343
+ 'note' => Mage::helper('catalog')->__('Depends on design theme'),
344
+ 'values' => $yesno,
345
+ ));
346
+ $fieldset->addField('used_for_sort_by', 'select', array(
347
+ 'name' => 'used_for_sort_by',
348
+ 'label' => Mage::helper('catalog')->__('Used for sorting in product listing'),
349
+ 'title' => Mage::helper('catalog')->__('Used for sorting in product listing'),
350
+ 'note' => Mage::helper('catalog')->__('Depends on design theme'),
351
+ 'values' => $yesno,
352
+ ));
353
+
354
+ if ($model->getId()) {
355
+ $form->getElement('attribute_code')->setDisabled(1);
356
+ $form->getElement('frontend_input')->setDisabled(1);
357
+
358
+ if (isset($disableAttributeFields[$model->getAttributeCode()])) {
359
+ foreach ($disableAttributeFields[$model->getAttributeCode()] as $field) {
360
+ $form->getElement($field)->setDisabled(1);
361
+ }
362
+ }
363
+ }
364
+ if (!$model->getIsUserDefined() && $model->getId()) {
365
+ $form->getElement('is_unique')->setDisabled(1);
366
+ }
367
+
368
+ $form->addValues($model->getData());
369
+
370
+ $form->getElement('apply_to')->setSize(5);
371
+
372
+ if ($applyTo = $model->getApplyTo()) {
373
+ $applyTo = is_array($applyTo) ? $applyTo : explode(',', $applyTo);
374
+ $form->getElement('apply_to')->setValue($applyTo);
375
+ } else {
376
+ $form->getElement('apply_to')->addClass('no-display ignore-validate');
377
+ }
378
+
379
+ $this->setForm($form);
380
+
381
+ /* MT start
382
+ return parent::_prepareForm();
383
+ */
384
+ }
385
+
386
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Block/Adminhtml/Catalog/Product/Attribute/Edit/Tab/Options.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Block_Adminhtml_Catalog_Product_Attribute_Edit_Tab_Options extends Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options
12
+ {
13
+
14
+ public function getOptionValues()
15
+ {
16
+ $attributeType = $this->getAttributeObject()->getFrontendInput();
17
+ $defaultValues = $this->getAttributeObject()->getDefaultValue();
18
+ /* MT start
19
+ if ($attributeType == 'select' || $attributeType == 'multiselect') {
20
+ */
21
+ if ($attributeType == 'select' || $attributeType == 'textfilter' || $attributeType == 'multiselect') {
22
+ /* MT end */
23
+ $defaultValues = explode(',', $defaultValues);
24
+ } else {
25
+ $defaultValues = array();
26
+ }
27
+
28
+ switch ($attributeType) {
29
+ case 'select':
30
+ /* MT add */
31
+ case 'textfilter':
32
+ /* MT end */
33
+ $inputType = 'radio';
34
+ break;
35
+ case 'multiselect':
36
+ $inputType = 'checkbox';
37
+ break;
38
+ default:
39
+ $inputType = '';
40
+ break;
41
+ }
42
+
43
+ $values = $this->getData('option_values');
44
+ if (is_null($values)) {
45
+ $values = array();
46
+ $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
47
+ ->setAttributeFilter($this->getAttributeObject()->getId())
48
+ ->setPositionOrder('desc', true)
49
+ ->load();
50
+
51
+ foreach ($optionCollection as $option) {
52
+ $value = array();
53
+ if (in_array($option->getId(), $defaultValues)) {
54
+ $value['checked'] = 'checked="checked"';
55
+ } else {
56
+ $value['checked'] = '';
57
+ }
58
+
59
+ $value['intype'] = $inputType;
60
+ $value['id'] = $option->getId();
61
+ $value['sort_order'] = $option->getSortOrder();
62
+ foreach ($this->getStores() as $store) {
63
+ $storeValues = $this->getStoreOptionValues($store->getId());
64
+ if (isset($storeValues[$option->getId()])) {
65
+ $value['store'.$store->getId()] = htmlspecialchars($storeValues[$option->getId()]);
66
+ }
67
+ else {
68
+ $value['store'.$store->getId()] = '';
69
+ }
70
+ }
71
+ $values[] = new Varien_Object($value);
72
+ }
73
+ $this->setData('option_values', $values);
74
+ }
75
+
76
+ return $values;
77
+ }
78
+
79
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes
12
+ {
13
+ protected function _setFieldset($attributes, $fieldset, $exclude=array())
14
+ {
15
+ $this->_addElementTypes($fieldset);
16
+ foreach ($attributes as $attribute) {
17
+ /* @var $attribute Mage_Eav_Model_Entity_Attribute */
18
+ if (!$attribute || !$attribute->getIsVisible()) {
19
+ continue;
20
+ }
21
+ if ( ($inputType = $attribute->getFrontend()->getInputType())
22
+ && !in_array($attribute->getAttributeCode(), $exclude)
23
+ && ('media_image' != $inputType)
24
+ ) {
25
+
26
+ $fieldType = $inputType;
27
+ $rendererClass = $attribute->getFrontend()->getInputRendererClass();
28
+ if (!empty($rendererClass)) {
29
+ $fieldType = $inputType . '_' . $attribute->getAttributeCode();
30
+ $fieldset->addType($fieldType, $rendererClass);
31
+ }
32
+
33
+ $element = $fieldset->addField($attribute->getAttributeCode(), $fieldType,
34
+ array(
35
+ 'name' => $attribute->getAttributeCode(),
36
+ 'label' => __($attribute->getFrontend()->getLabel()),
37
+ 'class' => $attribute->getFrontend()->getClass(),
38
+ 'required' => $attribute->getIsRequired(),
39
+ 'note' => $attribute->getNote(),
40
+ )
41
+ )
42
+ ->setEntityAttribute($attribute);
43
+
44
+ $element->setAfterElementHtml($this->_getAdditionalElementHtml($element));
45
+
46
+ /* MT start
47
+ if ($inputType == 'select' || $inputType == 'multiselect') {
48
+ */
49
+ if ($inputType == 'select' || $inputType == 'multiselect' || $inputType == 'textfilter') {
50
+ /* MT end */
51
+ $element->setValues($attribute->getSource()->getAllOptions(true, true));
52
+ } elseif ($inputType == 'date') {
53
+ $element->setImage($this->getSkinUrl('images/grid-cal.gif'));
54
+ $element->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Block/Catalog/Product/Compare/List.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Block_Catalog_Product_Compare_List extends Mage_Catalog_Block_Product_Compare_List
12
+ {
13
+
14
+ public function getProductAttributeValue($product, $attribute)
15
+ {
16
+ if (!$product->hasData($attribute->getAttributeCode())) {
17
+ return '&nbsp;';
18
+ }
19
+
20
+ /* MT start
21
+ if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('select','boolean','multiselect'))) {
22
+ */
23
+ if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('select','textfilter','boolean','multiselect'))) {
24
+ /* MT end */
25
+ //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode()));
26
+ $value = $attribute->getFrontend()->getValue($product);
27
+ }
28
+ else {
29
+ $value = $product->getData($attribute->getAttributeCode());
30
+ }
31
+ return $value ? $value : '&nbsp;';
32
+ }
33
+
34
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Block/CatalogSearch/Advanced/Form.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Block_CatalogSearch_Advanced_Form extends Mage_CatalogSearch_Block_Advanced_Form
12
+ {
13
+
14
+ public function getAttributeInputType($attribute)
15
+ {
16
+ $dataType = $attribute->getBackend()->getType();
17
+ $imputType = $attribute->getFrontend()->getInputType();
18
+ /* MT start
19
+ if ($imputType == 'select' || $imputType == 'multiselect') {
20
+ */
21
+ if ($imputType == 'select' || $imputType == 'textfilter' || $imputType == 'multiselect') {
22
+ /* MT end */
23
+ return 'select';
24
+ }
25
+
26
+ if ($imputType == 'boolean') {
27
+ return 'yesno';
28
+ }
29
+
30
+ if ($imputType == 'price') {
31
+ return 'price';
32
+ }
33
+
34
+ if ($dataType == 'int' || $dataType == 'decimal') {
35
+ return 'number';
36
+ }
37
+
38
+ if ($dataType == 'datetime') {
39
+ return 'date';
40
+ }
41
+
42
+ return 'string';
43
+ }
44
+
45
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/Catalog/Entity/Attribute.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_Catalog_Entity_Attribute extends Mage_Catalog_Model_Entity_Attribute
12
+ {
13
+ public function getBackendTypeByInput($type)
14
+ {
15
+ switch ($type) {
16
+ case 'text':
17
+ case 'gallery':
18
+ case 'media_image':
19
+ case 'multiselect':
20
+ return 'varchar';
21
+
22
+ case 'image':
23
+ case 'textarea':
24
+ return 'text';
25
+
26
+ case 'date':
27
+ return 'datetime';
28
+
29
+ case 'select':
30
+ /* MT start */
31
+ case 'textfilter':
32
+ /* MT end */
33
+ case 'boolean':
34
+ return 'int';
35
+
36
+
37
+ case 'price':
38
+ return 'decimal';
39
+ /*
40
+ default:
41
+ Mage::dispatchEvent('eav_attribute_get_backend_type_by_input', array('model'=>$this, 'type'=>$type));
42
+ if ($this->hasBackendTypeByInput()) {
43
+ return $this->getData('backend_type_by_input');
44
+ }
45
+ Mage::throwException('Unknown frontend input type');
46
+ */
47
+ }
48
+ }
49
+
50
+ public function getDefaultValueByInput($type)
51
+ {
52
+ $field = '';
53
+ switch ($type) {
54
+ case 'select':
55
+ /* MT start */
56
+ case 'textfilter':
57
+ /* MT end */
58
+ case 'gallery':
59
+ case 'media_image':
60
+ case 'multiselect':
61
+ return '';
62
+
63
+ case 'text':
64
+ case 'price':
65
+ case 'image':
66
+ $field = 'default_value_text';
67
+ break;
68
+
69
+ case 'textarea':
70
+ $field = 'default_value_textarea';
71
+ break;
72
+
73
+ case 'date':
74
+ $field = 'default_value_date';
75
+ break;
76
+
77
+ case 'boolean':
78
+ $field = 'default_value_yesno';
79
+ break;
80
+ /*
81
+ default:
82
+ Mage::dispatchEvent('eav_attribute_get_default_value_by_input', array('model'=>$this, 'type'=>$type));
83
+ if ($this->hasBackendTypeByInput()) {
84
+ return $this->getData('backend_type_by_input');
85
+ }
86
+ Mage::throwException('Unknown frontend input type');
87
+ */
88
+ }
89
+
90
+ return $field;
91
+ }
92
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/Catalog/Resource/Eav/Attribute.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_Catalog_Resource_Eav_Attribute extends Mage_Catalog_Model_Resource_Eav_Attribute
12
+ {
13
+
14
+ public function getSourceModel()
15
+ {
16
+ $model = $this->getData('source_model');
17
+ if (empty($model)) {
18
+ /* MT start
19
+ if ($this->getBackendType() == 'int' && $this->getFrontendInput() == 'select') {
20
+ */
21
+ if ($this->getBackendType() == 'int' && ($this->getFrontendInput() == 'select' || $this->getFrontendInput() == 'textfilter')) {
22
+ /* MT end */
23
+ return 'eav/entity_attribute_source_table';
24
+ }
25
+ }
26
+ return $model;
27
+ }
28
+
29
+ public function isAllowedForRuleCondition()
30
+ {
31
+ /* MT start
32
+ $allowedInputTypes = array('text', 'multiselect', 'textarea', 'date', 'datetime', 'select', 'boolean', 'price');
33
+ */
34
+ $allowedInputTypes = array('text', 'multiselect', 'textarea', 'date', 'datetime', 'select', 'textfilter', 'boolean', 'price');
35
+ /* MT end */
36
+ return $this->getIsVisible() && in_array($this->getFrontendInput(), $allowedInputTypes);
37
+ }
38
+
39
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/Catalog/Resource/Eav/Mysql4/Product.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_Catalog_Resource_Eav_Mysql4_Product extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product
12
+ {
13
+
14
+ protected function _processSaveData($saveData)
15
+ {
16
+ extract($saveData);
17
+ $insertEntity = true;
18
+ $entityIdField = $this->getEntityIdField();
19
+ $entityId = $newObject->getId();
20
+ $condition = $this->_getWriteAdapter()->quoteInto("$entityIdField=?", $entityId);
21
+
22
+ if (!empty($entityId)) {
23
+ $select = $this->_getWriteAdapter()->select()
24
+ ->from($this->getEntityTable(), $entityIdField)
25
+ ->where($condition);
26
+ if ($this->_getWriteAdapter()->fetchOne($select)) {
27
+ $insertEntity = false;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Process base row
33
+ */
34
+ if ($insertEntity) {
35
+ $this->_getWriteAdapter()->insert($this->getEntityTable(), $entityRow);
36
+ $entityId = $this->_getWriteAdapter()->lastInsertId();
37
+ $newObject->setId($entityId);
38
+ } else {
39
+ $this->_getWriteAdapter()->update($this->getEntityTable(), $entityRow, $condition);
40
+ }
41
+
42
+ /**
43
+ * insert attribute values
44
+ */
45
+ if (!empty($insert)) {
46
+ foreach ($insert as $attrId=>$value) {
47
+ $attribute = $this->getAttribute($attrId);
48
+
49
+ /* MT start */
50
+ if ($attribute->frontend_input == 'textfilter') {
51
+ $value = $this->_mtGetValue($attribute, $value);
52
+ }
53
+ /* MT end */
54
+
55
+ $this->_insertAttribute($newObject, $attribute, $value);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * update attribute values
61
+ */
62
+ if (!empty($update)) {
63
+ foreach ($update as $attrId=>$v) {
64
+ $attribute = $this->getAttribute($attrId);
65
+
66
+ /* MT start */
67
+ if ($attribute->frontend_input == 'textfilter') {
68
+ $v['value'] = $this->_mtGetValue($attribute, $v['value']);
69
+ }
70
+ /* MT end */
71
+
72
+ $this->_updateAttribute($newObject, $attribute, $v['value_id'], $v['value']);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * delete empty attribute values
78
+ */
79
+ if (!empty($delete)) {
80
+ foreach ($delete as $table=>$values) {
81
+ $this->_deleteAttributes($newObject, $table, $values);
82
+ }
83
+ }
84
+
85
+ return $this;
86
+ }
87
+
88
+ protected function _mtGetValue($attribute, $value)
89
+ {
90
+
91
+ $writeFilter = Mage::getSingleton('core/resource')->getConnection('core_write');
92
+ $eav_attribute = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
93
+ $eav_attribute_option_value = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
94
+ $eav_attribute_option = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option');
95
+ $textFilterResult = $writeFilter->query("select o.option_id from ".$eav_attribute." a, ".$eav_attribute_option_value." v, ".$eav_attribute_option." o
96
+ where a.attribute_id='".$attribute->attribute_id."'
97
+ and a.attribute_id=o.attribute_id
98
+ and o.option_id=v.option_id
99
+ and v.value='".$value."'");
100
+
101
+ $filterOptionId = 0; $i=0;
102
+ while ($rowFilter = $textFilterResult->fetch()) {
103
+ $filterOptionId=$rowFilter['option_id'];
104
+ $i++;
105
+ }
106
+
107
+ if ($i==0) { // new option: add & return option_id as $filterOptionId
108
+
109
+ $stores = Mage::getModel('core/store')
110
+ ->getResourceCollection()
111
+ ->setLoadDefault(true)
112
+ ->load();
113
+
114
+ $write = $this->_getWriteAdapter();
115
+ $data = array(
116
+ 'attribute_id' => $attribute->attribute_id,
117
+ 'sort_order' => 0,
118
+ );
119
+ $write->insert($eav_attribute_option, $data);
120
+
121
+ $filterOptionId = $write->lastInsertId();
122
+
123
+ foreach ($stores as $store) {
124
+ $data = array(
125
+ 'option_id' => $filterOptionId,
126
+ 'store_id' => $store->getId(),
127
+ 'value' => $value,
128
+ );
129
+ $write->insert($eav_attribute_option_value, $data);
130
+ }
131
+
132
+ }
133
+
134
+ // set option ID
135
+ return $filterOptionId;
136
+ }
137
+
138
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/CatalogIndex/Indexer/Eav.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_CatalogIndex_Indexer_Eav extends Mage_CatalogIndex_Model_Indexer_Eav
12
+ {
13
+
14
+ protected function _isAttributeIndexable(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
15
+ {
16
+ if ($attribute->getIsFilterable() == 0 && $attribute->getIsVisibleInAdvancedSearch() == 0) {
17
+ return false;
18
+ }
19
+ /* MT start
20
+ if ($attribute->getFrontendInput() != 'select' && $attribute->getFrontendInput() != 'multiselect') {
21
+ */
22
+ if ($attribute->getFrontendInput() != 'select' && $attribute->getFrontendInput() != 'textfilter' && $attribute->getFrontendInput() != 'multiselect') {
23
+ /* MT end */
24
+ return false;
25
+ }
26
+
27
+ return true;
28
+ }
29
+
30
+ protected function _getIndexableAttributeConditions()
31
+ {
32
+ /* MT start
33
+ $conditions = "frontend_input IN ('select', 'multiselect') AND (is_filterable IN (1, 2) OR is_visible_in_advanced_search = 1)";
34
+ */
35
+ $conditions = "frontend_input IN ('select', 'textfilter', 'multiselect') AND (is_filterable IN (1, 2) OR is_visible_in_advanced_search = 1)";
36
+ /* MT end */
37
+ return $conditions;
38
+
39
+ $conditions = array();
40
+ /* MT start
41
+ $conditions['frontend_input'] = array('select', 'multiselect');
42
+ */
43
+ $conditions['frontend_input'] = array('select', 'textfilter', 'multiselect');
44
+ /* MT end */
45
+ $conditions['or']['is_filterable'] = array(1, 2);
46
+ $conditions['or']['is_visible_in_advanced_search'] = 1;
47
+ }
48
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/CatalogRule/Rule/Condition/Product.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_CatalogRule_Rule_Condition_Product extends Mage_CatalogRule_Model_Rule_Condition_Product
12
+ {
13
+
14
+ public function getValueElementType()
15
+ {
16
+ if ($this->getAttribute()==='attribute_set_id') {
17
+ return 'select';
18
+ }
19
+ if (!is_object($this->getAttributeObject())) {
20
+ return 'text';
21
+ }
22
+ switch ($this->getAttributeObject()->getFrontendInput()) {
23
+ case 'select':
24
+ return 'select';
25
+
26
+ /* MT start */
27
+ case 'textfilter':
28
+ return 'textfilter';
29
+ /* MT end */
30
+
31
+ case 'multiselect':
32
+ return 'multiselect';
33
+
34
+ case 'date':
35
+ return 'date';
36
+
37
+ default:
38
+ return 'text';
39
+ }
40
+ }
41
+
42
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/CatalogSearch/Advanced.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_CatalogSearch_Advanced extends Mage_CatalogSearch_Model_Advanced
12
+ {
13
+
14
+ protected function _addSearchCriteria($attribute, $value)
15
+ {
16
+ $name = $attribute->getFrontend()->getLabel();
17
+
18
+ if (is_array($value) && (isset($value['from']) || isset($value['to']))){
19
+ if (isset($value['currency'])) {
20
+ $currencyModel = Mage::getModel('directory/currency')->load($value['currency']);
21
+ $from = $currencyModel->format($value['from'], array(), false);
22
+ $to = $currencyModel->format($value['to'], array(), false);
23
+ } else {
24
+ $currencyModel = null;
25
+ }
26
+
27
+ if (strlen($value['from']) > 0 && strlen($value['to']) > 0) {
28
+ // -
29
+ $value = sprintf('%s - %s', ($currencyModel ? $from : $value['from']), ($currencyModel ? $to : $value['to']));
30
+ } elseif (strlen($value['from']) > 0) {
31
+ // and more
32
+ $value = Mage::helper('catalogsearch')->__('%s and greater', ($currencyModel ? $from : $value['from']));
33
+ } elseif (strlen($value['to']) > 0) {
34
+ // to
35
+ $value = Mage::helper('catalogsearch')->__('up to %s', ($currencyModel ? $to : $value['to']));
36
+ }
37
+ }
38
+
39
+ /* MT start
40
+ if (($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') && is_array($value)) {
41
+ */
42
+ if (($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'textfilter' || $attribute->getFrontendInput() == 'multiselect') && is_array($value)) {
43
+ /* MT end */
44
+ foreach ($value as $k=>$v){
45
+ $value[$k] = $attribute->getSource()->getOptionText($v);
46
+
47
+ if (is_array($value[$k]))
48
+ $value[$k] = $value[$k]['label'];
49
+ }
50
+ $value = implode(', ', $value);
51
+ /* MT start
52
+ } else if ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') {
53
+ */
54
+ } else if ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'textfilter' || $attribute->getFrontendInput() == 'multiselect') {
55
+ /* MT end */
56
+ $value = $attribute->getSource()->getOptionText($value);
57
+ if (is_array($value))
58
+ $value = $value['label'];
59
+ } else if ($attribute->getFrontendInput() == 'boolean') {
60
+ $value = $value == 1
61
+ ? Mage::helper('catalogsearch')->__('Yes')
62
+ : Mage::helper('catalogsearch')->__('No');
63
+ }
64
+
65
+ $searchCriterias = $this->_searchCriterias;
66
+ $searchCriterias[] = array('name'=>$name, 'value'=>$value);
67
+ return $searchCriterias;
68
+ }
69
+
70
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/CatalogSearch/Mysql4/Search/Collection.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_CatalogSearch_Mysql4_Search_Collection
12
+ extends Mage_CatalogSearch_Model_Mysql4_Search_Collection
13
+ {
14
+
15
+ protected function _isAttributeTextAndSearchable($attribute)
16
+ {
17
+ /* MT start
18
+ if (($attribute->getIsSearchable() && !in_array($attribute->getFrontendInput(), array('select', 'multiselect')))
19
+ */
20
+ if (($attribute->getIsSearchable() && !in_array($attribute->getFrontendInput(), array('select', 'textfilter', 'multiselect')))
21
+ /* MT end */
22
+ && (in_array($attribute->getBackendType(), array('varchar', 'text')) || $attribute->getBackendType() == 'static')) {
23
+ return true;
24
+ }
25
+ return false;
26
+ }
27
+
28
+ protected function _hasAttributeOptionsAndSearchable($attribute)
29
+ {
30
+ /* MT start
31
+ if ($attribute->getIsSearchable() && in_array($attribute->getFrontendInput(), array('select', 'multiselect'))) {
32
+ */
33
+ if ($attribute->getIsSearchable() && in_array($attribute->getFrontendInput(), array('select', 'textfilter', 'multiselect'))) {
34
+ /* MT end */
35
+ return true;
36
+ }
37
+
38
+ return false;
39
+ }
40
+
41
+ protected function _getSearchInOptionSql($query)
42
+ {
43
+ $attributeIds = array();
44
+ $attributeTables = array();
45
+ $storeId = (int)$this->getStoreId();
46
+
47
+ /**
48
+ * Collect attributes with options
49
+ */
50
+ foreach ($this->_getAttributesCollection() as $attribute) {
51
+ if ($this->_hasAttributeOptionsAndSearchable($attribute)) {
52
+ $attributeTables[$attribute->getFrontendInput()] = $attribute->getBackend()->getTable();
53
+ $attributeIds[] = $attribute->getId();
54
+ }
55
+ }
56
+ if (empty($attributeIds)) {
57
+ return false;
58
+ }
59
+
60
+ $resource = Mage::getSingleton('core/resource');
61
+ $optionTable = $resource->getTableName('eav/attribute_option');
62
+ $optionValueTable = $resource->getTableName('eav/attribute_option_value');
63
+ $attributesTable = $resource->getTableName('eav/attribute');
64
+
65
+ /**
66
+ * Select option Ids
67
+ */
68
+ $select = $this->getConnection()->select()
69
+ ->from(array('default'=>$optionValueTable), array('option_id','option.attribute_id', 'store_id'=>'IFNULL(store.store_id, default.store_id)', 'a.frontend_input'))
70
+ ->joinLeft(array('store'=>$optionValueTable),
71
+ $this->getConnection()->quoteInto('store.option_id=default.option_id AND store.store_id=?', $storeId),
72
+ array())
73
+ ->join(array('option'=>$optionTable),
74
+ 'option.option_id=default.option_id',
75
+ array())
76
+ ->join(array('a' => $attributesTable), 'option.attribute_id=a.attribute_id', array())
77
+ ->where('default.store_id=0')
78
+ ->where('option.attribute_id IN (?)', $attributeIds)
79
+ ->where('IFNULL(store.value, default.value) LIKE :search_query');
80
+ $options = $this->getConnection()->fetchAll($select, array('search_query'=>$this->_searchQuery));
81
+ if (empty($options)) {
82
+ return false;
83
+ }
84
+
85
+ // build selects of entity ids for specified options ids by frontend input
86
+ $select = array();
87
+ foreach (array(
88
+ 'select' => 'value = %d',
89
+ /* MT start */
90
+ 'textfilter' => 'value = %d',
91
+ /* MT end */
92
+ 'multiselect' => 'FIND_IN_SET(%d, value)')
93
+ as $frontendInput => $condition) {
94
+ if (isset($attributeTables[$frontendInput])) {
95
+ $where = array();
96
+ foreach ($options as $option) {
97
+ if ($frontendInput === $option['frontend_input']) {
98
+ $where[] = sprintf("attribute_id=%d AND store_id=%d AND {$condition}", $option['attribute_id'], $option['store_id'], $option['option_id']);
99
+ }
100
+ }
101
+ if ($where) {
102
+ $select[$frontendInput] = (string)$this->getConnection()->select()
103
+ ->from($attributeTables[$frontendInput], 'entity_id')
104
+ ->where(implode(' OR ', $where));
105
+ }
106
+ }
107
+ }
108
+
109
+ // search in catalogindex for products as part of configurable/grouped/bundle products (current store)
110
+ $where = array();
111
+ foreach ($options as $option) {
112
+ $where[] = sprintf('attribute_id=%d AND value=%d', $option['attribute_id'], $option['option_id']);
113
+ }
114
+ if ($where) {
115
+ $select[] = (string)$this->getConnection()->select()
116
+ ->from($resource->getTableName('catalogindex/eav'), 'entity_id')
117
+ ->where(implode(' OR ', $where))
118
+ ->where("store_id={$storeId}");
119
+ }
120
+
121
+ return implode(' UNION ', $select);
122
+ }
123
+
124
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/Eav/Entity/Attribute.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_Eav_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute
12
+ {
13
+
14
+ public function usesSource()
15
+ {
16
+ /* MT start
17
+ return $this->getFrontendInput()==='select' || $this->getFrontendInput()==='multiselect';
18
+ */
19
+ return $this->getFrontendInput()==='select' || $this->getFrontendInput()==='multiselect' || $this->getFrontendInput()==='textfilter';
20
+ /* MT end */
21
+ }
22
+
23
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/Eav/Entity/Attribute/Frontend/Default.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_Eav_Entity_Attribute_Frontend_Default extends Mage_Eav_Model_Entity_Attribute_Frontend_Default
12
+ {
13
+
14
+ public function getValue(Varien_Object $object)
15
+ {
16
+ $value = $object->getData($this->getAttribute()->getAttributeCode());
17
+ /* MT start
18
+ if (in_array($this->getConfigField('input'), array('select','boolean'))) {
19
+ */
20
+ if (in_array($this->getConfigField('input'), array('select','textfilter','boolean'))) {
21
+ /* MT end */
22
+ $valueOption = $this->getOption($value);
23
+ if (!$valueOption) {
24
+ $opt = new Mage_Eav_Model_Entity_Attribute_Source_Boolean();
25
+ if ($options = $opt->getAllOptions()) {
26
+ foreach ($options as $option) {
27
+ if ($option['value'] == $value) {
28
+ $valueOption = $option['label'];
29
+ }
30
+ }
31
+ }
32
+ }
33
+ $value = $valueOption;
34
+ }
35
+ elseif ($this->getConfigField('input')=='multiselect') {
36
+ $value = $this->getOption($value);
37
+ if (is_array($value)) {
38
+ $value = implode(', ', $value);
39
+ }
40
+ }
41
+ return $value;
42
+ }
43
+
44
+ }
app/code/community/Morningtime/TextfieldLayeredNav/Model/Eav/Mysql4/Entity/Attribute.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Morningtime
4
+ * TextfieldLayeredNav module
5
+ *
6
+ * @category Morningtime
7
+ * @package Morningtime_TextfieldLayeredNav
8
+ * @author Mathijs Koenraadt (info@morningtime.com)
9
+ */
10
+
11
+ class Morningtime_TextfieldLayeredNav_Model_Eav_Mysql4_Entity_Attribute extends Mage_Eav_Model_Mysql4_Entity_Attribute
12
+ {
13
+
14
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
15
+ {
16
+ $frontendLabel = $object->getFrontendLabel();
17
+ if (is_array($frontendLabel)) {
18
+ if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0]=='') {
19
+ Mage::throwException(Mage::helper('eav')->__('Frontend label is not defined'));
20
+ }
21
+ $object->setFrontendLabel($frontendLabel[0]);
22
+
23
+ if ($object->getData('modulePrefix')) {
24
+ $str = $object->getData('modulePrefix') . Mage_Core_Model_Translate::SCOPE_SEPARATOR . $frontendLabel[0];
25
+ }
26
+ else {
27
+ $str = $frontendLabel[0];
28
+ }
29
+ Mage::getModel('core/translate_string')
30
+ ->setString($str)
31
+ ->setTranslate($frontendLabel[0])
32
+ ->setStoreTranslations($frontendLabel)
33
+ ->save();
34
+ }
35
+ $applyTo = $object->getApplyTo();
36
+
37
+ if (is_array($applyTo)) {
38
+ $object->setApplyTo(implode(',', $applyTo));
39
+ }
40
+
41
+ /**
42
+ * @todo need use default source model of entity type !!!
43
+ */
44
+ if (!$object->getId()) {
45
+ /* MT start
46
+ if ($object->getFrontendInput()=='select') {
47
+ */
48
+ if ($object->getFrontendInput()=='select' || $object->getFrontendInput()=='textfilter') {
49
+ /* MT end */
50
+ $object->setSourceModel('eav/entity_attribute_source_table');
51
+ }
52
+
53
+
54
+ }
55
+
56
+ }
57
+
58
+ protected function _saveOption(Mage_Core_Model_Abstract $object)
59
+ {
60
+ $option = $object->getOption();
61
+ if (is_array($option)) {
62
+ $write = $this->_getWriteAdapter();
63
+ $optionTable = $this->getTable('attribute_option');
64
+ $optionValueTable = $this->getTable('attribute_option_value');
65
+ $stores = Mage::getModel('core/store')
66
+ ->getResourceCollection()
67
+ ->setLoadDefault(true)
68
+ ->load();
69
+
70
+ if (isset($option['value'])) {
71
+ $attributeDefaultValue = array();
72
+ if (!is_array($object->getDefault())) {
73
+ $object->setDefault(array());
74
+ }
75
+
76
+ foreach ($option['value'] as $optionId => $values) {
77
+ $intOptionId = (int) $optionId;
78
+ if (!empty($option['delete'][$optionId])) {
79
+ if ($intOptionId) {
80
+ $condition = $write->quoteInto('option_id=?', $intOptionId);
81
+ $write->delete($optionTable, $condition);
82
+ }
83
+
84
+ continue;
85
+ }
86
+
87
+ if (!$intOptionId) {
88
+ $data = array(
89
+ 'attribute_id' => $object->getId(),
90
+ 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0,
91
+ );
92
+ $write->insert($optionTable, $data);
93
+ $intOptionId = $write->lastInsertId();
94
+ }
95
+ else {
96
+ $data = array(
97
+ 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0,
98
+ );
99
+ $write->update($optionTable, $data, $write->quoteInto('option_id=?', $intOptionId));
100
+ }
101
+
102
+ if (in_array($optionId, $object->getDefault())) {
103
+ if ($object->getFrontendInput() == 'multiselect') {
104
+ $attributeDefaultValue[] = $intOptionId;
105
+ /* MT start
106
+ } else if ($object->getFrontendInput() == 'select') {
107
+ */
108
+ } else if ($object->getFrontendInput() == 'select' || $object->getFrontendInput() == 'textfilter') {
109
+ /* MT end */
110
+ $attributeDefaultValue = array($intOptionId);
111
+ }
112
+ }
113
+
114
+
115
+ // Default value
116
+ if (!isset($values[0])) {
117
+ Mage::throwException(Mage::helper('eav')->__('Default option value is not defined'));
118
+ }
119
+
120
+ $write->delete($optionValueTable, $write->quoteInto('option_id=?', $intOptionId));
121
+ foreach ($stores as $store) {
122
+ if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) {
123
+ $data = array(
124
+ 'option_id' => $intOptionId,
125
+ 'store_id' => $store->getId(),
126
+ 'value' => $values[$store->getId()],
127
+ );
128
+ $write->insert($optionValueTable, $data);
129
+ }
130
+ }
131
+ }
132
+
133
+ $write->update($this->getMainTable(), array(
134
+ 'default_value' => implode(',', $attributeDefaultValue)
135
+ ), $write->quoteInto($this->getIdFieldName() . '=?', $object->getId()));
136
+ }
137
+ }
138
+ return $this;
139
+ }
140
+
141
+ }
app/code/community/Morningtime/TextfieldLayeredNav/controllers/Adminhtml/Catalog/Product/AttributeController.php ADDED
@@ -0,0 +1,57 @@