我试图在我的产品中添加更多的类别,但是一旦创建,该产品只保留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);
结果:
提前感谢!
发布于 2022-06-10 03:48:22
您需要调用updateCategories
函数将产品添加到多个类别中。因此,一旦您的产品被保存,您可以调用此功能。
例如:
$product->updateCategories($array_of_category_ids_here);
https://stackoverflow.com/questions/72571293
复制相似问题