Skip to content

Commit

Permalink
Merge pull request #37 from n0kit31/magento2
Browse files Browse the repository at this point in the history
Use store id when creatng url rewrites
  • Loading branch information
idziakjakub authored Apr 19, 2019
2 parents 5f8e55d + a4d29b4 commit 0bd54bb
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions magmi/plugins/extra/itemprocessors/itemindexer/otfindexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"));
Expand Down Expand Up @@ -178,15 +178,15 @@ 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);
}
}
}
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) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 0bd54bb

Please sign in to comment.