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

A suggestion to import configurable products + categories
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 

There are some servers that have a different configuration (php.ini) for Apache and for /bin/php, then I’ts not easy to run directly the script.

No problem, we only need to change:

// ONLY WORK VIA CRON OR SSH: /usr/bin/php -f /var/www/magento/cron_import.php
if (!$_SERVER["HTTP_USER_AGENT"]{

to

// ONLY WORK VIA CRON OR SSH: lynx -accept_all_cookies http://localhost/magento/cron_import.php (or http://domain.com/cron_import.php)
if ($_SERVER["SERVER_ADDR"== $_SERVER["REMOTE_ADDR"])

The script can now run via lynx, wget, elinks, etc:

wget -O - http://localhost/magento/cron_import.php
lynx -accept_all_cookies http://localhost/magento/cron_import.php

I observe that other server installations needs to change “require_once ‘app/Mage.php’;” line to “require_once ‘/var/www/magento/app/Mage.php’;” (the complete path)

good luck!

 
Magento Community Magento Community
Magento Community
Magento Community
 
PBaumann
Jr. Member
 
Total Posts:  19
Joined:  2008-08-14
 

Hi there,

thanks for this solution, it helped me a lot! I have one question: Isn´t it better to put the Productwithconfigurablesandcategories.php file into

app/code/local/Mage/Catalog/Model/Convert/Adapter in order to keep the file when updating to a higher version of magento? I remember that experts are warning to change something in the core directory.

I created the neccesary directories in app/local and the script worked fine.

Additionally, I also experienced the message “While trying to import i get this Notice: Undefined index: config_attributes in .../app/code/local/Mage/Catalog/Model/Convert/Adapter/Productwithconfigurablesandcategories.php on line 109” when the import process tried to import the configurable product.

I did everything you suggested but it didn´t helped. After messing around for more than two hours I had a closer look at your sample csv files and noticed that my csv file was missing the config_attributes entry. Oh my god! Seems stupid, but many issues have stupid reasons smile

See you
Patrick

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 

Excelent, Patrick!

I will try to move my .php to local/ folder too.

The file app/code/core/Mage/Eav/Model/Entity/Abstract.php is different in version 1.3.1 (in 1.2.1.2 my import script always works fine)

That is the question: Do you try to update some data in existing products (like the name, or stock quantiry, etc) I make a script than marked to “disable” the old product, then upload a new product with the same sku with the changes and “enabled”, but this does not work very well (returns “Warning: Invalid argument supplied for foreach() in /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 937")

These code are:

933                /**
   934                 * drop attributes that are unknown in new data
   935                 * not needed after introduction of partial entity loading
   936                 */
   
937                foreach ($origData as $k=>$v{
   938                    
if (!array_key_exists($k$newData)) {
   939                        
unset($origData[$k]);
   
940                    }
   941                }

I think there will be a better way to delete an obsolet product. Some ideas about it?

Thank you!

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 

There is a cut of the mentioned bash script, it’s very basic.

The diff command compares the new and old .csv and mark the output with ‘<’ or ‘>’ (changed or new). Based in that information, we play with the “Enabled"/"Disabled" feature, but now I think this isn’t the best way to do this.

The date (fecha) is used to show the products in home page.

# calculamos la fecha para los articulos que han de aparecer en el escaparate
fecha=`date +%d-%m-%Y\ 00:00:00`
# salva el separador de campo
oldIFS=$IFS
# nuevo separador de campo
IFS=$'\n'
# bucle que recoge el resultado de diff
for linea in $(diff $anterior $actual)
do
    
# los configurables aparecen en el escaparate
    
linea=${linea/'"configurable"'/'"configurable","'$fecha'"'}
    
# los simples no aparecen en el escaparate
    
linea=${linea/'"simple"'/'"simple",""'}
    
# analiza las diferencias
    
tipolinea=${linea:0:1}
    
case $tipolinea in
        
# linea antigua, eliminar (desactivar)
        
"<")
            
linea=${linea:2}
            linea
=${linea/'"Enabled"'/'"Disabled"'}
            
echo $linea >> $nuevo
            
;;
        
# linea nueva, agregar
        
">")
            
linea=${linea:2}
            
echo $linea >> $nuevo
            
;;
    
esac
done
# retaura el separador de campo
IFS=$old_IFS

I wait for your ideas!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Finn
Member
 
Total Posts:  75
Joined:  2008-12-03
Finland & The Netherlands
 

Hi all,

amartinez, thanks for posting such a super script, it’s been a life saver!

In the past couple of days I’ve been playing around with your script and after you posted the cron script along with it it became pretty much a necessity to install it into one of my shops. Because I want to keep the install as clean as possible I’ve made local module out of it (@Patrick, you just beat me with the suggestion wink

The module (Tansarc_ImportProductWithConfigurablesAndCategories) has been developed and shortly tested in v1.3.0.

I’ve made it so that during install/upgrade it runs a setup script (Resource_Cronscript_Mysql4_Setup) that:
- Renames old profile with the same name (Import Product With Configurables And Categories) by adding ‘-old’ to prevent overwriting by the next step

- Inserting the “Import Product With Configurables And Categories” profile into the ‘dataflow_profile’ table

- Creating/overwriting a cron script file (ImportProductWithConfigurablesAndCategories-CronScript.php) in the magento root folder

- During install the profileId is automatically included into the cron script file

For testing purposes I’ve been using version 0.1.1 because I wanted to see what happens during the upgrade. If you want to have Magento run the upgrade script, simply go to the database and change the version of this resource back to 0.1.0 in the core_resource table. Magento will then run “mysql4-upgrade-0.1.0-0.1.1.php”.

I also included a Sample.csv file I’ve used for my tests. BEWARE: the products tested with are the Magento Demo Shop Clogs, delete these before starting the test or the import will fail. You can delete them through “Catalog -> Manage Products”, filter by their SKU “cn”. Put the sample file into var/log/import and rename it to: “FileToImport.csv” (this is the filename the script will search for)

The profile can be run through the admin interface or from the command line.
wget -O - http://www.example.com/ImportProductWithConfigurablesAndCategories-CronScript.php
lynx -accept_all_cookies http://www.example.com/ImportProductWithConfigurablesAndCategories-CronScript.php

You can install the module by:
- place ‘modules/Tansarc_ImportProductWithConfigurablesAndCategories.xml’ in ‘app/etc/modules/’
- place ‘Tansarc’ folder into ‘app/code/local/’
- open any of your webshop pages as magento checks if anything needs to be upgraded before building a page

Besides this I found a little error in the posted version of the cron script:

if ($recordCount&#x50;0 == 0) {
should be
if ($recordCount 50; == 0) {

Have fun!

Finn

File Attachments
 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 

if you receive this:

PHP Fatal error:  Call to undefined method Mage_Catalog_Model_Product_Type_Simple::canUseAttribute() in /var/www/magento/app/code/core/Mage/Catalog/Model/Convert/Adapter/Productwithconfigurablesandcategories.php on line 113

Verify the correlation of header rows with it’s data.

I need to add this control too, to skip my special attribute ‘shoe_size’:

if ($attributeCode != 'shoe_size'// skip our special attribute (used to make configurable products)
                        
$attribute $product->getResource()->getAttribute($attributeCode);
                        if (
$product->getTypeInstance()->canUseAttribute($attribute)) {
                                
if ($new// fix for duplicating attributes error
                                        
$usingAttributeIds[] $attribute->getAttributeId();
                                
}
                        }
                }

Only for magento version < 1.3

Regards!

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 

Hi Finn!

You help us a lot! I analyze your solution in deep next monday smile Some parts of your post are obscure to me (I’m an absolut magento beginner)

Perhaps you can help me with the “update products” problem that I explain above.

Thanks again!

Antonio

P.D. The script line you reference was “if ($recordCount *percent* 500 == 0) {” (to calculate the module of recordCount / 500) perhaps an html error in the post smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 

Hi all,

I’m analyzing the problem detected with Taylor in this line (really, I see it now, then remember the Taylor comment smile)

$rootId $store->getRootCategoryId();

appears to return always 0, but my default store root category is 8!

I rewrite a possible solution, a little change:

// $rootId = $store->getRootCategoryId();
    $rootId Mage::app()->getStore()->getRootCategoryId();

That works fine for me (remember to verify you have the category correctly assigned in system - manage stores)

Regards,

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 
amartinez - 18 April 2009 06:15 AM

Excelent, Patrick!

I will try to move my .php to local/ folder too.

The file app/code/core/Mage/Eav/Model/Entity/Abstract.php is different in version 1.3.1 (in 1.2.1.2 my import script always works fine)

That is the question: Do you try to update some data in existing products (like the name, or stock quantiry, etc) I make a script than marked to “disable” the old product, then upload a new product with the same sku with the changes and “enabled”, but this does not work very well (returns “Warning: Invalid argument supplied for foreach() in /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 937")

These code are:

933                /**
   934                 * drop attributes that are unknown in new data
   935                 * not needed after introduction of partial entity loading
   936                 */
   
937                foreach ($origData as $k=>$v{
   938                    
if (!array_key_exists($k$newData)) {
   939                        
unset($origData[$k]);
   
940                    }
   941                }

I think there will be a better way to delete an obsolet product. Some ideas about it?

Thank you!

I can’t get it run… cron_import.php don’t authenticate correctly. There is some security changes in magento 1.3+ that prevents to cron_import.php to edit or delete existing products

somebody find a correct way to do it?

$profile Mage::getModel('dataflow/profile');
  
$userModel Mage::getModel('admin/user');
  
$userModel->setUserId(0); // or whatever else
  
Mage::getSingleton('admin/session')->setUser($userModel);

thanks a lot!

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 
amartinez - 21 April 2009 10:46 PM

amartinez - 18 April 2009 06:15 AM
Excelent, Patrick!

I will try to move my .php to local/ folder too.

The file app/code/core/Mage/Eav/Model/Entity/Abstract.php is different in version 1.3.1 (in 1.2.1.2 my import script always works fine)

That is the question: Do you try to update some data in existing products (like the name, or stock quantiry, etc) I make a script than marked to “disable” the old product, then upload a new product with the same sku with the changes and “enabled”, but this does not work very well (returns “Warning: Invalid argument supplied for foreach() in /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 937")

These code are:
933                /**
   934                 * drop attributes that are unknown in new data
   935                 * not needed after introduction of partial entity loading
   936                 */
   
937                foreach ($origData as $k=>$v{
   938                    
if (!array_key_exists($k$newData)) {
   939                        
unset($origData[$k]);
   
940                    }
   941                }

I think there will be a better way to delete an obsolet product. Some ideas about it?

Thank you!

I can’t get it run… cron_import.php don’t authenticate correctly. There is some security changes in magento 1.3+ that prevents to cron_import.php to edit or delete existing products

somebody find a correct way to do it?

$profile Mage::getModel('dataflow/profile');
  
$userModel Mage::getModel('admin/user');
  
$userModel->setUserId(0); // or whatever else
  
Mage::getSingleton('admin/session')->setUser($userModel);

thanks a lot!

Yeahhhh!! Finally it work!!!

replace Mage:app(); with:

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

I will go to clear my code & post it a.s.a.p.

Regards!

 
Magento Community Magento Community
Magento Community
Magento Community
 
fabcreasenso
Member
 
Avatar
Total Posts:  31
Joined:  2008-12-15
 

Hi amartinez,

thank you for all those informations.. I’ve been looking for a solution to this problem for a long time… and your import solution seems to work perfectly..
I have a question though.. I’d like to export an existing catalog, with a lot of multiple attributes configurable product in order to change some informations (meta stuff, prices)..

How can I export my catalog using your php, and directly have in my csv the associated column, with all the good liaisons ?

Thank you

Fab

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 
fabcreasenso - 23 April 2009 05:25 AM

Hi amartinez,

thank you for all those informations.. I’ve been looking for a solution to this problem for a long time… and your import solution seems to work perfectly..
I have a question though.. I’d like to export an existing catalog, with a lot of multiple attributes configurable product in order to change some informations (meta stuff, prices)..

How can I export my catalog using your php, and directly have in my csv the associated column, with all the good liaisons ?

Thank you

Fab

Hi!

I think you can export all your data with the existing magento profiles, perhaps configurating some additional XML export rule (CDATA blah blah) I’m sorry but I’m not a magneto expert smile only a persistent user (with some lucky)

But don’t worry, I’m sure that together we can!

...in the next chapter: the complete new import scripts!

 
Magento Community Magento Community
Magento Community
Magento Community
 
fabcreasenso
Member
 
Avatar
Total Posts:  31
Joined:  2008-12-15
 

Hey,
thanks for answering..
The thing is with the existing magento profile, you don’t export the connections between a configurable product and a simple product..
So it’s quite difficult when you want to work on a big catalog, cause you will have to do all the connections again in the csv file before re importing..
I’ll look into that.. and let you know if i find something…

Thanks anyway..

Fab

 
Magento Community Magento Community
Magento Community
Magento Community
 
abidwell
Jr. Member
 
Total Posts:  19
Joined:  2009-02-23
 

hi
am sure i am doing something stupid
when running the advanced profile version mine just sticks at

Starting catalog/convert_adapter_productwithconfigurablesandcategories :: parse

and goes no further
i am running 1.3

any ideas ?

many thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 
timmyludge - 24 April 2009 04:04 AM

hi
am sure i am doing something stupid
when running the advanced profile version mine just sticks at

Starting catalog/convert_adapter_productwithconfigurablesandcategories :: parse

and goes no further
i am running 1.3

any ideas ?

many thanks

hi, are you verify all your attributes, attributes setc, etc etc. These import script work’s fine… but don’t link configurable products width magento version 1.3+.

But don’t worry, I have a new script.

Wait a while…

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top