Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在PrestaShop上创建产品时添加类别_Php_Model View Controller_Prestashop_Prestashop 1.6 - Fatal编程技术网

Php 在PrestaShop上创建产品时添加类别

Php 在PrestaShop上创建产品时添加类别,php,model-view-controller,prestashop,prestashop-1.6,Php,Model View Controller,Prestashop,Prestashop 1.6,我正在PrestaShop 1.6上创建导入模块产品。产品创建时没有问题,但不包括类别 我用过: $product->id_category = array(); foreach($arr_cat_full as $cat){ $category = Category::searchByName(1, trim($cat), true); $product->id_category[] = (int)$categor

我正在PrestaShop 1.6上创建导入模块产品。产品创建时没有问题,但不包括类别

我用过:

$product->id_category = array();
foreach($arr_cat_full as $cat){                          
    $category = Category::searchByName(1, trim($cat), true);
    $product->id_category[] = (int)$category['id_category'];                       
}
如果我进入:

var_dump($category['id_category']);

结果是正确的。

您必须使用
Product
类的
addToCategories($categories=array())
函数

以这种方式使用:

$array_cc = array();
$product->id_category = array();
foreach($arr_cat_full as $cat){                          
        $category = Category::searchByName(1, trim($cat), true);
        $array_cc = (int)$category['id_category'];                       
}

$product->add();
$product->addToCategories($array_cc);
祝你好运