以编程方式创建组合 - Prestashop 1.6

Programmatically Creating Combinations- Prestashop 1.6

我使用 prestashop 核心 类 和导入脚本创建了新产品。现在我必须以编程方式生成这些产品与一组标准属性的组合。 我可以使用哪些 Prestashop 核心功能?

我还制作了一个导入脚本,并在我的方法之一中制作了这两个循环

    $iDefaultLangId = Configuration::get('PS_LANG_DEFAULT');
        foreach($aAttributeValues as $sValue) {

            if(!Attribute::isAttribute($iAttributeId, $sValue, $iDefaultLangId)) {
                $oAttribute = new Attribute();
                $oAttribute->id_attribute_group = $iAttributeId;
                $oAttribute->name = array();

                $oAttribute->name[3] = $sValue; //this is the is of your lang

                $oAttribute->add();

                echo "create attribute <br>";

            }
        }

        foreach(AttributeGroup::getAttributes($iDefaultLangId, $iAttributeId) as $aAttribute) {
            if(in_array($aAttribute['name'], $aAttributeValues)) {



                if(!$oProduct->productAttributeExists(array($aAttribute['id_attribute']))) {

                    echo "add combination with quantity " . $combQty ." e valore " . $aAttributeValues[0] . " <br>";

                    if ( $ref != false){

                        $id_product_attribute = $oProduct->addCombinationEntity($oProduct->price, 0, 0, 0, 0, 1, array(), $ref, 0, $combEan, false);

                    } else {

                        $id_product_attribute = $oProduct->addCombinationEntity($oProduct->price, 0, 0, 0, 0, 1, array(), $aAttribute['name'], 0, $combEan, false);

                    }



                    $combination = new Combination((int)$id_product_attribute);

                    $combination->setAttributes(array($aAttribute['id_attribute']));

                    $this->_setQuantity($oProduct->id, $combination->id, $combQty );

                } else {


                }