Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_CatalogIndex_Model_Aggregation
  • Mage_CatalogIndex_Model_Attribute
  • Mage_CatalogIndex_Model_Catalog_Index_Flag
  • Mage_CatalogIndex_Model_Catalog_Index_Kill_Flag
  • Mage_CatalogIndex_Model_Data_Abstract
  • Mage_CatalogIndex_Model_Data_Configurable
  • Mage_CatalogIndex_Model_Data_Grouped
  • Mage_CatalogIndex_Model_Data_Simple
  • Mage_CatalogIndex_Model_Data_Virtual
  • Mage_CatalogIndex_Model_Indexer
  • Mage_CatalogIndex_Model_Indexer_Abstract
  • Mage_CatalogIndex_Model_Indexer_Eav
  • Mage_CatalogIndex_Model_Indexer_Minimalprice
  • Mage_CatalogIndex_Model_Indexer_Price
  • Mage_CatalogIndex_Model_Indexer_Tierprice
  • Mage_CatalogIndex_Model_Mysql4_Abstract
  • Mage_CatalogIndex_Model_Mysql4_Aggregation
  • Mage_CatalogIndex_Model_Mysql4_Attribute
  • Mage_CatalogIndex_Model_Mysql4_Data_Abstract
  • Mage_CatalogIndex_Model_Mysql4_Data_Configurable
  • Mage_CatalogIndex_Model_Mysql4_Data_Grouped
  • Mage_CatalogIndex_Model_Mysql4_Indexer
  • Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract
  • Mage_CatalogIndex_Model_Mysql4_Indexer_Eav
  • Mage_CatalogIndex_Model_Mysql4_Indexer_Minimalprice
  • Mage_CatalogIndex_Model_Mysql4_Indexer_Price
  • Mage_CatalogIndex_Model_Mysql4_Price
  • Mage_CatalogIndex_Model_Mysql4_Retreiver
  • Mage_CatalogIndex_Model_Mysql4_Setup
  • Mage_CatalogIndex_Model_Observer
  • Mage_CatalogIndex_Model_Price
  • Mage_CatalogIndex_Model_Resource_Abstract
  • Mage_CatalogIndex_Model_Resource_Aggregation
  • Mage_CatalogIndex_Model_Resource_Attribute
  • Mage_CatalogIndex_Model_Resource_Data_Abstract
  • Mage_CatalogIndex_Model_Resource_Data_Configurable
  • Mage_CatalogIndex_Model_Resource_Data_Grouped
  • Mage_CatalogIndex_Model_Resource_Indexer
  • Mage_CatalogIndex_Model_Resource_Indexer_Abstract
  • Mage_CatalogIndex_Model_Resource_Indexer_Eav
  • Mage_CatalogIndex_Model_Resource_Indexer_Minimalprice
  • Mage_CatalogIndex_Model_Resource_Indexer_Price
  • Mage_CatalogIndex_Model_Resource_Price
  • Mage_CatalogIndex_Model_Resource_Retreiver
  • Mage_CatalogIndex_Model_Resource_Setup
  • Mage_CatalogIndex_Model_Retreiver

