/** * Inner join the groupscatalog index table to not count products * not visible to the specified customer group id * * @param Mage_Catalog_Model_Resource_Product_Collection $collection * @param int $groupId * @return void */ public function addGroupsCatalogFilterToProductCollectionCountSelect(Mage_Catalog_Model_Resource_Product_Collection $collection, $groupId) { $select = $collection->getProductCountSelect(); $storeId = $collection->getStoreId(); $this->addGroupsCatalogProductFilterToSelect($select, $groupId, $storeId); }
/** * Inner join the groupscatalog index table to not count products * not visible to the specified customer group id * * @param Mage_Catalog_Model_Resource_Product_Collection $collection * @param int $groupId * @return void */ public function addGroupsCatalogFilterToProductCollectionCountSelect(Mage_Catalog_Model_Resource_Product_Collection $collection, $groupId) { /* @var $helper Netzarbeiter_GroupsCatalog2_Helper_Data */ $helper = Mage::helper('netzarbeiter_groupscatalog2'); // Switch index table depending on the specified entity $this->_init($helper->getIndexTableByEntityType(Mage_Catalog_Model_Product::ENTITY), 'id'); if ($this->_doesIndexExists()) { $table = $this->getTable($helper->getIndexTableByEntityType(Mage_Catalog_Model_Product::ENTITY)); $this->_addGroupsCatalogFilterToSelect($collection->getProductCountSelect(), $table, $groupId, $collection->getStoreId()); } }
/** * Add index to product count select in product collection * * @param Mage_Catalog_Model_Resource_Product_Collection $collection * @param int $customerGroupId * @return Enterprise_CatalogPermissions_Model_Resource_Permission_Index */ public function addIndexToProductCount($collection, $customerGroupId) { $adapter = $this->_getReadAdapter(); $parts = $collection->getSelect()->getPart(Zend_Db_Select::FROM); if (isset($parts['permission_index_product'])) { return $this; } $collection->getProductCountSelect()->joinLeft(array('permission_index_product_count' => $this->getTable('permission_index_product')), 'permission_index_product_count.category_id = count_table.category_id' . ' AND permission_index_product_count.product_id = count_table.product_id' . ' AND permission_index_product_count.store_id = count_table.store_id' . ' AND ' . $adapter->quoteInto('permission_index_product_count.customer_group_id=?', $customerGroupId), array()); if (!Mage::helper('enterprise_catalogpermissions')->isAllowedCategoryView()) { $collection->getProductCountSelect()->where('permission_index_product_count.grant_catalog_category_view = ?', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_ALLOW); } else { $collection->getProductCountSelect()->where('permission_index_product_count.grant_catalog_category_view != ?' . ' OR permission_index_product_count.grant_catalog_category_view IS NULL', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY); } return $this; }