diff --git a/magmi/plugins/extra/itemprocessors/itemindexer/otfindexer.php b/magmi/plugins/extra/itemprocessors/itemindexer/otfindexer.php index cedb60e4..180f854d 100644 --- a/magmi/plugins/extra/itemprocessors/itemindexer/otfindexer.php +++ b/magmi/plugins/extra/itemprocessors/itemindexer/otfindexer.php @@ -11,7 +11,7 @@ class ItemIndexer extends Magmi_ItemProcessor public function getPluginInfo() { return array("name"=>"On the fly indexer","author"=>"Dweeves","version"=>"0.2", - "url"=>$this->pluginDocUrl("On_the_fly_indexer")); + "url"=>$this->pluginDocUrl("On_the_fly_indexer")); } public function getPluginParamNames() @@ -24,12 +24,12 @@ public function initialize($params) $this->_toindex = null; // initialize shortname array for tables $this->tns = array("cpe"=>$this->tablename("catalog_product_entity"), - "cce"=>$this->tablename("catalog_category_entity"),"ccp"=>$this->tablename("catalog_category_product"), - "cpw"=>$this->tablename("catalog_product_website"),"cs"=>$this->tablename("store"), - "csg"=>$this->tablename("store_group"),"cpev"=>$this->tablename("catalog_product_entity_varchar"), - "cpei"=>$this->tablename("catalog_product_entity_int"), - "ccev"=>$this->tablename("catalog_category_entity_varchar"),"ea"=>$this->tablename("eav_attribute"), - "ccpi"=>$this->tablename("catalog_category_product_index"),"curw"=>$this->tablename("url_rewrite")); + "cce"=>$this->tablename("catalog_category_entity"),"ccp"=>$this->tablename("catalog_category_product"), + "cpw"=>$this->tablename("catalog_product_website"),"cs"=>$this->tablename("store"), + "csg"=>$this->tablename("store_group"),"cpev"=>$this->tablename("catalog_product_entity_varchar"), + "cpei"=>$this->tablename("catalog_product_entity_int"), + "ccev"=>$this->tablename("catalog_category_entity_varchar"),"ea"=>$this->tablename("eav_attribute"), + "ccpi"=>$this->tablename("catalog_category_product_index"),"curw"=>$this->tablename("url_rewrite")); $inf = $this->getAttrInfo("visibility"); if ($inf == null) { $this->initAttrInfos(array("visibility")); @@ -178,7 +178,7 @@ public function buildUrlCatProdRewrite($pid, $purlk) // product + category url entries request $catid = $pinfo["catid"]; $sdata = array('product', $pid, $storeid, - "catalog/product/view/id/$pid/category/$catid", "$curlk/$purlk", 0, 1); + "catalog/product/view/id/$pid/category/$catid", "$curlk/$purlk", 0, 1); $vstr[] = "(" . $this->arr2values($sdata) . ")"; $data = array_merge($data, $sdata); } @@ -186,7 +186,7 @@ public function buildUrlCatProdRewrite($pid, $purlk) } if (count($vstr) > 0) { $sqlprodcat = "INSERT IGNORE INTO {$this->tns["curw"]} (entity_type,entity_id,store_id,target_path,request_path,redirect_type,is_autogenerated) VALUES " . - implode(",", $vstr); + implode(",", $vstr); $this->insert($sqlprodcat, $data); } if (count($catpathlist) > 0) { @@ -224,12 +224,12 @@ public function buildCatUrlRewrite($catpathlist, $cnames) } if (count($vstr) > 0) { $sqlcat = "INSERT INTO {$this->tns["curw"]} (entity_type,entity_id,store_id,target_path,request_path,redirect_type,is_autogenerated) VALUES " . - implode(",", $vstr) . " ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`)"; + implode(",", $vstr) . " ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`)"; $this->insert($sqlcat, $data); } } - public function builProductUrlRewrite($pid, $dorewrite=false) + public function builProductUrlRewrite($pid, $dorewrite=false, $store) { //new url @@ -238,8 +238,9 @@ public function builProductUrlRewrite($pid, $dorewrite=false) JOIN {$this->tns["ea"]} as ea ON ea.attribute_code IN ('url_key','name') JOIN {$this->tns["cpev"]} as cpev ON cpev.entity_id=cpe.entity_id AND cpev.attribute_id=ea.attribute_id JOIN {$this->tns["cpei"]} as cpei ON cpei.entity_id=cpe.entity_id AND cpei.attribute_id=? AND cpei.value>1 - WHERE cpe.entity_id=?"; - $result = $this->selectAll($sql, array($this->visinf["attribute_id"], $pid)); + JOIN {$this->tns["cs"]} as s ON cpev.store_id = s.store_id + WHERE cpe.entity_id=? AND s.code=?"; + $result = $this->selectAll($sql, array($this->visinf["attribute_id"], $pid, $store)); // nothing to build, product is not visible,return if (count($result) == 0) { return; @@ -278,7 +279,7 @@ public function builProductUrlRewrite($pid, $dorewrite=false) if ($dorewrite) { //rewrites SQL - $rewurlsql = "SELECT cpe.entity_id,cs.store_id, + $rewurlsql = "SELECT cpe.entity_id,cs.store_id, UUID() as id_path, curw.request_path as target_path, ? AS request_path, @@ -292,8 +293,8 @@ public function builProductUrlRewrite($pid, $dorewrite=false) JOIN {$this->tns["curw"]} as curw ON curw.product_id=cpe.entity_id AND curw.store_id=cs.store_id AND curw.request_path!=? WHERE cpe.entity_id=?"; - //read rewrites - $rewrites=$this->selectAll($rewurlsql, array($purlk, $purlk, $pid)); + //read rewrites + $rewrites=$this->selectAll($rewurlsql, array($purlk, $purlk, $pid)); } // delete old "system" url rewrite entries for product $sql = "DELETE FROM {$this->tns["curw"]} WHERE entity_id=? AND entity_type = 'product' AND is_autogenerated=1"; @@ -322,7 +323,7 @@ public function builProductUrlRewrite($pid, $dorewrite=false) $this->insert($sqlprod, array($purlk, $pid)); - //insert rewrites + //insert rewrites if ($dorewrite && count($rewrites)>0) { $fields=$this->arr2values(array_values($rewrites[0])); $data=array(); @@ -331,8 +332,8 @@ public function builProductUrlRewrite($pid, $dorewrite=false) $data=array_merge($data, array_values($rewrites[$i])); $ins[]="($fields)"; } - //insert rewrites - $sqlrew="INSERT INTO {$this->tns["curw"]} (entity_type,entity_id,store_id,target_path,request_path,redirect_type,is_autogenerated) VALUES ".implode(",", $ins)." ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`)"; + //insert rewrites + $sqlrew="INSERT INTO {$this->tns["curw"]} (entity_type,entity_id,store_id,target_path,request_path,redirect_type,is_autogenerated) VALUES ".implode(",", $ins)." ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`)"; $this->insert($sqlrew, $data); unset($ins); unset($data); @@ -341,9 +342,9 @@ public function builProductUrlRewrite($pid, $dorewrite=false) return $purlk; } - public function buildUrlRewrite($pid, $dorewrite=false) + public function buildUrlRewrite($pid, $dorewrite = false, $store = 'admin') { - $purlk = $this->builProductUrlRewrite($pid, $dorewrite); + $purlk = $this->builProductUrlRewrite($pid, $dorewrite, $store); if ($this->getParam("OTFI:usecatinurl") && !is_null($purlk)) { $this->buildUrlCatProdRewrite($pid, $purlk); } @@ -397,7 +398,7 @@ public function processItemAfterImport(&$item, $params = null) $pid=$params["product_id"]; $dorewrite=isset($item["url_rewrite"]) && $item["url_rewrite"]==1; $this->buildCatalogCategoryProductIndex($pid); - $this->buildUrlRewrite($pid, $dorewrite); + $this->buildUrlRewrite($pid, $dorewrite, $item['store']); } return true; }