Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ abstract class Netzarbeiter_GroupsCatalog2_Model_Resource_Indexer_Abstract exten
*/
protected $_groupIds = array();

/**
* Array of assigned category products
*
* @var array $_categoryProducts
*/
protected $_categoryProducts = array();

/**
* Module helper instance
*
Expand Down Expand Up @@ -325,6 +332,8 @@ protected function _insertIndexRecords(Zend_Db_Statement $stmt, array $limitToGr
$data, $entityId, $entityDefaultGroupsWithoutMode, $storesHandled, $limitToGroupIds
);

$this->_applyFilterToData($data);

// Insert INSERT_CHUNK_SIZE records at a time.
// If INSERT_CHUNK_SIZE records exist in $data then it is reset to an empty array afterwards
$this->_insertIndexRecordsIfMinChunkSizeReached($data, self::INSERT_CHUNK_SIZE);
Expand Down Expand Up @@ -365,13 +374,24 @@ protected function _insertIndexRecords(Zend_Db_Statement $stmt, array $limitToGr
$data, $entityId, $entityDefaultGroupsWithoutMode, $storesHandled, $limitToGroupIds
);

$this->_applyFilterToData($data);
// Insert missing index records
$this->_insertIndexRecordsIfMinChunkSizeReached($data, 1);
}

Varien_Profiler::stop($this->_getProfilerName() . '::reindexEntity::insert');
}

/**
* Apply a filter
*
* @param array $data Insert data
*/
protected function _applyFilterToData(array &$data)
{

}

/**
* Add a record to the data array if the group Id was not excluded by $limitToGroupIds
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,40 @@ protected function _getEntityTypeCode()
{
return Mage_Catalog_Model_Category::ENTITY;
}

/**
* Apply a filter
*
* @param array $data Insert data
*/
protected function _applyFilterToData(array &$data)
{
if ($this->_helper()->getConfig('show_empty_categories')) return;

$this->_categoryProducts = array();
foreach($data as $key => $values) {
$visibleItems = array();
if(empty($this->_categoryProducts[$values['catalog_entity_id']])) {
$this->_categoryProducts[$values['catalog_entity_id']] = array();
$category = Mage::getModel('catalog/category')->load($values['catalog_entity_id']);
$productCollection = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($category);
foreach($productCollection as $product) {
$this->_categoryProducts[$values['catalog_entity_id']][] = $product->getId();
}
}
if(!empty($this->_categoryProducts[$values['catalog_entity_id']])) {
$visibleItems = Mage::getResourceSingleton('netzarbeiter_groupscatalog2/filter')
->getVisibleIdsFromEntityIdList(
Mage_Catalog_Model_Product::ENTITY,
$this->_categoryProducts[$values['catalog_entity_id']],
$values['store_id'],
$values['group_id']
);
}
if(empty($visibleItems)) {
unset($data[$key]);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
<entity_hidden_behaviour_customer>404</entity_hidden_behaviour_customer>
<entity_hidden_redirect_guest>customer/account/login</entity_hidden_redirect_guest>
<entity_hidden_redirect_customer>cms</entity_hidden_redirect_customer>
<show_empty_categories>1</show_empty_categories>
<display_entity_hidden_msg>0</display_entity_hidden_msg>
<entity_hidden_msg_guest>Please register an account and log in.</entity_hidden_msg_guest>
<entity_hidden_msg_customer>Please contact us to request further access privileges.</entity_hidden_msg_customer>
Expand Down
13 changes: 13 additions & 0 deletions app/code/community/Netzarbeiter/GroupsCatalog2/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@
<entity_hidden_behaviour_customer>302</entity_hidden_behaviour_customer>
</depends>
</entity_hidden_redirect_customer>
<show_empty_categories>
<label>Should empty categories shown in Frontend-Menu?</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>95</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[Please reindex the category index after change]]></comment>
<depends>
<is_active>1</is_active>
</depends>
</show_empty_categories>
<display_entity_hidden_msg>
<label>Display a message when a hidden entity is accessed?</label>
<frontend_type>select</frontend_type>
Expand Down
3 changes: 2 additions & 1 deletion app/locale/de_DE/Netzarbeiter_GroupsCatalog2.csv
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
"Show multiselect customer group fields","Kundengruppen Multiselect Felder im Backend anzeigen"
"Disable only if there is a very large number of customer groups and if the product and category settings are done using some import mechanism instead of the admin panel.","Nur deaktivieren wenn es sehr viele Kundengruppen gibt und die Produkt- und Kategorie-Einstellungen mittels eines Import Mechanismus gesetzt werden anstelle des Admin-Interfaces."
"This field is read-only.<br/>(change the ""Show multiselect customer group fields"" option further down to enable this field)","Dieses Feld kann nur gelesen werden.<br/>(ändern Sie ""Kundengruppen Multiselect Felder im Backend anzeigen"" um es zu aktivieren)"

"Should empty categories shown in Frontend-Menu?","Sollen leere Kategorien im Menü erscheinen?"
"Please reindex the category index after change","Bitte nach Änderung den GroupsCatalog Kategorien index neu erstellen"