也许你们中一些使用 prestashop 核心类的人知道如何创建具有自定义属性的产品?我的意思是通过以编程方式创建使用 prestashop 类的脚本来在 prestashop 系统中添加新产品。
最佳答案
他的代码工作正常。如果您以编程方式创建新属性,请使用以下代码添加新属性并获取 $idProductAttribute
use PrestaShop\PrestaShop\Adapter\Import\ImportDataFormatter;
$newGroup = new AttributeGroup();
$newGroup->name = ImportDataFormatter::createMultiLangField('test');
$newGroup->public_name = ImportDataFormatter::createMultiLangField('test');
$newGroup->group_type = 'select';
$newGroup->add();
$newAttribute = new Attribute();
$newAttribute->name = ImportDataFormatter::createMultiLangField('test');
$newAttribute->id_attribute_group = $newGroup->id;
$newAttribute->add();
$idProductAttribute = $product->addProductAttribute($price,
$weight,
$unit_impact,
$ecotax,
$quantity,
$id_images,
$reference,
$id_supplier,
$ean13,
$default,
$location,
$upc,
$minimal_quantity,
$isbn,
$low_stock_threshold,
$low_stock_alert);
$product->addAttributeCombinaison($idProductAttribute, array($newAttribute->id_attribute_group));
这对我有用。
关于module - 如何以编程方式创建具有自定义属性的 Prestashop 产品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26131536/