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_CatalogIndex
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: * Index data retreiver factory
29: *
30: * @method Mage_CatalogIndex_Model_Resource_Retreiver _getResource()
31: * @method Mage_CatalogIndex_Model_Resource_Retreiver getResource()
32: * @method int getEntityTypeId()
33: * @method Mage_CatalogIndex_Model_Retreiver setEntityTypeId(int $value)
34: * @method int getAttributeSetId()
35: * @method Mage_CatalogIndex_Model_Retreiver setAttributeSetId(int $value)
36: * @method string getTypeId()
37: * @method Mage_CatalogIndex_Model_Retreiver setTypeId(string $value)
38: * @method string getSku()
39: * @method Mage_CatalogIndex_Model_Retreiver setSku(string $value)
40: * @method int getHasOptions()
41: * @method Mage_CatalogIndex_Model_Retreiver setHasOptions(int $value)
42: * @method int getRequiredOptions()
43: * @method Mage_CatalogIndex_Model_Retreiver setRequiredOptions(int $value)
44: * @method string getCreatedAt()
45: * @method Mage_CatalogIndex_Model_Retreiver setCreatedAt(string $value)
46: * @method string getUpdatedAt()
47: * @method Mage_CatalogIndex_Model_Retreiver setUpdatedAt(string $value)
48: *
49: * @category Mage
50: * @package Mage_CatalogIndex
51: * @author Magento Core Team <core@magentocommerce.com>
52: */
53: class Mage_CatalogIndex_Model_Retreiver extends Mage_Core_Model_Abstract
54: {
55: const CHILDREN_FOR_TIERS = 1;
56: const CHILDREN_FOR_PRICES = 2;
57: const CHILDREN_FOR_ATTRIBUTES = 3;
58:
59: protected $_attributeIdCache = array();
60:
61: /**
62: * Customer group cache
63: *
64: * @var Mage_Customer_Model_Mysql4_Group_Collection
65: */
66: protected $_customerGroups;
67:
68: /**
69: * Retreiver model names cache
70: *
71: * @var array
72: */
73: protected $_retreivers = array();
74:
75: /**
76: * Retreiver factory init, load retreiver settings
77: *
78: */
79: protected function _construct()
80: {
81: $config = Mage::getConfig()->getNode('global/catalog/product/type')->asArray();
82: foreach ($config as $type=>$data) {
83: if (isset($data['index_data_retreiver'])) {
84: $this->_retreivers[$type] = $data['index_data_retreiver'];
85: }
86: }
87:
88: $this->_init('catalogindex/retreiver');
89: }
90:
91: /**
92: * Returns data retreiver model by specified product type
93: *
94: * @param string $type
95: * @return Mage_CatalogIndex_Model_Data_Abstract
96: */
97: public function getRetreiver($type)
98: {
99: if (isset($this->_retreivers[$type])) {
100: return Mage::getSingleton($this->_retreivers[$type]);
101: } else {
102: Mage::throwException("Data retreiver for '{$type}' is not defined");
103: }
104: }
105:
106: /**
107: * Return customer group collection
108: *
109: * @return Mage_Customer_Model_Entity_Group_Collection
110: */
111: public function getCustomerGroups()
112: {
113: if (is_null($this->_customerGroups)) {
114: $this->_customerGroups = Mage::getModel('customer/group')->getCollection();
115: }
116: return $this->_customerGroups;
117: }
118:
119: /**
120: * Return product ids sorted by type
121: *
122: * @param array $products
123: * @return array
124: */
125: public function assignProductTypes($products)
126: {
127: $flat = $this->_getResource()->getProductTypes($products);
128: $result = array();
129: foreach ($flat as $one) {
130: $result[$one['type']][] = $one['id'];
131: }
132: return $result;
133: }
134: }
135: