Exemplo n.º 1
0
 /**
  * @param array $entityIds
  * @return Mage_Catalog_Model_Resource_Category_Collection
  */
 protected function _preparedCollection(array $entityIds = array())
 {
     if (empty(self::$_categoryCollection)) {
         self::$_categoryCollection = Mage::getSingleton("catalog/category")->getCollection()->addAttributeToSelect("name");
         if (!empty($entityIds)) {
             self::$_categoryCollection->addFieldToFilter("entity_id", $entityIds);
         }
         self::$_categoryCollection->addFieldToFilter("entity_id", array("nin" => $this->_getHelper()->getRootCategoryIds()));
     }
     return self::$_categoryCollection;
 }
 /**
  * Init virtual category attributes using the backend model when category load.
  *
  * @return Mage_Catalog_Model_Resource_Category_Collection
  */
 protected function _afterLoad()
 {
     parent::_afterLoad();
     if (array_key_exists('virtual_category', $this->_selectAttributes)) {
         $virtualCategoryBackendModel = Mage::getModel('smile_virtualcategories/category_attributes_backend_virtual');
         foreach ($this->_items as $item) {
             $virtualCategoryBackendModel->afterLoad($item);
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Build a list of product categories in hierarchical order.
  *
  * @name parseCategoryValue
  * @param Mage_Catalog_Model_Resource_Category_Collection $objectCollection
  * @return string
  */
 protected function parseCategoryValue($objectCollection)
 {
     $objectCollection->addAttributeToSelect('name');
     $object = $objectCollection->getFirstItem();
     $names = array();
     while ($object->getLevel() > 0) {
         $names[] = $object->getName();
         $object = $object->getParentCategory();
     }
     return implode('/', array_reverse($names));
 }
Exemplo n.º 4
0
 /**
  * Retrieve inactive category item ids
  *
  * @param Mage_Catalog_Model_Resource_Category_Collection $collection
  * @param int $storeId
  * @return array
  */
 protected function _getInactiveItemIds($collection, $storeId)
 {
     $filter = $collection->getAllIds();
     $attributeId = $this->_getIsActiveAttributeId();
     $conditionSql = $this->_conn->getCheckSql('c.value_id > 0', 'c.value', 'd.value');
     $table = Mage::getSingleton('core/resource')->getTableName(array('catalog/category', 'int'));
     $bind = array('attribute_id' => $attributeId, 'store_id' => $storeId, 'zero_store_id' => 0, 'cond' => 0);
     $select = $this->_conn->select()->from(array('d' => $table), array('d.entity_id'))->where('d.attribute_id = :attribute_id')->where('d.store_id = :zero_store_id')->where('d.entity_id IN (?)', $filter)->joinLeft(array('c' => $table), 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = d.entity_id', array())->where($conditionSql . ' = :cond');
     return $this->_conn->fetchCol($select, $bind);
 }
 /**
  * Handles collection filtering by ids retrieves from search engine.
  * Will also stores faceted data and total records.
  *
  * @return Mage_Catalog_Model_Resource_Category_Collection
  */
 protected function _beforeLoad()
 {
     $this->_prepareQuery();
     $ids = array();
     $result = $this->getSearchEngineQuery()->search();
     $ids = isset($result['ids']) ? $result['ids'] : array();
     $this->_facetedData = isset($result['faceted_data']) ? $result['faceted_data'] : array();
     $this->_totalRecords = isset($result['total_count']) ? $result['total_count'] : null;
     $this->_isSpellChecked = isset($result['is_spellchecked']) ? $result['is_spellchecked'] : false;
     if (empty($ids)) {
         $ids = array(0);
         // Fix for no result
     }
     $this->addIdFilter($ids);
     $this->_searchedEntityIds = $ids;
     $this->_pageSize = false;
     return parent::_beforeLoad();
 }
 /**
  * Build a list of product categories in hierarchical order.
  *
  * @name parseCategoryValue
  * @param Mage_Catalog_Model_Resource_Category_Collection $objectCollection
  * @return string
  */
 protected function parseCategoryValue($objectCollection)
 {
     $objectCollection->addAttributeToSelect('name');
     $object = $objectCollection->getFirstItem();
     $names = array();
     $depth = 0;
     if (!Mage::app()->isSingleStoreMode()) {
         $depth = 1;
     }
     while ($object->getLevel() > $depth) {
         $names[] = $object->getName();
         $object = $object->getParentCategory();
     }
     return implode('/', array_reverse($names));
 }
Exemplo n.º 7
0
 /**
  * Based on provided Collection and optionally sort order, returns sorted array of categories.
  * 
  * @param Mage_Catalog_Model_Resource_Category_Collection $collection
  * @param string $sortOrder
  * @return array
  */
 public function getCategoriesFromCollection($collection, $sortOrder = '')
 {
     $categories = array();
     if ($sortOrder != '') {
         $sort = explode(',', $sortOrder);
         foreach ($sort as $id) {
             $c = $collection->getItemById($id);
             if ($c != null) {
                 $categories[$id] = $this->categoryToArray($c);
             }
         }
     } else {
         foreach ($collection as $c) {
             $id = $c->getId();
             $categories[$id] = $this->categoryToArray($c);
         }
     }
     return $categories;
 }
Exemplo n.º 8
0
 /**
  * Add index to category collection
  *
  * @param Mage_Catalog_Model_Resource_Category_Collection|Mage_Catalog_Model_Resource_Category_Flat_Collection $collection
  * @param int $customerGroupId
  * @param int $websiteId
  * @return Enterprise_CatalogPermissions_Model_Resource_Permission_Index
  */
 public function addIndexToCategoryCollection($collection, $customerGroupId, $websiteId)
 {
     $adapter = $this->_getReadAdapter();
     if ($collection instanceof Mage_Catalog_Model_Resource_Category_Flat_Collection) {
         $tableAlias = 'main_table';
     } else {
         $tableAlias = 'e';
     }
     $collection->getSelect()->joinLeft(array('permission_index' => $this->getTable('permission_index')), 'permission_index.category_id = ' . $tableAlias . '.entity_id' . ' AND ' . $adapter->quoteInto('permission_index.website_id = ?', $websiteId) . ' AND ' . $adapter->quoteInto('permission_index.customer_group_id = ?', $customerGroupId), array());
     if (!Mage::helper('enterprise_catalogpermissions')->isAllowedCategoryView()) {
         $collection->getSelect()->where('permission_index.grant_catalog_category_view = ?', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_ALLOW);
     } else {
         $collection->getSelect()->where('permission_index.grant_catalog_category_view != ?' . ' OR permission_index.grant_catalog_category_view IS NULL', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY);
     }
     return $this;
 }
Exemplo n.º 9
0
 public function loadCollection(Mage_Catalog_Model_Resource_Category_Collection $collection, array $additionalFields = array())
 {
     $toLoad = array_unique(array_merge($this->_requiredCategoryFields, $this->_config()->megaMenuAttributeCodes(), $additionalFields));
     foreach ($toLoad as $field) {
         $collection->addAttributeToSelect($field);
     }
     $childreen = $collection->load($this->_debugDbLoads)->getItems();
     if ($this->_debugDbLoads) {
         foreach ($childreen as $child) {
             Mage::log('collection item loaded' . var_export($child->debug(), true));
         }
     }
     $this->_categoriesCache = $childreen + $this->_categoriesCache;
     return $childreen;
 }