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_Adminhtml_Block_Sitemap
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Action
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Link
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Time
  • Mage_Adminhtml_SitemapController
  • Mage_Sitemap_Helper_Data
  • Mage_Sitemap_Model_Mysql4_Catalog_Category
  • Mage_Sitemap_Model_Mysql4_Catalog_Product
  • Mage_Sitemap_Model_Mysql4_Cms_Page
  • Mage_Sitemap_Model_Mysql4_Sitemap
  • Mage_Sitemap_Model_Mysql4_Sitemap_Collection
  • Mage_Sitemap_Model_Observer
  • Mage_Sitemap_Model_Resource_Catalog_Category
  • Mage_Sitemap_Model_Resource_Catalog_Product
  • Mage_Sitemap_Model_Resource_Cms_Page
  • Mage_Sitemap_Model_Resource_Sitemap
  • Mage_Sitemap_Model_Resource_Sitemap_Collection
  • Mage_Sitemap_Model_Sitemap
  • 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_Sitemap
 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:  * Sitemap resource product collection model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Sitemap
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Sitemap_Model_Resource_Catalog_Product extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Collection Zend Db select
 39:      *
 40:      * @var Zend_Db_Select
 41:      */
 42:     protected $_select;
 43: 
 44:     /**
 45:      * Attribute cache
 46:      *
 47:      * @var array
 48:      */
 49:     protected $_attributesCache    = array();
 50: 
 51:     /**
 52:      * Init resource model (catalog/category)
 53:      *
 54:      */
 55:     protected function _construct()
 56:     {
 57:         $this->_init('catalog/product', 'entity_id');
 58:     }
 59: 
 60:     /**
 61:      * Add attribute to filter
 62:      *
 63:      * @param int $storeId
 64:      * @param string $attributeCode
 65:      * @param mixed $value
 66:      * @param string $type
 67:      * @return Zend_Db_Select
 68:      */
 69:     protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
 70:     {
 71:         if (!isset($this->_attributesCache[$attributeCode])) {
 72:             $attribute = Mage::getSingleton('catalog/product')->getResource()->getAttribute($attributeCode);
 73: 
 74:             $this->_attributesCache[$attributeCode] = array(
 75:                 'entity_type_id'    => $attribute->getEntityTypeId(),
 76:                 'attribute_id'      => $attribute->getId(),
 77:                 'table'             => $attribute->getBackend()->getTable(),
 78:                 'is_global'         => $attribute->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
 79:                 'backend_type'      => $attribute->getBackendType()
 80:             );
 81:         }
 82: 
 83:         $attribute = $this->_attributesCache[$attributeCode];
 84: 
 85:         if (!$this->_select instanceof Zend_Db_Select) {
 86:             return false;
 87:         }
 88: 
 89:         switch ($type) {
 90:             case '=':
 91:                 $conditionRule = '=?';
 92:                 break;
 93:             case 'in':
 94:                 $conditionRule = ' IN(?)';
 95:                 break;
 96:             default:
 97:                 return false;
 98:                 break;
 99:         }
100: 
101:         if ($attribute['backend_type'] == 'static') {
102:             $this->_select->where('e.' . $attributeCode . $conditionRule, $value);
103:         } else {
104:             $this->_select->join(
105:                 array('t1_'.$attributeCode => $attribute['table']),
106:                 'e.entity_id=t1_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.store_id=0',
107:                 array()
108:             )
109:             ->where('t1_'.$attributeCode.'.attribute_id=?', $attribute['attribute_id']);
110: 
111:             if ($attribute['is_global']) {
112:                 $this->_select->where('t1_'.$attributeCode.'.value'.$conditionRule, $value);
113:             } else {
114:                 $ifCase = $this->_select->getAdapter()->getCheckSql('t2_'.$attributeCode.'.value_id > 0', 't2_'.$attributeCode.'.value', 't1_'.$attributeCode.'.value');
115:                 $this->_select->joinLeft(
116:                     array('t2_'.$attributeCode => $attribute['table']),
117:                     $this->_getWriteAdapter()->quoteInto('t1_'.$attributeCode.'.entity_id = t2_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.attribute_id = t2_'.$attributeCode.'.attribute_id AND t2_'.$attributeCode.'.store_id=?', $storeId),
118:                     array()
119:                 )
120:                 ->where('('.$ifCase.')'.$conditionRule, $value);
121:             }
122:         }
123: 
124:         return $this->_select;
125:     }
126: 
127:     /**
128:      * Get category collection array
129:      *
130:      * @param unknown_type $storeId
131:      * @return array
132:      */
133:     public function getCollection($storeId)
134:     {
135:         $products = array();
136: 
137:         $store = Mage::app()->getStore($storeId);
138:         /* @var $store Mage_Core_Model_Store */
139: 
140:         if (!$store) {
141:             return false;
142:         }
143: 
144:         $urCondions = array(
145:             'e.entity_id=ur.product_id',
146:             'ur.category_id IS NULL',
147:             $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()),
148:             $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1),
149:         );
150:         $this->_select = $this->_getWriteAdapter()->select()
151:             ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName()))
152:             ->join(
153:                 array('w' => $this->getTable('catalog/product_website')),
154:                 'e.entity_id=w.product_id',
155:                 array()
156:             )
157:             ->where('w.website_id=?', $store->getWebsiteId())
158:             ->joinLeft(
159:                 array('ur' => $this->getTable('core/url_rewrite')),
160:                 join(' AND ', $urCondions),
161:                 array('url' => 'request_path')
162:             );
163: 
164:         $this->_addFilter($storeId, 'visibility', Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds(), 'in');
165:         $this->_addFilter($storeId, 'status', Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(), 'in');
166: 
167:         $query = $this->_getWriteAdapter()->query($this->_select);
168:         while ($row = $query->fetch()) {
169:             $product = $this->_prepareProduct($row);
170:             $products[$product->getId()] = $product;
171:         }
172: 
173:         return $products;
174:     }
175: 
176:     /**
177:      * Prepare product
178:      *
179:      * @param array $productRow
180:      * @return Varien_Object
181:      */
182:     protected function _prepareProduct(array $productRow)
183:     {
184:         $product = new Varien_Object();
185:         $product->setId($productRow[$this->getIdFieldName()]);
186:         $productUrl = !empty($productRow['url']) ? $productRow['url'] : 'catalog/product/view/id/' . $product->getId();
187:         $product->setUrl($productUrl);
188:         return $product;
189:     }
190: }
191: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0