Magento Forum

Page 17 of 17
Configurable Products? 
 
nabler
Sr. Member
 
Total Posts:  80
Joined:  2010-07-27
 

Thnx For All awose member finally i made it....
this is really sweet victory you all really save my ass..

 
Magento Community Magento Community
Magento Community
Magento Community
 
Diogo Barioni Abdalla
Member
 
Total Posts:  44
Joined:  2009-03-25
 

Hello,

I am a php developer customizing a Magento store for the first time. My client has a store with around 5 thousand products, mostly t-shirts with configurable color and size, and I need to import its database (which I already have in xls format, had to export from a MS-SQL database) to Magento.

So looking for a solution to import those t-shirts as configurable products, Ive found this page http://www.ayasoftware.com/content/how-import-configurable-products-csv-file-magento-system , and then later this thread, which, as I understand, is the origin of that Productwithconfigurablesandcategories class they got on that page.

After applying that label fix from some pages ago (my Magento is 1.4.1) , I was able to get it working. But then I realized it will only import the configurable product itself, and will not create the simple products to be associated with the configurable product. Then is not good enough for me and I decided to increment it.

What I want is to import a csv that will be like this

"websites","type","attribute_set","config_attributes","sku","category_ids","name","meta keyword","description","short_description","custom_made","price","shirt_size","color","qty","status","visibility","weight","is_in_stock"
"base,masculino,feminino"
,"configurable","Camisetas","color,shirt_size","111111","42","Teste","teste","ubaubauba","uuuu","Sim","115","Feminina GG,Feminina G,Feminina M","Amarelo,Branco,Preto","50","Habilitado","Catálogo, busca","5","1"

Where Im giving “Amarelo,Branco,Preto” has colors and “Feminina GG,Feminina G,Feminina M” as sizes.

And then have the script automatically create not only the configurable t-shirt “teste”, but also all the simple products corresponding to all combinations of shirt_size and color.

So I came up with this code, which I placed right after “$product->setCanSaveCustomOptions(true);”

$vals = array();

                foreach(
$configAttributeCodes as $code)
                
{
                    $arr 
explode(','$importData[$code]);
                    
$vals[] $arr;
                
}//foreach codes

                
$combs $this->getCombinations($vals);
                
$associated = array();

                foreach(
$combs as $comb)
                
