1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_XmlConnect
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Filter collection
29: *
30: * @category Mage
31: * @package Mage_XmlConnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Model_Resource_Filter_Collection extends Varien_Data_Collection
35: {
36: /**
37: * Set CategoryId filter
38: *
39: * @param int $categoryId
40: * @return Mage_XmlConnect_Model_Resource_Filter_Collection
41: */
42: public function setCategoryId($categoryId)
43: {
44: if ((int)$categoryId > 0) {
45: $this->addFilter('category_id', $categoryId);
46: }
47: return $this;
48: }
49:
50: /**
51: * Load data
52: *
53: * @param bool $printQuery
54: * @param bool $logQuery
55: * @return Mage_XmlConnect_Model_Resource_Filter_Collection
56: */
57: public function load($printQuery = false, $logQuery = false)
58: {
59: if (empty($this->_items)) {
60: $layer = Mage::getSingleton('catalog/layer');
61: foreach ($this->_filters as $filter) {
62: if ('category_id' == $filter['field']) {
63: $layer->setCurrentCategory((int)$filter['value']);
64: }
65: }
66: if ($layer->getCurrentCategory()->getIsAnchor()) {
67: foreach ($layer->getFilterableAttributes() as $attributeItem) {
68: $filterModelName = 'catalog/layer_filter_attribute';
69: switch ($attributeItem->getAttributeCode()) {
70: case 'price':
71: $filterModelName = 'catalog/layer_filter_price';
72: break;
73: case 'decimal':
74: $filterModelName = 'catalog/layer_filter_decimal';
75: break;
76: default:
77: $filterModelName = 'catalog/layer_filter_attribute';
78: break;
79: }
80:
81: $filterModel = Mage::getModel($filterModelName);
82: $filterModel->setLayer($layer)->setAttributeModel($attributeItem);
83: $filterValues = new Varien_Data_Collection;
84: foreach ($filterModel->getItems() as $valueItem) {
85: $valueObject = new Varien_Object();
86: $valueObject->setLabel($valueItem->getLabel());
87: $valueObject->setValueString($valueItem->getValueString());
88: $valueObject->setProductsCount($valueItem->getCount());
89: $filterValues->addItem($valueObject);
90: }
91: $item = new Varien_Object;
92: $item->setCode($attributeItem->getAttributeCode());
93: $item->setName($filterModel->getName());
94: $item->setValues($filterValues);
95: $this->addItem($item);
96: }
97: }
98: }
99: return $this;
100: }
101: }
102: