@@ -9,7 +9,7 @@ class ItemIndexer extends Magmi_ItemProcessor
9
9
10
10
public function getPluginInfo ()
11
11
{
12
- return array ("name " =>"On the fly indexer " ,"author " =>"Dweeves " ,"version " =>"0.1.8 " ,
12
+ return array ("name " =>"On the fly indexer " ,"author " =>"Dweeves " ,"version " =>"0.2 " ,
13
13
"url " =>$ this ->pluginDocUrl ("On_the_fly_indexer " ));
14
14
}
15
15
@@ -156,7 +156,7 @@ public function buildUrlCatProdRewrite($pid, $purlk)
156
156
JOIN {$ this ->tns ["ea " ]} as ea2 ON ea2.attribute_code ='name' AND ea2.entity_type_id=ea1.entity_type_id
157
157
JOIN {$ this ->tns ["ccev " ]} as ccevd ON ccevd.attribute_id=ea2.attribute_id AND ccevd.entity_id=cce.entity_id AND ccevd.store_id=0
158
158
LEFT JOIN {$ this ->tns ["ccev " ]} as ccev ON ccev.attribute_id=ea2.attribute_id AND ccev.entity_id=cce.entity_id AND ccev.store_id=?
159
- WHERE cce.entity_id IN ( $ catin)
159
+ WHERE cce.entity_id IN ( $ catin) AND cce.level>1
160
160
GROUP BY cce.entity_id " ;
161
161
$ result = $ this ->selectAll ($ sql , array_merge (array ($ storeid ), $ catids ));
162
162
@@ -181,15 +181,17 @@ public function buildUrlCatProdRewrite($pid, $purlk)
181
181
}
182
182
// make string with that
183
183
$ namestr = implode ("/ " , $ names );
184
- // build category url key (allow / in slugging)
185
- $ curlk = Slugger::slug ($ namestr , true );
186
-
187
- // product + category url entries request
188
- $ catid = $ pinfo ["catid " ];
189
- $ sdata = array ($ pid ,$ storeid ,$ catid ,"product/ $ pid/ $ catid " ,
190
- "catalog/product/view/id/ $ pid/category/ $ catid " ,"$ curlk/ $ purlk " ,1 );
191
- $ vstr [] = "( " . $ this ->arr2values ($ sdata ) . ") " ;
192
- $ data = array_merge ($ data , $ sdata );
184
+ if ($ namestr !="" ) {
185
+ // build category url key (allow / in slugging)
186
+ $ curlk = Slugger::slug ($ namestr , true );
187
+
188
+ // product + category url entries request
189
+ $ catid = $ pinfo ["catid " ];
190
+ $ sdata = array ($ pid , $ storeid , $ catid , "product/ $ pid/ $ catid " ,
191
+ "catalog/product/view/id/ $ pid/category/ $ catid " , "$ curlk/ $ purlk " , 1 );
192
+ $ vstr [] = "( " . $ this ->arr2values ($ sdata ) . ") " ;
193
+ $ data = array_merge ($ data , $ sdata );
194
+ }
193
195
}
194
196
}
195
197
if (count ($ vstr ) > 0 )
@@ -244,8 +246,10 @@ public function buildCatUrlRewrite($catpathlist, $cnames)
244
246
}
245
247
}
246
248
247
- public function builProductUrlRewrite ($ pid )
249
+ public function builProductUrlRewrite ($ pid, $ dorewrite = false )
248
250
{
251
+
252
+ //new url
249
253
$ sql = "SELECT ea.attribute_code,cpei.value,cpev.attribute_id,cpev.value
250
254
FROM {$ this ->tns ["cpe " ]} AS cpe
251
255
JOIN {$ this ->tns ["ea " ]} as ea ON ea.attribute_code IN ('url_key','name')
@@ -273,11 +277,32 @@ public function builProductUrlRewrite($pid)
273
277
// if we've got an url key use it, otherwise , make a slug from the product name as url key
274
278
$ urlend =$ this ->getParam ("OTFI:useurlending " ,1 )==1 ?$ this ->getParam ("OTFI:urlending " , ".html " ):"" ;
275
279
$ purlk = (isset ($ pburlk ) ? $ pburlk : Slugger::slug ($ pname )) . $ urlend ;
276
-
280
+ $ rewrites =array ();
281
+
282
+ if ($ dorewrite ) {
283
+ //rewrites SQL
284
+ $ rewurlsql = "SELECT cpe.entity_id,cs.store_id,
285
+ UUID() as id_path,
286
+ curw.request_path as target_path,
287
+ ? AS request_path,
288
+ 0 as is_system,
289
+ 'RP' as options
290
+ FROM {$ this ->tns ["cpe " ]} as cpe
291
+ JOIN {$ this ->tns ["cpw " ]} as cpw ON cpw.product_id=cpe.entity_id
292
+ JOIN {$ this ->tns ["cs " ]} as cs ON cs.website_id=cpw.website_id
293
+ JOIN {$ this ->tns ["ccp " ]} as ccp ON ccp.product_id=cpe.entity_id
294
+ JOIN {$ this ->tns ["cce " ]} as cce ON ccp.category_id=cce.entity_id
295
+ JOIN {$ this ->tns ["curw " ]} as curw ON curw.product_id=cpe.entity_id
296
+ AND curw.store_id=cs.store_id AND curw.request_path!=?
297
+ WHERE cpe.entity_id=? " ;
298
+ //read rewrites
299
+ $ rewrites =$ this ->selectAll ($ rewurlsql ,array ($ purlk ,$ purlk ,$ pid ));
300
+ }
277
301
// delete old "system" url rewrite entries for product
278
302
$ sql = "DELETE FROM {$ this ->tns ["curw " ]} WHERE product_id=? AND is_system=1 " ;
279
303
$ this ->delete ($ sql , $ pid );
280
-
304
+
305
+
281
306
// product url index info
282
307
$ produrlsql = "SELECT cpe.entity_id,cs.store_id,
283
308
CONCAT('product/',cpe.entity_id) as id_path,
@@ -291,15 +316,38 @@ public function builProductUrlRewrite($pid)
291
316
JOIN {$ this ->tns ["cce " ]} as cce ON ccp.category_id=cce.entity_id
292
317
WHERE cpe.entity_id=? " ;
293
318
319
+
294
320
// insert lines
295
321
$ sqlprod = "INSERT INTO {$ this ->tns ["curw " ]} (product_id,store_id,id_path,target_path,request_path,is_system) $ produrlsql ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`) " ;
322
+
296
323
$ this ->insert ($ sqlprod , array ($ purlk ,$ pid ));
324
+
325
+ //insert rewrites
326
+ if (count ($ rewrites )>0 )
327
+ {
328
+
329
+ $ fields =$ this ->arr2values (array_values ($ rewrites [0 ]));
330
+ $ data =array ();
331
+ $ ins =array ();
332
+ for ($ i =0 ;$ i <count ($ rewrites );$ i ++)
333
+ {
334
+ $ data =array_merge ($ data ,array_values ($ rewrites [$ i ]));
335
+ $ ins []="( $ fields) " ;
336
+ }
337
+ //insert rewrites
338
+ $ sqlrew ="INSERT INTO {$ this ->tns ["curw " ]} (product_id,store_id,id_path,target_path,request_path,is_system,options) VALUES " .implode (", " ,$ ins )." ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`) " ;
339
+ $ this ->insert ($ sqlrew ,$ data );
340
+ unset($ ins );
341
+ unset($ data );
342
+ }
343
+
297
344
return $ purlk ;
345
+
298
346
}
299
347
300
- public function buildUrlRewrite ($ pid )
348
+ public function buildUrlRewrite ($ pid, $ dorewrite = false )
301
349
{
302
- $ purlk = $ this ->builProductUrlRewrite ($ pid );
350
+ $ purlk = $ this ->builProductUrlRewrite ($ pid, $ dorewrite );
303
351
if ($ this ->getParam ("OTFI:usecatinurl " ))
304
352
{
305
353
$ this ->buildUrlCatProdRewrite ($ pid , $ purlk );
@@ -353,8 +401,9 @@ public function processItemAfterImport(&$item, $params = null)
353
401
if (count ($ item ) > 0 )
354
402
{
355
403
$ pid =$ params ["product_id " ];
404
+ $ dorewrite =isset ($ item ["url_rewrite " ]) && $ item ["url_rewrite " ]==1 ;
356
405
$ this ->buildCatalogCategoryProductIndex ($ pid );
357
- $ this ->buildUrlRewrite ($ pid );
406
+ $ this ->buildUrlRewrite ($ pid, $ dorewrite );
358
407
}
359
408
return true ;
360
409
}
0 commit comments