im using an import script that import's simple and configurable product to magento from xml.
The problem is that, imported simple products are i magento but they don't have attributes values assigned.
Import via APIv2 is working well bu it is to slow, that why i need to do this on model.
my question is: Is This (code below) correct ? Meybe you have better, different metod to assigne attribute value to product :-)
$product->setData('rozmiar',$Products['sizeId']);
$product->setData('kolor',$Products['colorId']);
my code:
$productCheck = Mage::getModel('catalog/product')->loadByAttribute('sku', $products['sku']);
if ($productCheck) {
$productCheck->delete();
//print_r('true !');
}
$color = attributeValueExists1('kolor',$Products['color']);
$size = attributeValueExists1('rozmiar',$Products['size']);
$product = Mage::getModel('catalog/product');
$product->setCreatedAt(strtotime('now'));
$product->setTypeId($products['type']);
$product->setTaxClassId(0);
$product->setWebsiteIds(array(1));
$product->setAttributeSetId($products['attrset']);
$product->setSku($products['sku']);
$product->setName($products['name']);
$product->setDescription($products['description']);
$product->setInDepth('');
$product->setPrice($products['price']);
$product->setShortDescription($products['description']);
$product->setWeight(0);
$product->setStatus(1);
$product->setVisibility(1);
//$product->setMetaDescription($products['name']);
//$product->setMetaTitle($products['name']);
//$product->setMetaKeywords($products['name']);
$product->setCategoryIds($products['categories']);
$product->setKolor($color);
$product->setRozmiar($size);
//$product->setData('rozmiar',$Products['size']);
//$product->setData('kolor',$Products['color']);
$product->setStockData(array(
'use_config_manage_stock' => 0,
'manage_stock'=>1,
'min_sale_qty'=>1,
//'max_sale_qty'=>2,
'is_in_stock' => 1,
'qty' => $products['qty']
)
);
$product->save();
Importing products via Soap APIv2 im using
$result = $this->client2->catalogProductCreate($this->session, $type, /*$attributeSet['set_id']*/ '4', $kod, array(
'categories' => $kategorie, // array !!!!
'websites' => array(1),
'name' => $nazwa,
'description' => $opis,
'short_description' => $opis,
'weight' => '1',
'status' => '1',
'url_key' => $nazwa,
'url_path' => $nazwa,
'visibility' => '1',
'price' => $cena,
'tax_class_id' => 1,
'meta_title' => '',
'meta_keyword' => '',
'meta_description' => '',
'stock_data' => array( 'manage_stock' => '1',
'manage_stockSpecified' => False,
'is_in_stock' => '1',
'is_in_StockSpecified' => False,
'qty' => $ilosc
),
'additional_attributes' => $additionalattr
));
return $result;
Is additional_attributes different from $product->setData('rozmiar',$Products['sizeID']); ? If it's not the same how can i add additional_attributes when importing products via catalog/product model ?
First you need to assign corresponding attributes to products. Then after you can use import script to save those attributes value to products.