/**
  * Apply category filter to layer
  *
  * @param   Zend_Controller_Request_Abstract $request
  * @param   Mage_Core_Block_Abstract $filterBlock
  * @return  Mage_Catalog_Model_Layer_Filter_Category
  */
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     $filter = (int) $request->getParam($this->getRequestVar());
     if (!$filter) {
         return $this;
     }
     // load data for applied category
     $this->_appliedCategory = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($filter);
     if ($this->_appliedCategory->getId()) {
         // create join and conditions for additional category filter
         $tableAlias = 'category_layered_' . $this->_rootCategory->getId();
         $conditions = array();
         $conditions['category_id'] = $filter;
         $conditions['store_id'] = Mage::app()->getStore()->getId();
         if (!$this->_appliedCategory->getIsAnchor()) {
             $conditions['is_parent'] = 1;
         }
         $this->getLayer()->getProductCollection()->joinTable(array($tableAlias => 'catalog/category_product_index'), "product_id=entity_id", array($tableAlias . '_cat_id' => 'category_id', $tableAlias . '_store_id' => 'store_id'), $conditions, 'inner');
         // add filter to layer state
         $this->getLayer()->getState()->addFilter($this->_createItem($this->_appliedCategory->getName(), $filter));
         // if current applied category has no children reset items array (for hiding filter block)
         if (!$this->_appliedCategory->getChildrenCategories()) {
             $this->_items = array();
         }
     }
     return $this;
 }
 protected function exportData(Mage_Catalog_Model_Category $category, $file, $depth = 0)
 {
     $data = array('id' => $category->getId(), 'parent_id' => $category->getParentId(), 'attribute_set_id' => $category->getAttributeSetId(), 'urlPath' => $category->getUrlPath(), 'urlKey' => $category->getUrlKey(), 'path' => $category->getPath(), 'position' => $category->getPosition(), 'page_layout' => $category->getPageLayout(), 'description' => $category->getDescription(), 'display_mode' => $category->getDisplayMode(), 'is_active' => $category->getIsActive(), 'is_anchor' => $category->getIsAnchor(), 'include_in_menu' => $category->getIncludeInMenu(), 'custom_design' => $category->getCustomDesign(), 'level' => $category->getLevel(), 'name' => $category->getName(), 'metaTitle' => $category->getMetaTitle(), 'metaKeywords' => $category->getMetaKeywords(), 'metaDescription' => $category->getMetaDescription());
     echo str_repeat('  ', $depth);
     echo '* ' . $category->getName() . sprintf(' (%s products)', $category->getProductCount()) . PHP_EOL;
     fputcsv($file, $data);
     if ($category->hasChildren()) {
         $children = Mage::getModel('catalog/category')->getCategories($category->getId());
         foreach ($children as $child) {
             $child = Mage::getModel('catalog/category')->load($child->getId());
             $this->exportData($child, $file, $depth + 1);
         }
     }
 }
Esempio n. 3
0
 /**
  * Specify category filter for product collection
  *
  * @param   Mage_Catalog_Model_Category $category
  * @return  Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
  */
 public function addCategoryFilter(Mage_Catalog_Model_Category $category)
 {
     $this->_productLimitationFilters['category_id'] = $category->getId();
     if ($category->getIsAnchor()) {
         unset($this->_productLimitationFilters['category_is_anchor']);
     } else {
         $this->_productLimitationFilters['category_is_anchor'] = 1;
     }
     $this->_query->setQuery($this->_queryString);
     if ($this->getStoreId() == Mage_Core_Model_App::ADMIN_STORE_ID) {
         //$this->_applyZeroStoreProductLimitations();
     } else {
         // $this->_applyProductLimitations();
     }
     return $this;
 }
