Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 35 of 35
A suggestion to import configurable products + categories
 
badongnew
Jr. Member
 
Total Posts:  2
Joined:  2012-06-15
 

I was able to import successfully, however in my 178 products, only 103 got Imported, and its all random, configurable or not]

any bright ideas?
Bones

 
Magento Community Magento Community
Magento Community
Magento Community
 
tigerofasia
Jr. Member
 
Avatar
Total Posts:  21
Joined:  2010-07-11
 

I would just like to share this fix of mine for the images (image, small_image, thumbnail). This fixed my problem before.

Add these :

$mediaGalleryBackendModel $this->getAttribute('media_gallery')->getBackend();
        
$arrayToMassAdd = array();
        foreach (
$product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute{
            
if (isset($importData[$mediaAttributeCode])) {
                $file 
trim($importData[$mediaAttributeCode]);
                if (!empty(
$file) && !$mediaGalleryBackendModel->getImage($product$file)) {
                    $arrayToMassAdd[] 
= array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
                
}
            }
        }

        $addedFilesCorrespondence 
$mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
            
$product,
            
$arrayToMassAddMage::getBaseDir('media') . DS 'import',
            
false,
            
false
        
);

        foreach (
$product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute{
            $addedFile 
'';
            if (isset(
$importData[$mediaAttributeCode '_label'])) {
                $fileLabel 
trim($importData[$mediaAttributeCode '_label']);
                if (isset(
$importData[$mediaAttributeCode])) {
                    $keyInAddedFile 
array_search($importData[$mediaAttributeCode],
                        
$addedFilesCorrespondence['alreadyAddedFiles']);
                    if (
$keyInAddedFile !== false{
                        $addedFile 
$addedFilesCorrespondence['alreadyAddedFilesNames'][$keyInAddedFile];
                    
}
                }

                
if (!$addedFile{
                    $addedFile 
$product->getData($mediaAttributeCode);
                
}
                
if ($fileLabel && $addedFile{
                    $mediaGalleryBackendModel
->updateImage($product$addedFile, array('label' => $fileLabel));
                
}
            }
        }

after these :

foreach ( $inventoryFields as $field {
            
if ( isset( $importData[$field] ) ) {
                
if ( in_array$field$this -> _toNumber ) ) {
                    $stockData[$field] 
$this -> getNumber$importData[$field] );
                    

                
else {
                    $stockData[$field] 
$importData[$field];
                    

                } 
            } 
        $product 
-> setStockData$stockData );

Btw, the fix above is for the latest magento version
----------------------------------------------------------------------------

And I would just like to add this one because I spent hours just to make the configurable options show on the frontend. I hope this helps someone struggling right now. The “options_container” value I used is “Block after Info Column” and then the configurable options showed magically! I thought this field is of no use but it’s some kinda powerful!

Thanks to the people who created this very helpful import code. You know who you are. May GOD bless you all wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
Max134
Member
 
Total Posts:  37
Joined:  2010-05-29
 

Hello

Everything works fine in magento 1.7.0.2 but one thing, that I do not how resolve it.

Well, When process finish, if I execute this sql:

SELECT * FROM catalog_product_entity WHERE entity_id = idConfigurableproduct

has_options = 0 and required_options = 0,

If I put required_options = 1 it works, I also need that has_options=1 in the configurable products.

In the code I try this one:

$product->setHasOptions(1);
$product->setRequiredOptions(1); or $product->setData('required_options',1);

None of these works, required_options is allways 0, and there is a problem in front.end when is 0 and not 1.

I realize that this code unset required_options attribute;

foreach ($this->_ignoreFields as $field{                        
            
if (isset($importData[$field])) {
                
unset($importData[$field]);
            
}
        }
but If I comment it, there is bigger problems. Probably there is not relation with my issue, but I would like to know too, how you determine which attributes are ignoreFields, I try to look for an answer I do not find the reason an attribute belons to ignore.

I hope get some help, it is just a little that I need to resolve my imports of configurable products.

Thanks in advance !

 
Magento Community Magento Community
Magento Community
Magento Community
 
Max134
Member
 
Total Posts:  37
Joined:  2010-05-29
 

Hi again,

I check that required_options and has_options changes its value to 0, in the _beforesave function. So the solution I find to put the configurable products to 1 is just a sql statement.

$product->save();
        if(
$is_configconfigurable){
            $write 
Mage::getSingleton('core/resource')->getConnection('core_write');
            
$write->query('UPDATE catalog_product_entity SET has_options= ?,required_options= ? where entity_id= ?',array(1,1,$product->getId()));
            
        
}
        
return true;

Now I need into Advanced Dataflow profiles, the options to upload cvs file like Dataflow - Profiles. That will be amazing.

And I pretend too, not include configurable products into csv files, just get them about simple products.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Max134
Member
 
Total Posts:  37
Joined:  2010-05-29
 

Hi

I have a little problem, import works fine, but I have problem with images, I only put images in configurable products, obviously there is not reason to put them in simples products.

My problem if the next, if I pass the cvs file twice (for update values, etc..), the images selection are all put with no selection. So it all is a mess. I need that when the product is already exists to skip images.

I’ve tried this code:

if($new){
             
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute{
                  
                 $images 
array_reverse (explode(',',$importData[$mediaAttributeCode]));
                 
$i=0;
                 foreach(
$images as $img){
                     
if(strpos($img,'http')!==FALSE){
                         $i
++;
                         
$image_url  $img;
                         
$image_type substr(strrchr($image_url,"."),1);
                         
//$filename   = strtolower( preg_replace("/ /", '_', $importData['sku'].'-'.substr(md5($mediaAttributeCode), 0,3))).'.'.$image_type;
                          
                         
$filename =  substr(str_replace($image_type''basename($img)),0,-1).'-'.$i.'.'.$image_type;
                         
$filepath   Mage::getBaseDir('media') . DS 'import'DS $filename;
                          
                         
file_put_contents($filepathfile_get_contents(trim($image_url)));
                          
                         
$image = new SimpleImage();
                         
$image->load($filepath);
                         
$image->resizeToWidth(675);
                         
$image->save($filepath);
                         
$img '/'.$filename;
                          
                          
                     
}
             
                     
if($mediaAttributeCode=='image'){
                         $importData[
'image']$img;
                     
}
                     
                     
/*
                      if($mediaAttributeCode=='change_image' && ){
                     $importData['image']= $img;
                     }*/
                     
if(!$img && ($mediaAttributeCode=='small_image' || $mediaAttributeCode=='thumbnail')){
                         $img 
$importData['image'];
                     
}
                     
if (isset($img)) {
                         $file 
trim($img);
                         if (!empty(
$file) && !$mediaGalleryBackendModel->getImage($product$file)) {
                             $arrayToMassAdd[] 
= array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
                         
}
                     }
                 }
             }
            $addedFilesCorrespondence 
$mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
                    
$product,
                    
$arrayToMassAddMage::getBaseDir('media') . DS 'import',
                    
false,
                    
false
            
);
            
            foreach (
$product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute{
                $addedFile 
'';
                if (isset(
$importData[$mediaAttributeCode '_label'])) {
                    $fileLabel 
trim($importData[$mediaAttributeCode '_label']);
                    if (isset(
$importData[$mediaAttributeCode])) {
                        $keyInAddedFile 
array_search($importData[$mediaAttributeCode],
                                
$addedFilesCorrespondence['alreadyAddedFiles']);
                        if (
$keyInAddedFile !== false{
                            $addedFile 
$addedFilesCorrespondence['alreadyAddedFilesNames'][$keyInAddedFile];
                        
}
                    }
            
                    
if (!$addedFile{
                        $addedFile 
$product->getData($mediaAttributeCode);
                    
}
                    
if ($fileLabel && $addedFile{
                        $mediaGalleryBackendModel
->updateImage($product$addedFile, array('label' => $fileLabel));
                    
}
                }
            }
         

            $imageData 
= array();
            foreach (
$this->_imageFields as $field{
                
if (!empty($importData[$field]) && $importData[$field] != 'no_selection'{
                    
if (!isset($imageData[$importData[$field]])) {
                        $imageData[$importData[$field]] 
= array();
                    
}
                    $imageData[$importData[$field]][] 
$field;
                
}
            }
    
            
foreach ($imageData as $file => $fields{
                
try {
                    $product
->addImageToMediaGallery(Mage::getBaseDir('media') . DS 'import' $file$fields);
                
}
                
catch (Exception $e{}
            }
         }

As you see if the product exits, skip to write images, but anyway the selection disappears, that’s a big problem.

Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Köme
Jr. Member
 
Total Posts:  2
Joined:  2010-12-20
 

I made a complete system (SalesPro) to import. The installer can be downloaded free of charge. Uploading data from Excel or Open Office. http://salespro.komesoft.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
RobPeters
Jr. Member
 
Total Posts:  1
Joined:  2010-05-13
 

Just wanted to drop: This script saved my life! Kudos to all involved.

 
Magento Community Magento Community
Magento Community
Magento Community
 
wpenders
Jr. Member
 
Total Posts:  4
Joined:  2011-04-08
 
tigerofasia - 05 January 2013 02:45 AM

I would just like to share this fix of mine for the images (image, small_image, thumbnail). This fixed my problem before.

You are my hero. Spent hours in a row trying to load the thumbs. Pasted your code and voila smile
Also thanks to the people who initially wrote this script!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 35 of 35