我必须为客户制作 Prestashop 网站,所以我必须每天使用脚本导入他们的所有产品。除了我需要启用ps_facetedsearch
模块的属性外,一切都运行良好(类别、产品、照片、功能)。我可以在我的数据库中插入属性值,但我找不到如何将它们分配给产品(这是问题 #1)。然后我需要在我的脚本中配置上述模块,以便这些属性可以在搜索块中显示为过滤器。准确地说,我必须告诉我的过滤器模型中使用了哪些类别,而我不能每天手动进行。
这是我用来将数据作为属性插入的代码($data
是要导入所有数据的对象):
$attributesGroupArray=array('1' => 'Attribute1','2' => 'Attribute2','3' => 'Attribute3','4' => 'Attribute4');
foreach($attributesGroupArray as $id_attribute_group => $name){
$attribute=new Attribute();
$attribute->id_attribute_group=$id_attribute_group;
$attribute->name=array((int)Configuration::get('PS_LANG_DEFAULT') => $data->$name);
$attribute->url_name=array((int)Configuration::get('PS_LANG_DEFAULT') => url_rewrite($data->$name));
$attribute->add();
$attributeid=$attribute->id;
}
关于这两个问题,你能指出我正确的方向吗?
编辑:对于我的问题的第一部分,我接受了以下答案。至于第二部分,我终于找到了正确的代码,所以我会把它放在这里,以防有一天它可以帮助到别人。
$cats=Db::getInstance()->executeS('SELECT id_category FROM `'._DB_PREFIX_.'category` WHERE `id_category`>\'1\'');
foreach($cats as $cle => $resultat){
$comptattribut=0;
$atts=DB::getInstance()->executeS('SELECT id_attribute_group FROM `'._DB_PREFIX_.'attribute_group` ORDER BY position ASC');
foreach($atts as $cleatt => $resultatatt){
$comptattribut++;
DB::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'layered_category` SET `id_shop`=\'1\', `id_category`=\''.$resultat['id_category'].'\', `id_value`=\''.$resultatatt['id_attribute_group'].'\', `type`=\'id_attribute_group\', `position`=\''.$comptattribut.'\', `filter_type`=\'0\', `filter_show_limit`=\'0\'');
}
DB::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'layered_category` SET `id_shop`=\'1\', `id_category`=\''.$resultat['id_category'].'\', `id_value`=NULL, `type`=\'price\', `position`=\''.($comptattribut+1).'\', `filter_type`=\'1\', `filter_show_limit`=\'0\'');
}