Esempio n. 4
0
 /**
  * Specify category filter for product collection
  *
  * @param Mage_Catalog_Model_Category $category
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 public function addCategoryFilter(Mage_Catalog_Model_Category $category)
 {
     $this->_productLimitationFilters['category_id'] = $category->getId();
     if ($category->getIsAnchor()) {
         unset($this->_productLimitationFilters['category_is_anchor']);
     } else {
         $this->_productLimitationFilters['category_is_anchor'] = 1;
     }
     if ($this->getStoreId() == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) {
         //FIXME: apply no store
         //$this->_applyZeroStoreProductLimitations();
     } else {
         //FIXME: apply stores
         //$this->_applyProductLimitations();
     }
     return $this;
 }
 /**
  * Specify category filter for product collection
  *
  * @param Mage_Catalog_Model_Category $category
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
  */
 public function addCategoryFilter(Mage_Catalog_Model_Category $category)
 {
     $this->_productLimitationFilters['category_id'] = $category->getId();
     if ($category->getIsAnchor()) {
         unset($this->_productLimitationFilters['category_is_anchor']);
     } else {
         $this->_productLimitationFilters['category_is_anchor'] = 1;
     }
     $this->_applyProductLimitations();
     return $this;
 }
 /**
  * Specify category filter for product collection
  *
  * @param   Mage_Catalog_Model_Category $category
  * @param   bool $renderAlias instruction for build category table alias based on category id
  * @return  Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
  */
 public function addCategoryFilter(Mage_Catalog_Model_Category $category, $renderAlias = false)
 {
     if ($renderAlias) {
         $alias = 'cat_index_' . $category->getId();
     } else {
         $alias = 'cat_index';
     }
     $categoryCondition = $this->getConnection()->quoteInto($alias . '.product_id=e.entity_id AND ' . $alias . '.store_id=? AND ', $this->getStoreId());
     if ($category->getIsAnchor()) {
         $categoryCondition .= $this->getConnection()->quoteInto($alias . '.category_id=?', $category->getId());
     } else {
         $categoryCondition .= $this->getConnection()->quoteInto($alias . '.category_id=? AND ' . $alias . '.is_parent=1', $category->getId());
     }
     $this->getSelect()->joinInner(array($alias => $this->getTable('catalog/category_product_index')), $categoryCondition, array('position' => 'position'));
     $this->_categoryIndexJoined = true;
     $this->_joinFields['position'] = array('table' => $alias, 'field' => 'position');
     //        $this->joinField(
     //            $alias,
     //            'catalog/category_product_index',
     //            'position',
     //            'product_id=entity_id',
     //            $categoryCondition
     //        );
     return $this;
 }
 public function addCategoryFilter(Mage_Catalog_Model_Category $category)
 {
     $this->_productLimitationFilters['category_id'] = $category->getId();
     if ($category->getIsAnchor()) {
         $this->getSelect()->where('available_category_ids:' . $category->getId());
     } else {
         $this->getSelect()->where('available_category_ids:' . $category->getId());
     }
     return $this;
 }
Esempio n. 8
0
 /**
  * add category filter to collection
  *
  * @param Mage_Catalog_Model_Category $category
  */
 public function addCategoryFilter(Mage_Catalog_Model_Category $category)
 {
     $this->_productLimitationFilters['category_id'] = $category->getId();
     if ($category->getIsAnchor() == 1) {
         unset($this->_productLimitationFilters['category_is_anchor']);
     } else {
         $this->_productLimitationFilters['category_is_anchor'] = 1;
     }
     $this->_fieldMap['position'] = 'category_sort.category_' . $category->getId();
     return $this;
 }
 /**
  * Add category filter to product collection
  *
  * @param Mage_Catalog_Model_Category $category Category
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 public function pushCategoryFilter(Mage_Catalog_Model_Category $category)
 {
     if (is_array($this->_productLimitationFilters['category_id'])) {
         $this->_productLimitationFilters['category_id'][] = $category->getId();
     } else {
         $this->_productLimitationFilters['category_id'] = array($category->getId());
     }
     if ($category->getIsAnchor()) {
         unset($this->_productLimitationFilters['category_is_anchor']);
     } else {
         $this->_productLimitationFilters['category_is_anchor'] = 1;
     }
     if ($this->getStoreId() == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) {
         $this->_applyZeroStoreProductLimitations();
     } else {
         $this->_applyProductLimitations();
     }
     return $this;
 }
Esempio n. 10
0
 public function addCategoryFilter(Mage_Catalog_Model_Category $category, $renderAlias = false)
 {
     if ($category->getIsAnchor()) {
         $categoryCondition = $this->getConnection()->quoteInto('{{table}}.category_id IN (?)', explode(',', $category->getAllChildren()));
         $this->getSelect()->group('e.entity_id');
     } else {
         $categoryCondition = $this->getConnection()->quoteInto('{{table}}.category_id=?', $category->getId());
     }
     if ($renderAlias) {
         $alias = 'category_' . $category->getId();
     } else {
         $alias = 'position';
     }
     $this->joinField($alias, 'catalog/category_product', 'position', 'product_id=entity_id', $categoryCondition);
     return $this;
 }