php 添加产品组合

pgccezyw  于 5个月前  发布在  PHP
关注(0)|答案(1)|浏览(68)

我在做一个Prestashop模块,我需要添加大小组合
我正在做这个`$product = new Product($idProduct);

$attribute = new ProductAttribute();
    $attribute->name = $attributeName;
    $attribute->public_name = $attributeName;
    $attribute->add();

    $idAtributoTalla = (int)$attribute->id;

    $attributeValue = new AttributeGroup();
    $attributeValue->id_attribute_group = $idAtributoTalla;
    $attributeValue->name = array_fill(0, Language::getLanguages(false, false), $attributeValue);
    $attributeValue->position = ProductAttribute::getHigherPosition($idAtributoTalla) + 1;
    $attributeValue->add();

    $product->update();

    $product->addProductAttributeCombination($idAtributoTalla, array($idAtributoTalla));

    $product->update();`

字符串
但是当我执行代码时,我有一个错误:ProductAttribute->id_attribute_group属性为空。
我试图手动添加一个组ID,但没有工作

gtlvzcf8

gtlvzcf81#

您正在调用$attribute->add(),但没有指定id_attribute_group属性。这是必需的属性,如果没有此属性,则无法添加新的ProductAttribute。
ProductAttribute对象模型被Map到表attribute,这是您的场景中的“大小号”(例如:37、38、39)。它必须被Map到AttributeGroup对象模型。

相关问题