Example #1
0
 /**
  * Add URL rewrites to collection
  *
  */
 protected function _addUrlRewrite()
 {
     $urlRewrites = null;
     if ($this->_cacheConf) {
         if (!($urlRewrites = Mage::app()->loadCache($this->_cacheConf['prefix'] . 'urlrewrite' . 'urlrewrite'))) {
             $urlRewrites = null;
         } else {
             $urlRewrites = unserialize($urlRewrites);
         }
     }
     if (!$urlRewrites) {
         $productIds = array();
         foreach ($this->_items as $item) {
             $productIds[] = $item->getEntityId();
         }
         #if (!count($productIds)) {
         #    return;
         #}
         $select = $this->_factory->getProductUrlRewriteHelper()->getTableSelect($productIds, $this->_urlRewriteCategory, Mage::app()->getStore()->getId());
         $urlRewrites = array();
         foreach (Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($select) as $row) {
             if (!isset($urlRewrites[$row['product_id']])) {
                 $urlRewrites[$row['product_id']] = $row['request_path'];
             }
         }
         if ($this->_cacheConf) {
             Mage::app()->saveCache(serialize($urlRewrites), $this->_cacheConf['prefix'] . 'urlrewrite' . 'urlrewrite', array_merge($this->_cacheConf['tags'], array(Mage_Catalog_Model_Product_Url::CACHE_TAG)), $this->_cacheLifetime);
         }
     }
     foreach ($this->_items as $item) {
         if (empty($this->_urlRewriteCategory)) {
             $item->setDoNotUseCategoryId(true);
         }
         if (isset($urlRewrites[$item->getEntityId()])) {
             $item->setData('request_path', $urlRewrites[$item->getEntityId()]);
         } else {
             $item->setData('request_path', false);
         }
     }
 }