Interfaces

  • Mage_CatalogIndex_Model_Indexer_Interface
  • Overview
  • Package
  • Class
  • Tree
  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: /**
 29:  * Resource model CatalogIndex Data Abstract
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_CatalogIndex
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_CatalogIndex_Model_Resource_Data_Abstract extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Attribute id by code cache
 39:      *
 40:      * @var array
 41:      */
 42:     protected $_attributeCodeIds     = array();
 43: 
 44:     /**
 45:      * Link select object
 46:      *
 47:      * @var Zend_Db_Select
 48:      */
 49:     protected $_linkSelect           = null;
 50: 
 51:     /**
 52:      * Set link select
 53:      *
 54:      * @param Zend_Db_Select $select
 55:      * @return Mage_CatalogIndex_Model_Resource_Data_Abstract
 56:      */
 57:     protected function _setLinkSelect($select)
 58:     {
 59:         $this->_linkSelect = $select;
 60:         return $this;
 61:     }
 62: 
 63:     /**
 64:      * Get link select
 65:      *
 66:      * @return Zend_Db_Select $select
 67:      */
 68:     protected function _getLinkSelect()
 69:     {
 70:         return $this->_linkSelect;
 71:     }
 72: 
 73:     /**
 74:      * Init resource
 75:      *
 76:      */
 77:     protected function _construct()
 78:     {
 79:         $this->_init('catalog/product', 'entity_id');
 80:     }
 81: 
 82:     /**
 83:      * Retreive specified attribute data for specified products from specified store
 84:      *
 85:      * @param array $products
 86:      * @param array $attributes
 87:      * @param int $store
 88:      * @return unknown
 89:      */
 90:     public function getAttributeData($products, $attributes, $store)
 91:     {
 92:         $suffixes = array('decimal', 'varchar', 'int', 'text', 'datetime');
 93:         if (!is_array($products)) {
 94:             $products = new Zend_Db_Expr($products);
 95:         }
 96:         $result = array();
 97:         foreach ($suffixes as $suffix) {
 98:             $tableName = "{$this->getTable('catalog/product')}_{$suffix}";
 99:             $condition = "product.entity_id = c.entity_id AND c.store_id = {$store} AND c.attribute_id = d.attribute_id";
100:             $defaultCondition = "product.entity_id = d.entity_id AND d.store_id = 0";
101:             $fields = array(
102:                 'entity_id',
103:                 'type_id',
104:                 'attribute_id'  => 'IF(c.value_id > 0, c.attribute_id, d.attribute_id)',
105:                 'value'         => 'IF(c.value_id > 0, c.value, d.value)'
106:             );
107: 
108:             $select = $this->_getReadAdapter()->select()
109:                 ->from(array('product'=>$this->getTable('catalog/product')), $fields)
110:                 ->where('product.entity_id in (?)', $products)
111:                 ->joinRight(array('d'=>$tableName), $defaultCondition, array())
112:                 ->joinLeft(array('c'=>$tableName), $condition, array())
113:                 ->where('c.attribute_id IN (?) OR d.attribute_id IN (?)', $attributes);
114:             $part = $this->_getReadAdapter()->fetchAll($select);
115: 
116:             if (is_array($part)) {
117:                 $result = array_merge($result, $part);
118:             }
119:         }
120: 
121:         return $result;
122:     }
123: 
124:     /**
125:      * Returns an array of product children/parents
126:      *
127:      * @param int $store
128:      * @param string $table
129:      * @param string $idField
130:      * @param string $whereField
131:      * @param int $id
132:      * @param array $additionalWheres
133:      * @return mixed
134:      */
135:     public function fetchLinkInformation($store, $table, $idField, $whereField, $id, $additionalWheres = array())
136:     {
137:         $idsConditionSymbol = "= ?";
138:         if (is_array($id)) {
139:             $idsConditionSymbol = "in (?)";
140:         }
141: 
142:         $select = $this->_getReadAdapter()->select();
143:         $select->from(array('l'=>$this->getTable($table)), array("l.{$idField}"))
144:             ->where("l.{$whereField} {$idsConditionSymbol}", $id);
145:         foreach ($additionalWheres as $field=>$condition) {
146:             $select->where("l.$field = ?", $condition);
147:         }
148: 
149:         // add status filter
150:         $this->_addAttributeFilter($select, 'status', 'l', $idField, $store,
151:             Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
152:         // add website filter
153:         if ($websiteId = Mage::app()->getStore($store)->getWebsiteId()) {
154:             $select->join(
155:                 array('w' => $this->getTable('catalog/product_website')),
156:                 "l.{$idField}=w.product_id AND w.website_id={$websiteId}",
157:                 array()
158:             );
159:         }
160: 
161:         $this->_setLinkSelect($select);
162:         $this->_prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres);
163: 
164:         return $this->_getWriteAdapter()->fetchCol($this->_getLinkSelect());
165:     }
166: 
167:     /**
168:      * Prepare select statement before 'fetchLinkInformation' function result fetch
169:      *
170:      * @param int $store
171:      * @param string $table
172:      * @param string $idField
173:      * @param string $whereField
174:      * @param int $id
175:      * @param array $additionalWheres
176:      */
177:     protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array())
178:     {
179: 
180:     }
181: 
182:     /**
183:      * Return minimal prices for specified products
184:      *
185:      * @param array $products
186:      * @param array $priceAttributes
187:      * @param int $store
188:      * @return mixed
189:      */
190:     public function getMinimalPrice($products, $priceAttributes, $store)
191:     {
192:         $website = Mage::app()->getStore($store)->getWebsiteId();
193: 
194:         $fields = array('customer_group_id', 'minimal_value'=>'MIN(value)');
195:         $select = $this->_getReadAdapter()->select()
196:             ->from(array('base'=>$this->getTable('catalogindex/price')), $fields)
197:             ->where('base.entity_id in (?)', $products)
198:             ->where('base.attribute_id in (?)', $priceAttributes)
199:             ->where('base.website_id = ?', $website)
200:             ->group('base.customer_group_id');
201:         return $this->_getReadAdapter()->fetchAll($select);
202:     }
203: 
204:     /**
205:      * Return tier prices for specified product in specified website
206:      *
207:      * @param array $products
208:      * @param int $website
209:      * @return mixed
210:      */
211:     public function getTierPrices($products, $website)
212:     {
213:         $fields = array(
214:             'entity_id',
215:             'type_id',
216:             'c.customer_group_id',
217:             'c.qty',
218:             'c.value',
219:             'c.all_groups',
220:         );
221:         $condition = "product.entity_id = c.entity_id";
222: 
223:         $select = $this->_getReadAdapter()->select()
224:             ->from(array('product'=>$this->getTable('catalog/product')), $fields)
225:             ->joinLeft(array('c'=>"{$this->getTable('catalog/product')}_tier_price"), $condition, array())
226:             ->where('product.entity_id in (?)', $products);
227:         if (Mage::helper('catalog')->isPriceGlobal())
228:         {
229:             $select->where('c.website_id=?', 0);
230:         }
231:         elseif (Mage::app()->getWebsite($website)->getBaseCurrencyCode() != Mage::app()->getBaseCurrencyCode()) {
232:             $select->where('c.website_id=?', $website);
233:         }
234:         else {
235:             $select->where('c.website_id IN(?)', array(0, $website));
236:         }
237: 
238:         return $this->_getReadAdapter()->fetchAll($select);
239:     }
240: 
241:     /**
242:      * Add attribute filter to select
243:      *
244:      * @param Varien_Db_Select $select
245:      * @param string $attributeCode
246:      * @param string $table the main table name or alias
247:      * @param string $field entity_id field name
248:      * @param int $store
249:      * @param int|string|array $value the filter value
250:      * @return Mage_CatalogIndex_Model_Resource_Data_Abstract
251:      */
252:     protected function _addAttributeFilter(Varien_Db_Select $select, $attributeCode, $table, $field, $store, $value)
253:     {
254:         $adapter = $this->_getReadAdapter();
255:         $attribute = Mage::getSingleton('eav/config')
256:             ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
257:         /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
258:         $attributeTable = $attribute->getBackend()->getTable();
259:         if ($attribute->getBackendType() == 'static') {
260:             $tableAlias = sprintf('t_%s', $attribute->getAttributeCode());
261:             $joinCond   = join(' AND ', array(
262:                 sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableAlias)
263:             ));
264:             $select
265:                 ->join(
266:                     array($tableAlias => $attributeTable),
267:                     $joinCond,
268:                     array())
269:                 ->where(sprintf('%s.%s IN(?)', $tableAlias, $attribute->getAttributeCode()), $value);
270:         }
271:         elseif ($attribute->isScopeGlobal()) {
272:             $tableAlias = sprintf('t_%s', $attribute->getAttributeCode());
273:             $joinCond   = join(' AND ', array(
274:                 sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableAlias),
275:                 $adapter->quoteInto(sprintf('`%s`.`attribute_id`=?', $tableAlias), $attribute->getAttributeId()),
276:                 $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableAlias), 0)
277:             ));
278:             $select
279:                 ->join(
280:                     array($tableAlias => $attributeTable),
281:                     $joinCond,
282:                     array())
283:                 ->where(sprintf('%s.value IN(?)', $tableAlias), $value);
284:         }
285:         else {
286:             $tableGlobal    = sprintf('t_global_%s', $attribute->getAttributeCode());
287:             $tableStore     = sprintf('t_store_%s', $attribute->getAttributeCode());
288:             $joinCondGlobal = join(' AND ', array(
289:                 sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableGlobal),
290:                 $adapter->quoteInto(sprintf('`%s`.`attribute_id`=?', $tableGlobal), $attribute->getAttributeId()),
291:                 $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableGlobal), 0)
292:             ));
293:             $joinCondStore  = join(' AND ', array(
294:                 sprintf('`%s`.`entity_id`=`%s`.`entity_id`', $tableGlobal, $tableStore),
295:                 sprintf('`%s`.`attribute_id`=`%s`.`attribute_id`', $tableGlobal, $tableStore),
296:                 $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableStore), $store)
297:             ));
298:             $whereCond      = sprintf('IF(`%s`.`value_id`>0, `%s`.`value`, `%s`.`value`) IN(?)',
299:                 $tableStore, $tableStore, $tableGlobal);
300: 
301:             $select
302:                 ->join(
303:                     array($tableGlobal => $attributeTable),
304:                     $joinCondGlobal,
305:                     array())
306:                 ->joinLeft(
307:                     array($tableStore => $attributeTable),
308:                     $joinCondStore,
309:                     array())
310:                 ->where($whereCond, $value);
311:         }
312: 
313:         return $this;
314:     }
315: }
316: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0