/**
  * @param Mana_Seo_Rewrite_Url $urlModel
  * @return string | bool
  */
 public function getUrlKey($urlModel)
 {
     Mana_Core_Profiler2::start(__METHOD__);
     /* @var $seo Mana_Seo_Helper_Data */
     $seo = Mage::helper('mana_seo');
     /* @var $logger Mana_Core_Helper_Logger */
     $logger = Mage::helper('mana_core/logger');
     if (($categoryId = $urlModel->getSeoRouteParam('id')) === false) {
         $logger->logSeoUrl(sprintf('WARNING: while resolving %s, %s route parameter is required', 'category URL key', 'id'));
     }
     if (!isset($this->_urlKeys[$categoryId])) {
         $urlCollection = $seo->getUrlCollection($urlModel->getSchema(), Mana_Seo_Resource_Url_Collection::TYPE_PAGE);
         $urlCollection->addFieldToFilter('category_id', $categoryId);
         if (!($result = $urlModel->getUrlKey($urlCollection))) {
             $logger->logSeoUrl(sprintf('WARNING: %s not found by  %s %s', 'category URL key', 'id', $categoryId));
         }
         $this->_urlKeys[$categoryId] = $result;
     }
     Mana_Core_Profiler2::stop();
     return $this->_urlKeys[$categoryId]['final_url_key'];
 }
 /**
  * @param $optionId
  * @return array | bool
  */
 protected function _getSpecialFilterUrlKey($specialFilterUrl)
 {
     Mana_Core_Profiler2::start(__METHOD__);
     if (!isset(self::$_specialFilterUrlKeys[$specialFilterUrl])) {
         /* @var $seo Mana_Seo_Helper_Data */
         $seo = Mage::helper('mana_seo');
         /* @var $logger Mana_Core_Helper_Logger */
         $logger = Mage::helper('mana_core/logger');
         $urlCollection = $seo->getUrlCollection($this->getSchema(), Mana_Seo_Resource_Url_Collection::TYPE_ATTRIBUTE_VALUE);
         $urlCollection->addFieldToFilter('type', Mana_Seo_Model_ParsedUrl::PARAMETER_SPECIAL);
         $urlCollection->addFieldToFilter('url_key', $specialFilterUrl);
         if (!($result = $this->getUrlKey($urlCollection, array('final_include_filter_name', 'position', 'option_id')))) {
             $logger->logSeoUrl(sprintf('WARNING: %s not found by  %s %s', 'special filter URL key', 'id', $specialFilterUrl));
         }
         self::$_specialFilterUrlKeys[$specialFilterUrl] = $result;
     }
     Mana_Core_Profiler2::stop();
     return self::$_specialFilterUrlKeys[$specialFilterUrl];
 }
예제 #3
0
 /**
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $productCollection
  * @param $categoryCollection
  * @param bool $inCurrentCategory
  * @return $this
  */
 public function addCountToCategories($productCollection, $categoryCollection, $inCurrentCategory = false)
 {
     Mana_Core_Profiler2::start(__METHOD__);
     $isAnchor = array();
     $isNotAnchor = array();
     foreach ($categoryCollection as $category) {
         if ($category->getIsAnchor()) {
             $isAnchor[] = $category->getId();
         } else {
             $isNotAnchor[] = $category->getId();
         }
     }
     $productCounts = array();
     if ($isAnchor || $isNotAnchor) {
         /* @var $select Varien_Db_Select */
         $select = $productCollection->getProductCountSelect();
         if ($inCurrentCategory) {
             $from = $select->getPart(Varien_Db_Select::FROM);
             if (isset($from['cat_index'])) {
                 $categoryId = $this->getLayer()->getCurrentCategory()->getId();
                 $from['cat_index']['joinCondition'] = preg_replace("/(.*)(`?)cat_index(`?).(`?)category_id(`?)='(\\d+)'(.*)/", "\$1\$2cat_index\$3.\$4category_id\$5='{$categoryId}'\$7", $from['cat_index']['joinCondition']);
                 $select->setPart(Varien_Db_Select::FROM, $from);
             }
         }
         Mage::dispatchEvent('catalog_product_collection_before_add_count_to_categories', array('collection' => $productCollection));
         if ($isAnchor) {
             $anchorStmt = clone $select;
             $anchorStmt->limit();
             //reset limits
             $anchorStmt->where('count_table.category_id IN (?)', $isAnchor);
             $sql = $anchorStmt->__toString();
             $productCounts += $productCollection->getConnection()->fetchPairs($anchorStmt);
             $anchorStmt = null;
         }
         if ($isNotAnchor) {
             $notAnchorStmt = clone $select;
             $notAnchorStmt->limit();
             //reset limits
             $notAnchorStmt->where('count_table.category_id IN (?)', $isNotAnchor);
             $notAnchorStmt->where('count_table.is_parent = 1');
             $productCounts += $productCollection->getConnection()->fetchPairs($notAnchorStmt);
             $notAnchorStmt = null;
         }
         $select = null;
         $productCollection->unsProductCountSelect();
     }
     foreach ($categoryCollection as $category) {
         $_count = 0;
         if (isset($productCounts[$category->getId()])) {
             $_count = $productCounts[$category->getId()];
         }
         $category->setProductCount($_count);
     }
     Mana_Core_Profiler2::stop();
     return $this;
 }
예제 #4
0
 /**
  * @param $optionId
  * @return array | bool
  */
 protected function _getValueUrlKey($optionId)
 {
     Mana_Core_Profiler2::start(__METHOD__);
     if (!isset(self::$_valueUrlKeys[$optionId])) {
         if (($item = $this->itemHelper()->get($optionId)) && $item->getData('seo_url_key')) {
             $result = array('id' => $item->getData('seo_id'), 'final_url_key' => $item->getData('seo_url_key'), 'final_include_filter_name' => $item->getData('seo_include_filter_name'), 'position' => $item->getData('seo_position'), 'option_id' => $item->getData('value'));
         } else {
             /* @var $seo Mana_Seo_Helper_Data */
             $seo = Mage::helper('mana_seo');
             /* @var $logger Mana_Core_Helper_Logger */
             $logger = Mage::helper('mana_core/logger');
             $urlCollection = $seo->getUrlCollection($this->getSchema(), Mana_Seo_Resource_Url_Collection::TYPE_ATTRIBUTE_VALUE);
             $urlCollection->addFieldToFilter('option_id', $optionId);
             if (!($result = $this->getUrlKey($urlCollection, array('final_include_filter_name', 'position', 'option_id')))) {
                 $logger->logSeoUrl(sprintf('WARNING: %s not found by  %s %s', 'attribute option URL key', 'id', $optionId));
             }
         }
         self::$_valueUrlKeys[$optionId] = $result;
     }
     Mana_Core_Profiler2::stop();
     return self::$_valueUrlKeys[$optionId];
 }