Reputation: 154
I created new product with prestashop core classes with an import script. Now I have to generate programmatically the combinations of these products with a standard set of attributes. What prestashop core functions can I use?
Upvotes: 2
Views: 3904
Reputation: 203
I also made a import script and i made these two loop in one of my method
$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 {
}
Upvotes: 3