@@ -33,6 +33,8 @@ class Technooze_Tindexer_Model_Indexer extends Mage_Index_Model_Indexer_Abstract
33
33
// var to protect multiple runs
34
34
protected $ _registered = false ;
35
35
protected $ _processed = false ;
36
+ protected $ _categoryId = 0 ;
37
+ protected $ _productIds = array ();
36
38
37
39
/**
38
40
* not sure why this is required.
@@ -94,6 +96,9 @@ protected function _registerProductEvent(Mage_Index_Model_Event $event)
94
96
95
97
if ($ eventType == Mage_Index_Model_Event::TYPE_SAVE || $ eventType == Mage_Index_Model_Event::TYPE_MASS_ACTION ) {
96
98
$ process = $ event ->getProcess ();
99
+ $ this ->_productIds = $ event ->getDataObject ()->getData ('product_ids ' );
100
+ $ this ->flagIndexRequired ($ this ->_productIds , 'products ' );
101
+
97
102
$ process ->changeStatus (Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX );
98
103
}
99
104
}
@@ -113,6 +118,9 @@ protected function _registerCategoryEvent(Mage_Index_Model_Event $event)
113
118
114
119
if ($ category ->getIsChangedProductList () || $ category ->getAffectedCategoryIds ()) {
115
120
$ process = $ event ->getProcess ();
121
+ $ this ->_categoryId = $ event ->getDataObject ()->getData ('entity_id ' );
122
+ $ this ->flagIndexRequired ($ this ->_categoryId , 'categories ' );
123
+
116
124
$ process ->changeStatus (Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX );
117
125
}
118
126
}
@@ -123,9 +131,21 @@ protected function _processEvent(Mage_Index_Model_Event $event){
123
131
}
124
132
}
125
133
126
- public function reindexAll ( ){
127
- // reindex all data | initFilteredProductsCount
134
+ public function flagIndexRequired ( $ ids = array (), $ type = ' products ' ){
135
+ $ ids = ( array ) $ ids ;
128
136
$ collection = Mage::getModel ('tindexer/products ' )->getCollection ();
137
+ $ filter = array ();
138
+ foreach ($ ids as $ id ){
139
+ $ filter [] = array ('like ' => "%, {$ id },% " );
140
+ }
141
+ $ collection ->addFieldToFilter ($ type , $ filter );
142
+ $ collection ->setDataToAll ('flag ' , 1 );
143
+ $ collection ->save ();
144
+ }
145
+
146
+ public function reindexAll (){
147
+ // reindex all data which are flagged 1 | initFilteredProductsCount
148
+ $ collection = Mage::getModel ('tindexer/products ' )->getCollection ()->addFieldToFilter ('flag ' , 1 );
129
149
foreach ($ collection as $ v ){
130
150
try {
131
151
Mage::getModel ('tindexer/products ' )->initFilteredProductsCount ('brand ' , $ v ->getData ('attr_id ' ), $ v ->getData ('tindexer_id ' ));
0 commit comments