Skip to content

Commit

Permalink
Use store id when creatng url rewrites
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Krzyżanowski committed Nov 6, 2018
1 parent f6b370b commit 484a320
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 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,14 +238,16 @@ 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;
}
// see what we get as available product attributes
foreach ($result as $row) {
echo $row;
if ($row["attribute_code"] == "url_key") {
$pburlk = nullifempty($row["value"]);
}
Expand Down Expand Up @@ -278,7 +280,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 +294,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 +324,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 +333,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 +343,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 +399,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 484a320

Please sign in to comment.