Magento API. Import simple+configurable products. Program doesn’t create super attribute options. 

Please LogIn to Reply!

Post By: admin | 26-01-2012 06:35 Reply

 

I found code example here : http://www.stephenrhoades.com/?p=338
Made some little changes. And what happens is: script creates 3 products, it links them(so catalog_product_relation has entries), BUT it doesn’t creates options for attribute. How I can fix it?
Magento version is 1.6.0.0 stable.
Server is localhost.

public function run(){
        $newProductData 
= array(
            
'name'                     => 'Product Name 1',
            
'websites'                  => array(1),
            
'description'               => 'a',        
            
'short_description'               => 'a',        
            
'price'                     => 9.99,
            
'category_ids'        => '',
            
'visibility'            => 4,
            
'status'                => 1,
            
'weight'                => 1,
            
'tax_class_id'            => 0,
        );
        
$productOne $this->doProductMigration('simple'4'SKU_VALUE1'$newProductData);
        
$newProductData = array(
            
'name'                     => 'Product Name 2',
            
'websites'                  => array(1),
            
'description'               => 'a',        
            
'short_description'               => 'a',        
            
'price'                     => 9.99,
            
'category_ids'        => '',
            
'visibility'            => 4,
            
'status'                => 1,
            
'weight'                => 1,
            
'tax_class_id'            => 0,
        );
        
$productTwo $this->doProductMigration('simple'4'SKU_VALUE2'$newProductData);         
        
//Create the configurable products data
        
$configurableProductsData = array(
            
$productOne['product_id'=> array(
                
'attribute_id'        => 83//The attribute id
                
'label'                => 'Red',
                
'value_index'        => false//The option id
                
'is_percent'        => 0,
                
'pricing_value'        => ''
            
),
            
$productTwo['product_id'=> array(
                
'attribute_id'        => 83//The attribute id
                
'label'                => 'Blue',
                
'value_index'        => false//The option id     
                
'is_percent'        => 0,
                
'pricing_value'        => ''    
            
)
        );         
        
//Create the configurable attributes data
        
$configurableAttributesData = array(
            
'0'    => array(
                
'id'                 => NULL,
                
'label'            => ''//optional, will be replaced by the modified api.php
                
'position'            => NULL,
                
'values'            => array(
                    
=> array(
                        
'attribute_id'        => 83//The attribute id
                        
'label'                => 'Red',
                        
'value_index'        => false//The option id
                        
'is_percent'        => 0,
                        
'pricing_value'        => ''                
                    
),
                    
=> array(
                        
'attribute_id'        => 83//The attribute id
                        
'label'                => 'Blue',
                        
'value_index'        => false//The option id     
                        
'is_percent'        => 0,
                        
'pricing_value'        => ''                            
                    
)
                ),
                
'attribute_id'         => 83//get this value from attributes api call
                
'attribute_code'            => 'color'//get this value from attributes api call
                
'frontend_label'            => ''//optional, will be replaced by the modifed api.php
                
'html_id'            => 'config_super_product__attribute_0'
            
)
        );         
        
//add configurable product
        
$newProductData = array(
            
'name'                                  => 'Product Group Name',
            
'websites'                              => array(1), 
            
'description'                           => 'Group description',        
            
'short_description'                           => 'Short Group description',        
            
'category_ids'                => '',
            
'visibility'                    => 4,
            
'status'                    => 1,
            
'price'                                 => 9.99,                
            
'tax_class_id'                => 0,
            
'weight'                    => 0,
            
'configurable_products_data'     => $configurableProductsData,
            
'configurable_attributes_data'     => $configurableAttributesData        
        
);    
        
$result $this->doProductMigration('configurable'4"GROUP-SKU"$newProductData); 
    
}

 

You solve the problem?!

`Reply Or Comment!
Please LogIn to Reply!