opencart导入分类扩展的代码思路

通过清心醉

opencart导入分类扩展的代码思路

作者封装的OPENCART导入其他网站的分类的信息,需要提供PDO的连接参数和导入的7个数据参数.

class Category_PHP
{
public $pdo; //私有数据成员PDO连接
private $dbname;
private $user;
private $password;
private $pre;

/**
* 构造方法获取PDO的连接参数
* @return PDO
*/
function __construct()
{
#################
#参数初始化开始
##################
$this->pre=’mmc_’;
$this->dbname=’opencart’;
$this->user=’root’;
$this->password=”;
#################
#参数初始化结束
##################
$pdo=new PDO (“mysql:host=localhost;dbname=$this->dbname;charset=utf8”,$this->user,$this->password);
return $this->pdo=$pdo;
}

/**
* 表前缀组合,返回一个数据表名称
* @param unknown $table
* @return string
*/
protected function table($table)
{
return “$this->pre”.”$table”;
}

/**
* 写入数据库分类表  根分类
* @param unknown $data
*/
protected function insert_opencart_calss($data=array())
{
/**
* 以下7个参数为必填项,比如url可以自己重新组合
*/
$id=$data[‘1’];  //分类的ID
$mixid=$data[‘2’];  //分类的上级ID
$name=$data[‘3’]; //名称
$description=$data[‘4’]; //元描述
$keywords=$data[‘5’]; //关键字组合
$title=$data[‘6’]; //元标题
$url=$data[‘7’]; //伪静态的URL

$time=date(“Y-m-d H:i:s”);
$this->category($id,$time,$time);
$this->category_path($id,$mixid); //写入目录扩展
$this->category_url($id, $url); //写入重写URL
$this->category_description($id, $name, $description, $keywords, $title); //写入产品的详细信息
$this->category_to_layout($id); //写入分类的布局
$this->category_to_store($id); //写入分类的店铺

}

#########################################################################################
#    写入分类的其他扩展开始(不管根分类还是子分类)
#########################################################################################
/**
* 写入category_description分类详细扩展
* 需要分类ID,分类名称,分类描述(分类元描述)
* @param unknown $id
* @param unknown $name
* @param unknown $description
* @param unknown $keywords
* @param unknown $title
*/
protected function category($id,$time,$time)
{
$table=$this->table(‘category’); //获取分类数据表
$sql=”INSERT INTO $table (`category_id`, `parent_id`, `top`, `column`, `sort_order`, `status`, `date_added`, `date_modified`)
VALUES (‘$id’, ‘0’, ‘1’, ‘1’, ‘1’, ‘1’, ‘$time’,’$time’)”;
$this->pdo->exec($sql);
}

protected function category_description($id,$name,$description,$keywords,$title)
{
$table=$this->table(‘category_description’);
$sql=”INSERT INTO $table(`category_id`,`language_id`,`name`,`description`,`meta_title`,`meta_keyword`,`meta_description`)
VALUES(‘$id’,’1′,’$name’,’$description’,’$title’,’$keywords’,’$description’)”;
$this->pdo->exec($sql);
}
/**
* 写入category_path目录数据表扩展
* @param unknown $id
* @param unknown $pathid
*/
protected function category_path($id=0,$pathid=0)
{
$table=$this->table(‘category_path’);
if ($pathid==0) //如果父ID==0
{
$sql=”INSERT INTO $table(`category_id`,`path_id`,`level`)VALUES(‘$id’,’$id’,’0′)”;
}
else
{
$sql=”INSERT INTO $table(`category_id`,`path_id`,`level`)VALUES(‘$id’,’$pathid’,’0′)”;
}
$this->pdo->exec($sql);
}
/**
* 重写分类的URL格式
* @param unknown $id
* @param unknown $url
*/
protected function category_url($id,$url)
{
$table=$this->table(‘url_alias’);
$urlid=”category_id=”.”$id”; //分类的ID
$sql=”INSERT INTO $table(`query`,`keyword`,`language_id`)VALUES(‘$urlid’,’$url’,’1′)”;
$this->pdo->exec($sql);
}

/**
* 写入分类的布局
* @param unknown $id
*/
protected function category_to_layout($id)
{
$table=$this->table(‘category_to_layout’);
$sql=”INSERT INTO $table(`category_id`,`store_id`,`layout_id`)VALUES(‘$id’,’0′,’0′)”;
$this->pdo->exec($sql);
}
/**
* 写入分类对应的店铺
* @param unknown $id
*/
protected function category_to_store($id)
{
$table=$this->table(‘category_to_store’);
$sql=”INSERT INTO $table(`category_id`,`store_id`)VALUES(‘$id’,’0′)”;
$this->pdo->exec($sql);
}
#########################################################################################
#    写入分类的其他扩展结束(不管根分类还是子分类)
#########################################################################################
}

关于作者

清心醉 administrator

发表评论

如果喜欢作者的文章,您可以打赏给作者:

TRC20(虚拟货币):


ERC20(虚拟货币):


Bitcoin(BTC):