{
                    $data 
$importData;
                    
$data['name'$importData['name'].' '.$comb;
                    
$data['sku'$importData['sku'].'-'.str_replace(' ''-'$comb);

                    unset(
$data['config_attributes']);

                    
$data['descripition'$data['name'];
                    
$data['short_description'$data['name'];

                    
$data['visibility''Not Visible Individually';
                    
$data['type''simple';

                    
$values explode('-'$comb);
                    
$ti count($values);

                    for(
$i 0$i $ti$i++)$data[$configAttributeCodes[$i]] $values[$i];

                    if(
$this->saveRow($data))$associated[] $data['sku'];
                
}//foreach $combs as value

                
$importData['associated'implode(','$associated);

Basically, this will get all possible combinations of color and size, then save the corresponding simple products (automatically creating the name and sku for each combination) and then put the sku codes of all of then into $importData[’associated’] so they will be associated with the configurable product.

In theory, I think is correct. And its almost working. The script will successfully create the simple products, but then it will fail trying to save the configurable one. It will give me this error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘210-1’ for key ‘IDX_STOCK_PRODUCT’

Where 210, curiously, is the ID of the last created simple product.

So, I dont know where to go from here. What Im doing wrong? And feel Im so near, but doing something stupid.

Any help would be much appreciated.

Thank you

EDIT: Ok, so it has something to do with the stock, since that index belongs to the cataloginventory_stock_item table. But I still got no clue whats going wrong here.

EDIT 2: If I unset both ‘color’ and ‘shirt_size’ from $importData before saving the configurable product, I dont get the error. But then the configurable product is saved like a simple product, with no associated product anyway. Oh boy.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Diogo Barioni Abdalla
Member
 
Total Posts:  44
Joined:  2009-03-25
 

Anyone, please

 
Magento Community Magento Community
Magento Community
Magento Community
 
Diogo Barioni Abdalla
Member
 
Total Posts:  44
Joined:  2009-03-25
 

Still trying…

 
Magento Community Magento Community
Magento Community
Magento Community
 
bolasevich
Sr. Member
 
Avatar
Total Posts:  235
Joined:  2008-03-04
Newington, CT USA
 

@Diogo Barioni Abdalla

i think it has something to do with the stock of the products.. maybe you need to be setting these for all products you are “creating” attempting to import because that error in some cases could translate or be the issue of ‘null’ aka not being set and when its trying to insert ‘null’ and of course it can’t just a theory i could be wrong smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Diogo Barioni Abdalla
Member
 
Total Posts:  44
Joined:  2009-03-25
 

Thanks for the reply, but I was able to fix it.

The problem was actually here:

public function getProductModel()
    
{
        
if(is_null($this->_productModel))
        
//if(true)
        
{
            $productModel 
Mage::getModel('catalog/product');
            
$this->_productModel Mage::objects()->save($productModel);
        
}
        
return Mage::objects()->load($this->_productModel);
    
}

The class reuses the model once it has been created (because its meant to insert one product at a time, not a bunch of then). So, after inserting the last simple product, the garbage it left on the model would cause that error inserting the configurable one.

I solved it by changing the position of that block of code where I create the simple products to the top of “saveRow”, and right after doing it I manually set the model to null:

$this->_productModel null;

This solved everything and I was able to insert 950 configurable products with over 25000 simple products automatically created for then (there was a lot of possibilities for each configurable product)

I putting my class here (along with a sample csv), so if anyone ever needs to import a big load of configurable products and auto create the simple ones, they can try it. Its not fast at all, mind you: took a very long time for each product in my case (because one t-shirt would usually have more than 150 possible combinations of size and color), but it worked.

File Attachments
Productwithconfigurablesandcategories.php  (File Size: 16KB - Downloads: 411)
configurable_sample.txt  (File Size: 3KB - Downloads: 475)
 
Magento Community Magento Community
Magento Community
Magento Community
 
gpcola
Sr. Member
 
Total Posts:  97
Joined:  2009-10-05
 

Ok I’m back with this issue again:

Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray

 
Magento Community Magento Community
Magento Community
Magento Community
 
gpcola
Sr. Member
 
Total Posts:  97
Joined:  2009-10-05
 

My problem is a little different to others mentioned in this thread perhaps in that I’m calling saveRow() from my own script that is building and maintaining a list of products, downloaded from my supplier by xml feed, in a temporary database before then using magento to add or update them in my site’s catalogue.

require_once($_SERVER['DOCUMENT_ROOT']."/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php");
    
$MageProducts = new Mage_Catalog_Model_Convert_Adapter_Productimport();
    ...
    ...
    foreach(
$products as $product{
        $result 
$MageProducts->saveRow($product);
    
}

The first time I hit a configurable product I get this error but if I immediately hit refresh the script runs right past that product and all the way through to the end, passing many simple/configurable product sets on its way, without failing.

Line 107 of ProductImport.php is this line

$cspa  $product->getTypeInstance()->getConfigurableAttributesAsArray($product);

For some reason the $product->getTypeInstance is returning Mage_Catalog_Model_Product_Type_Simple but only the first time in a session?!

If I add print_r($product->getTypeInstance()) just before that line I get the following for a configurable product

Mage_Catalog_Model_Product_Type_Simple Object [_product:protected] => Mage_Catalog_Model_Product Object [_cacheTag:protected] => catalog_product [_eventPrefix:protected] => catalog_product [_eventObject:protected] => product [_canAffectOptions:protected] => [_typeInstance:protected] => Mage_Catalog_Model_Product_Type_Simple Object *RECURSION[_typeInstanceSingleton:protected] => Mage_Catalog_Model_Product_Type_Configurable Object [_usedProductAttributeIds:protected] => _cache_instance_used_product_attribute_ids....

Which is clearly wrong…

I want to be able to use my script through cron, but this error is stopping me from doing that so I desperately need some help to fix - can anyone offer some advice?

thanks -gpcola

 
Magento Community Magento Community
Magento Community
Magento Community
 
keyzo
Jr. Member
 
Total Posts:  23
Joined:  2011-02-12
 

@Diogo Barioni Abdalla I’ve followed your method and currently it’s working good, but how do you set the qty of stock per size ?

Anybody got any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
keyzo
Jr. Member
 
Total Posts:  23
Joined:  2011-02-12
 

@Diogo Barioni Abdalla I\’ve followed your method and currently it\’s working good, but how do you set the qty of stock per size ?

Anybody got any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
pradeep_kumar67
Sr. Member
 
Avatar
Total Posts:  160
Joined:  2010-06-24
Bangalore
 
plasmagunman - 22 June 2010 10:35 AM

rich15swan - 21 June 2010 02:41 AM
@neuromancer8

I am currently having the same issue what was the solution that you came across?

for me the patch of @caligola worked like a charm:
in file app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php find the code

if ( !empty( $usingAttributeIds ) ) {
    $product 
-> getTypeInstance() -> setUsedProductAttributeIds$usingAttributeIds );
    
$product -> setConfigurableAttributesData$product -> getTypeInstance() -> getConfigurableAttributesAsArray() );
    
$product -> setCanSaveConfigurableAttributestrue );
    
$product -> setCanSaveCustomOptionstrue );
}
and replace it with
if ( !empty( $usingAttributeIds ) ) {
    $product 
-> getTypeInstance() -> setUsedProductAttributeIds$usingAttributeIds );
    
$attributes_array $product->getTypeInstance()->getConfigurableAttributesAsArray();
    foreach(
$attributes_array as $key => $attribute_value{
        $attributes_array[$key][
'label'$attribute_value['frontend_label'];
    
}
    $product 
-> setConfigurableAttributesData($attributes_array);
    
$product -> setCanSaveConfigurableAttributestrue );
    
$product -> setCanSaveCustomOptionstrue );
}

Boss thanks it helped me lot grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
tmp2000
Jr. Member
 
Total Posts:  9
Joined:  2011-07-14
 

After a few days combination with others codes, I got the import configurable products successfully.
Please see the attached.It will be pleasure if any body use it.
Fixed the error getConfigurableAttributesAsArray not exist which as I found caused by $product->getTypeInstance()->getSetAttributes();
But don’t know the reason.
Some drawbacks:
$rootId = $store->getRootCategoryId();//Don’t know why the rootId always get 0
May be some body can help solve it.
Change the codes as following which others code supplied before :
$attr_codes[$cs_attr[’attribute_id’]] = strtolower($cs_attr[’attribute_code’]);
//$attr_codes[] = $cs_attr[’attribute_id’];

File Attachments
ProductImport.php  (File Size: 21KB - Downloads: 98)
 
Magento Community Magento Community
Magento Community
Magento Community
 
wuqio
Jr. Member
 
Total Posts:  4
Joined:  2012-10-21
 

nd to add to this, yes there should probably be some documentation. You’ve been waiting a shorter period of time than I have. And no, it won’t cover everything necessary because Magento is too flexible. The list of required import items is a moving target because attributes can be added and deleted at will and any new ones added that are created as required items need to be added to your new product import list. nike requin pas cher
nike tn requin
chaussure nike requin tn

 
Magento Community Magento Community
Magento Community
Magento Community
 
wuqio
Jr. Member
 
Total Posts:  4
Joined:  2012-10-21
 

You could use this to add multiple views but exclude is checked by default. This prevents the other product images from displaying on the product page. nike tn shopair yeezy pas cher shox nike femme noir

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 17 of 17