Magento批量复制自身产品分类目录

7天成为Magento系统架构师,现在开始学习Magento全栈开发!

《Magento2.X企业级开发实战》

global->resources->default_setup->connection->host;
$username=$xml->global->resources->default_setup->connection->username;
$password=$xml->global->resources->default_setup->connection->password;
$dbname=$xml->global->resources->default_setup->connection->dbname;
$res=mysql_pconnect($host,$username,$password);
mysql_select_db($dbname);




$catsDone=0;
duplicate_entity($catId);
echo$catsDone.' Categories duplicated.';

function duplicate_entity($id,$parent_id=null){
global$catsDone;


// Grab category to copy
$sql="SELECT * FROM catalog_category_entity WHERE entity_id = ".$id;
$query_entity=mysql_query($sql);

$entity=mysql_fetch_object($query_entity);


if(!$parent_id)$parent_id=$entity->parent_id;




mysql_query("INSERT INTO catalog_category_entity (entity_type_id, attribute_set_id, parent_id, created_at, updated_at, path, position, level, children_count)
VALUES ({$entity->entity_type_id}, {$entity->attribute_set_id}, {$parent_id}, NOW(), NOW(), '', {$entity->position}, {$entity->level}, {$entity->children_count})");
$newEntityId=mysql_insert_id();

$query=mysql_query("SELECT path FROM catalog_category_entity WHERE entity_id = ".$parent_id);
$parent=mysql_fetch_object($query);
$path=$parent->path.'/'.$newEntityId;

mysql_query("UPDATE catalog_category_entity SET path='".$path."' WHERE entity_id=".$newEntityId);


foreach(array('datetime','decimal','int','text','varchar')as$dataType){
$sql="SELECT * FROM catalog_category_entity_".$dataType."
WHERE entity_id=".$entity->entity_id;
//die($sql);
$query=mysql_query($sql);
while($value=mysql_fetch_object($query)){
mysql_query("INSERT INTO catalog_category_entity_".$dataType." (entity_type_id, attribute_id, store_id, entity_id, value)
VALUES ({$value->entity_type_id}, {$value->attribute_id}, {$value->store_id}, {$newEntityId}, '{$value->value}')");
}
}


$sql="SELECT entity_id FROM catalog_category_entity WHERE parent_id = ".$id;
$query=mysql_query($sql);

while($entity=mysql_fetch_object($query)){
duplicate_entity($entity->entity_id,$newEntityId);
}
$catsDone++;
}
?>

转载请注明:(●–●) Hello.My Weicot » Magento批量复制自身产品分类目录

文章来源于互联网:Magento批量复制自身产品分类目录

如无特殊说明或标注,任何个人或组织,复制、转载、采集本站内容请注明:
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。