I have received a request from one of my clients (he bought this extenstion How to Import Configurable Products into Magento From Google Spreadsheet) asking me to modify the importer script.
Here is the request:
“When I import a configurable product, I want to add a column (or multiple columns) to the CSV file in which I tell the importer the price for each super attribute. ”
Here is how we have implemented it :
Add a new column called super_attributes
and add something like this:
config_attributes : color,size
super_attributes : 5.20,10.2|2.21,3.22
add the following code snippet after $product->save (); the one before return true;
//SUPER ATTRIBUTES
if (! empty ( $importData ['super_attributes'] )) {
$super_attributes = explode('|',$importData["super_attributes"]);
$product = Mage::getModel('catalog/product');
$productid = $product->getIdBySku($importData ['sku']);
$product = Mage::getSingleton("catalog/Product")->load($productid);
if ($data = $product->getTypeInstance()->getConfigurableAttributesAsArray(($product))) {
$counter = 0;
foreach ($data as $attributeData) {
$id = isset($attributeData['id']) ? $attributeData['id'] : null;
$size = sizeof($attributeData['values']);
for($j=0; $j< $size ; $j++){
$attributes = explode(',',$super_attributes[$counter]);
$attributeData['values'][$j]['pricing_value'] = $attributes[$j];
}
$attribute = Mage::getModel('catalog/product_type_configurable_attribute')
->setData($attributeData)
->setId($id)
->setStoreId($product->getStoreId())
->setProductId($productid)
->save();
$counter ++;
}
}
}