Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilanguage Category Import - Error on a sql query #69

Open
wants to merge 15 commits into
base: magento2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Join the chat at https://gitter.im/dweeves/magmi-git](https://badges.gitter.im/dweeves/magmi-git.svg)](https://gitter.im/dweeves/magmi-git?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FCTC7R3YUJVPQ)

magmi-git 0.7.23
===
Expand Down
4 changes: 2 additions & 2 deletions magmi/engines/magmi_productimportengine.php
Original file line number Diff line number Diff line change
Expand Up @@ -1678,13 +1678,13 @@ public function createAttributes($pid, &$item, $attmap, $isnew, $itemids)
}
}
// if we have something to do with this value
if ($ovalue !== false && $ovalue != null)
if ($ovalue !== false && $ovalue !== null)
{
$data[] = $this->getProductEntityType();
$data[] = $attid;
$data[] = $store_id;
$data[] = $pid;
$data[] = $ovalue == '__NULL__' ? null : $ovalue;
$data[] = $ovalue === '__NULL__' ? null : $ovalue;
$insstr = "(?,?,?,?,?)";
$inserts[] = $insstr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ protected function _createOptions($item, $params)

if (!empty($option['title'])) {
if (empty($existingOption['title'])) {
$sql = "INSERT INTO $optv (option_id, store_id, title) VALUES(:option_id, :store_id, :title)";
$sql = "INSERT INTO $optv (option_id, store_id, title,parent_product_id) VALUES(:option_id, :store_id, :title, :parent_product_id)";
$bind = array('option_id'=>$option['option_id'],'store_id'=>$option['store_id'],
'title'=>$option['title']);
'title'=>$option['title'],'parent_product_id' => $option['parent_id']);
$this->insert($sql, $bind);
} elseif ($existingOption['title'] != $option['title']) {
$sql = "UPDATE $optv SET title = :title WHERE option_id = :option_id AND store_id = :store_id";
Expand All @@ -181,13 +181,13 @@ protected function _createOptions($item, $params)
$optionId = $this->insert($sql, $bind);
$option['option_id'] = $optionId;

$sql = "INSERT INTO $optv (option_id, store_id, title) VALUES(:option_id, :store_id, :title)";
$bind = array('option_id'=>$option['option_id'],'store_id'=>0,'title'=>$option['code']);
$sql = "INSERT INTO $optv (option_id, store_id, title, parent_product_id) VALUES(:option_id, :store_id, :title, :parent_product_id)";
$bind = array('option_id'=>$option['option_id'],'store_id'=>0,'title'=>$option['code'],'parent_product_id' => $option['parent_id']);
$this->insert($sql, $bind);

if (!empty($option['title']) && $option['store_id'] != 0) {
$bind = array('option_id'=>$option['option_id'],'store_id'=>$option['store_id'],
'title'=>$option['title']);
'title'=>$option['title'],'parent_product_id' => $option['parent_id']);
$this->insert($sql, $bind);
}
}
Expand Down
74 changes: 37 additions & 37 deletions magmi/plugins/extra/itemprocessors/categories/categoryimport.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function initialize($params)

public function initStores()
{
$sql = 'SELECT store_id AS id, code FROM ' . $this->tablename('core_store');
$sql = 'SELECT store_id AS id, code FROM ' . $this->tablename('store');
$stores = $this->selectAll($sql, null, 'code');
$this->stores = array_reduce($stores, function ($result, $store) {
$result[$store['code']] = $store['id'];
Expand All @@ -56,31 +56,27 @@ public function initStores()
*/
public function initCats()
{
// zioigor - 20110426 missing call to tablename method for table_prfix
$t = $this->tablename("catalog_category_entity");
$csg = $this->tablename("core_store_group");
$cs = $this->tablename("core_store");
$ccev = $t . "_varchar";
$ea = $this->tablename("eav_attribute");

$t = $this->tablename("catalog_category_entity");
$csg = $this->tablename("store_group");
$cs = $this->tablename("store");
$ccev = $t . "_varchar";
$ea = $this->tablename("eav_attribute");
$result = $this->selectAll(
"SELECT cs.store_id,csg.website_id,cce.entity_type_id,cce.path,ccev.value as name
FROM $cs as cs
JOIN $csg as csg on csg.group_id=cs.group_id
JOIN $t as cce ON cce.entity_id=csg.root_category_id
JOIN $ea as ea ON ea.attribute_code='name' AND ea.entity_type_id=cce.entity_type_id
JOIN $ccev as ccev ON ccev.attribute_id=ea.attribute_id AND ccev.entity_id=cce.entity_id
");
"SELECT cs.store_id,csg.website_id,cce.path,ccev.value as name
FROM $cs as cs
JOIN $csg as csg on csg.group_id=cs.group_id
JOIN $t as cce ON cce.entity_id=csg.root_category_id
JOIN $ea as ea ON ea.attribute_code='name'
JOIN $ccev as ccev ON ccev.attribute_id=ea.attribute_id AND ccev.entity_id=cce.entity_id
");
foreach ($result as $row) {
$rootinfo = array(
"path" => $row["path"],
"etid" => $row["entity_type_id"],
"name" => $row["name"],
"rootarr" => explode("/", $row["path"])
);
$rootinfo = array("path"=>$row["path"],"name"=>$row["name"],
"rootarr"=>explode("/", $row["path"]));
$this->_catroots[$row["store_id"]] = $rootinfo;
$this->_catrootw[$row["website_id"]][] = $row["store_id"];
if ($this->_cat_eid == null) {
$this->_cat_eid = $row["entity_type_id"];
// $this->_cat_eid = $row["entity_type_id"];
}
}
}
Expand All @@ -91,8 +87,9 @@ public function initCats()
public function getCatAttributeInfos($attcode)
{
$t = $this->tablename("eav_attribute");
$sql = "SELECT * FROM $t WHERE entity_type_id=? AND attribute_code=?";
$info = $this->selectAll($sql, array($this->_cat_eid, $attcode));
$sql = "SELECT * FROM $t WHERE attribute_code=?";

$info = $this->selectAll($sql, array($attcode));
return $info[0];
}

Expand Down Expand Up @@ -165,17 +162,17 @@ public function getCategoryId($parentpath, $cattrs)
$path = implode("/", $parentpath);
$parentid = array_pop($parentpath);
// get child info using parent data
$sql = "SELECT cce.entity_type_id,cce.attribute_set_id,cce.level+1 as level,COALESCE(MAX(eac.position),0)+1 as position
FROM $cet as cce
LEFT JOIN $cet as eac ON eac.parent_id=cce.entity_id
WHERE cce.entity_id=?
GROUP BY eac.parent_id";
$sql = "SELECT cce.attribute_set_id,cce.level+1 as level,COALESCE(MAX(eac.position),0)+1 as position
FROM $cet as cce
LEFT JOIN $cet as eac ON eac.parent_id=cce.entity_id
WHERE cce.entity_id=?
GROUP BY eac.parent_id";
$info = $this->selectAll($sql, array($parentid));
$info = $info[0];
// insert new category
$sql = "INSERT INTO $cet (entity_type_id,attribute_set_id,parent_id,position,level,path,children_count) VALUES (?,?,?,?,?,?,?)";
$sql = "INSERT INTO $cet (attribute_set_id,parent_id,position,level,path,children_count) VALUES (?,?,?,?,?,?)";
// insert empty path until we get category id
$data = array($info["entity_type_id"],$info["attribute_set_id"],$parentid,$info["position"],$info["level"],"",0);
$data = array($info["attribute_set_id"],$parentid,$info["position"],$info["level"],"",0);
// insert in db,get cat id
$catid = $this->insert($sql, $data);

Expand All @@ -193,16 +190,15 @@ public function getCategoryId($parentpath, $cattrs)

foreach ($attinfo as $attrcode => $attdata) {
if (isset($attdata["attribute_id"])) {
$inserts[] = "(?,?,?,?,?)";
$data[] = $info["entity_type_id"];
$inserts[] = "(?,?,?,?)";
$data[] = $attdata["attribute_id"];
$data[] = 0; // store id 0 for categories
$data[] = $catid;
$data[] = $cattrs[$attrcode];
}
}

$sql = "INSERT INTO $tb (entity_type_id,attribute_id,store_id,entity_id,value) VALUES " .
$sql = "INSERT INTO $tb (attribute_id,store_id,entity_id,value) VALUES " .
implode(",", $inserts) . " ON DUPLICATE KEY UPDATE value=VALUES(`value`)";
$this->insert($sql, $data);
unset($data);
Expand Down Expand Up @@ -304,6 +300,8 @@ public function getCategoryIdsFromDef($pcatdef, $srdefs, $item)
} else {
$catpos[] = "0";
}
} else {
$catpos[] = "0";
}
$translation_option = array_values(array_filter($a, function ($option) { return stripos($option, '[') === 0; }));
$translation_option_part = count($translation_option) ? '::' . $translation_option[0] : '';
Expand Down Expand Up @@ -407,18 +405,20 @@ public function updateOrCreateAttributes($category_id, $attributes, $store_id =

foreach ($attinfo as $attrcode => $attdata) {
if (isset($attdata['attribute_id'])) {
$placeholders[] = '(?,?,?,?,?)';
$values[] = $this->_cat_eid;//$info['entity_type_id'];
$placeholders[] = '(?,?,?,?)'; //berto - fix query error
//$values[] = $this->_cat_eid;//$info['entity_type_id']; //berto - fix query error
$values[] = $attdata['attribute_id'];
$values[] = $store_id;
$values[] = $category_id;
$values[] = $attributes[$attrcode];
}
}

$sql = "INSERT INTO $table (entity_type_id,attribute_id,store_id,entity_id,value) VALUES " .
//berto - fix query error
$sql = "INSERT INTO $table (attribute_id,store_id,entity_id,value) VALUES " .
implode(",", $placeholders) . " ON DUPLICATE KEY UPDATE value=VALUES(`value`)";
$this->insert($sql, $values);


}
}

Expand Down
2 changes: 1 addition & 1 deletion magmi/web/ajax_gettime.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
echo $_REQUEST["prefix"] . ":" . strftime("%c");
echo htmlspecialchars($_REQUEST["prefix"]).":".strftime("%c");