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_Catalog
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: /**
29: * Catalog Product Flat Helper
30: *
31: * @category Mage
32: * @package Mage_Catalog
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Catalog_Helper_Product_Flat extends Mage_Core_Helper_Abstract
36: {
37: const XML_PATH_USE_PRODUCT_FLAT = 'catalog/frontend/flat_catalog_product';
38: const XML_NODE_ADD_FILTERABLE_ATTRIBUTES = 'global/catalog/product/flat/add_filterable_attributes';
39: const XML_NODE_ADD_CHILD_DATA = 'global/catalog/product/flat/add_child_data';
40:
41: /**
42: * Catalog Flat Product index process code
43: *
44: * @var string
45: */
46: const CATALOG_FLAT_PROCESS_CODE = 'catalog_product_flat';
47:
48: /**
49: * Catalog Product Flat index process
50: *
51: * @var Mage_Index_Model_Process
52: */
53: protected $_process;
54:
55: /**
56: * Catalog Product Flat status by store
57: *
58: * @var array
59: */
60: protected $_isEnabled = array();
61:
62: /**
63: * Catalog Product Flat Flag object
64: *
65: * @var Mage_Catalog_Model_Product_Flat_Flag
66: */
67: protected $_flagObject;
68:
69: /**
70: * Retrieve Catalog Product Flat Flag object
71: *
72: * @return Mage_Catalog_Model_Product_Flat_Flag
73: */
74: public function getFlag()
75: {
76: if (is_null($this->_flagObject)) {
77: $this->_flagObject = Mage::getSingleton('catalog/product_flat_flag')
78: ->loadSelf();
79: }
80: return $this->_flagObject;
81: }
82:
83: /**
84: * Check is builded Catalog Product Flat Data
85: *
86: * @return bool
87: */
88: public function isBuilt()
89: {
90: return $this->getFlag()->getIsBuilt();
91: }
92:
93: /**
94: * Check is enable catalog product for store
95: *
96: * @param mixed $store
97: * @return bool
98: */
99: public function isEnabled($store = null)
100: {
101: $store = Mage::app()->getStore($store);
102: if ($store->isAdmin()) {
103: return false;
104: }
105:
106: if (!isset($this->_isEnabled[$store->getId()])) {
107: if (Mage::getStoreConfigFlag(self::XML_PATH_USE_PRODUCT_FLAT, $store)) {
108: $this->_isEnabled[$store->getId()] = $this->getProcess()->getStatus() == Mage_Index_Model_Process::STATUS_PENDING;
109: } else {
110: $this->_isEnabled[$store->getId()] = false;
111: }
112: }
113: return $this->_isEnabled[$store->getId()];
114: }
115:
116: /**
117: * Is add filterable attributes to Flat table
118: *
119: * @return int
120: */
121: public function isAddFilterableAttributes()
122: {
123: return intval(Mage::getConfig()->getNode(self::XML_NODE_ADD_FILTERABLE_ATTRIBUTES));
124: }
125:
126: /**
127: * Is add child data to Flat
128: *
129: * @return int
130: */
131: public function isAddChildData()
132: {
133: return intval(Mage::getConfig()->getNode(self::XML_NODE_ADD_CHILD_DATA));
134: }
135:
136: /**
137: * Retrive Catalog Product Flat index process
138: *
139: * @return Mage_Index_Model_Process
140: */
141: public function getProcess()
142: {
143: if (is_null($this->_process)) {
144: $this->_process = Mage::getModel('index/process')
145: ->load(self::CATALOG_FLAT_PROCESS_CODE, 'indexer_code');
146: }
147: return $this->_process;
148: }
149: }
150: