【问题标题】:Prestashop - Add multiple categories to a productPrestashop - 为产品添加多个类别
【发布时间】:2022-06-10 19:48:22
【问题描述】:

我正在尝试在我的产品中添加更多类别,但一旦创建,产品只保留 id_cetegory_default。

我的代码:

$xml = simplexml_load_file('php://input');
$product = new Product($xml->id);
$product->category = [2,7];
$product->id_category_default = (int)$xml->id_category_default; //categories
$product->name = $xml->name; //nom produit
$product->price = $xml->price; //prix
$product->id_tax_rules_group = (int)$xml->id_tax_rules_group;
$product->ean13 = $xml->ean13; //code barre
$product->description = $xml->description; //description
$product->description_short = $xml->description_short; //petite description
$product->reference = $xml->reference; //reference
$product->weight = $xml->weight; //poids
$product->height = $xml->height; //hauteur
$product->width = $xml->width; //largeur
$product->depth = $xml->depth; //profondeur
$product->indexed = 1;
$product->active = true;
$product->save();
$e = $product->getDefaultIdProductAttribute();
StockAvailable::setQuantity($product->id, $e, $xml->quantity);
$image = new Image();
$image->id_product = $product->id;
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = true;
$image->add();
AdminImportControllerCore::copyImg((int)$product->id, (int)$image->id, $xml->urlImage, 'products', false);

结果:

提前致谢!

【问题讨论】:

    标签: php prestashop


    【解决方案1】:

    您需要调用updateCategories 函数将产品添加到多个类别中。因此,一旦您的产品得到保存;你可以调用这个函数。

    例如:

    $product->updateCategories($array_of_category_ids_here);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      相关资源
      最近更新 更多