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
 
abidwell
Jr. Member
 
Total Posts:  19
Joined:  2009-02-23
 

40*** /home/tomlodge/public_html/magento/cron_import_1.3.php (that runs ok - i get an automated email to say it has run)

my cron_import_1.3.php - profile 9 is my correct version of the Profile

1.#!/usr/bin/php
2.<?
3.if (!$_SERVER["SERVER_ADDR"] == $_SERVER["REMOTE_ADDR"]) {
4.  $profileId = 9; // SYSTEM - IMPORT/EXPORT - ADVANCED PROFILES
5.

If I run that as it is - then i don’t get any errors in the cronjob report - but the product doesn’t create - so I will check the profile and the sample data is all ok i guess (but that file does import ok when i run the profile from AdminPanel so presumably its ok)

If i take out line 1 then i get script errors

/home/mysite/public_html/magento/cron_import_1.3.php: line 1: ?: No such file or directory
/home/mysite/public_html/magento/cron_import_1.3.php: line 2: syntax error near unexpected token `{’
/home/mysite/public_html/magento/cron_import_1.3.php: line 2: `if (!$_SERVER["SERVER_ADDR"] == $_SERVER["REMOTE_ADDR"]) {’

Any pointers would be really appreciated

Tom

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

hi again,

I think you really don’t need to update every 40 minutes. Perhaps every 6 hours (at least) will be right.

Now, the line #3 have 2 erros:

1/ You mistake when copying it (look at extra simbol ! in if clausule)

2/ These change only work with web browsers (like lynx) not for directly run of the script. I explain it before. Please try with:

if (!$_SERVER["HTTP_USER_AGENT"]) {

good luck!

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

hi
thanks for such quick reply - it’s not actually running every 40mins - that is the time past the hour when it runs - so i keep moving it forward - once i can get it working it would run every 12hours or something as you suggest.

if i change the cron_import as you suggest i now get

X-Powered-By: PHP/5.2.5
Content-type: text/html

Fatal error:  Uncaught exception ‘Exception’ with message ‘Notice: Undefined index:  SCRIPT_FILENAME in /home/mysite/public_html/magento/lib/Zend/Controller/Request/Http.php on line 543’ in /home/mysite/public_html/magento/app/code/core/Mage/Core/functions.php:240
Stack trace:
#0 /home/mysite/public_html/magento/lib/Zend/Controller/Request/Http.php(543): mageCoreErrorHandler(8, ‘Undefined index...’, ‘/home/mysite/...’, 543, Array)
#1 /home/mysite/public_html/magento/lib/Zend/Controller/Request/Http.php(575): Zend_Controller_Request_Http->setBasePath()
#2 /home/mysite/public_html/magento/app/code/core/Mage/Core/Controller/Request/Http.php(154): Zend_Controller_Request_Http->getBasePath()
#3 /home/mysite/public_html/magento/app/code/core/Mage/Core/Model/Cookie.php(119): Mage_Core_Controller_Request_Http->getBasePath()
#4 /home/mysite/public_html/magento/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php(80): Mage_Core_Model_Cookie->getPath()
#5 /home/mysite/public_html/magento/app/code/core/Mage/Cor in <b>/home/mysite/public_html/magento/app/code/core/Mage/Core/functions.php</b> on line <b>240</b><br />

do you think it is to do with SiteGround hosting cronjob ?

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

uhm, it sound like there’s out the system path. 2 options:

1/ run a bash script that change the current path to your magento folder (like cd /home/mysite/public_html/magento ; ./cron_import_1.3.php)

2/ another way, is to modify the require_once line, like this: require_once ‘/home/mysite/public_html/magento/app/Mage.php’;

go & try!

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

Antonio

ok - the cronjob appears to run with no errors but does not create the product
if i enter the url to that job in a browser it runs ok - but still does not associate the product
the browser displays

Starting Mage_Dataflow_Model_Convert_Adapter_Io :: load Loaded successfully: “/home/mysite/public_html/magento/var/import/importconfigurable.csv” Starting Mage_Dataflow_Model_Convert_Parser_Csv :: parse Found 3 rows Starting catalog/convert_adapter_productwithconfigurablesandcategories :: parse Done

should i be able to run the script from a browser window and it all work - or do i have to work out why the cronjob version is not creating product ?

thanks
Tom

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

Antonio

i hold my head in shame - i have just realised that i was trying to import using your Euro sizes and my Default is UK - so I didn’t have the Euro sizes in there…

So it does all work from the script in a browser - I just need to work out why the cronjob script in my hosting server does not work.

I will keep you updated on my progress

Thank you so much for your help

Tom

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

Please verify that the categories are correctly updated.

May Good Luck Be With You, Padawan!

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

ok
we are getting there now - the cronjob i have put on hold for now - will contact SiteGround and ask.

i was wondering though - did you work out the best way for multiple attributes - size and color being the most obvious

i read in the post that you can try running the import twice and just change the color for example ?

Tom

UPDATE:
just in case anyone is reading the thread and having any of the issues I had.
it all works nicely now after i had a slight change in the order i did everything
i created all my simple product first (in all the colour and size options) and actually created those using the standard magento import
and then just used this script to create the configurable parts. when i do that - i can have two lines for the same configurable product and just change the config_attributes field on each row and it all runs through great so far.. i need to check why my images aren’t connecting but pretty certain i read something in this thread about that the other day.. Clearly I am not as proficient as Antonio but if anyone has any questions for me on how mine is working I keep a tab on this thread so feel free to post a question.

cheers Tom

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

Running the script twice sounds nice. Please try it.

I’m fighting now with bundles & grouped & configurable products… all together one :D

Is like mixing PAELLA DE BOGAVANTE with FABADA ASTURIANA, but I am beginning to see the light.

I will maintain informed

Antonio

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

Hi all!

There’s the import script’s latest version.

Now you can import SIMPLE, CONFIGURABLE or GROUPED products.

Make sure you create an advanced profile (named Productwithconfigurablesandcategories) with this Actions XML:

<action type="dataflow/convert_adapter_io" method="load">
    <var 
name="type">file</var>
    <var 
name="path">media/import/</var>
    <var 
name="filename"><![CDATA[prueba_ambos.csv]]></var>
    <var 
name="format"><![CDATA[csv]]></var>
</
action>

<
action type="dataflow/convert_parser_csv" method="parse">
    <var 
name="delimiter"><![CDATA[,]]></var>
    <var 
name="enclose"><![CDATA["]]></var>
    <var name="
fieldnames">true</var>
    <var name="
store"><![CDATA[0]]></var>
    <var name="
number_of_records">1</var>
    <var name="
decimal_separator"><![CDATA[.]]></var>
    <var name="
adapter">catalog/convert_adapter_productwithconfigurablesandcategories</var>
    <var name="
method">parse</var>
</action>

Combine it with cron jobs to obtain a fully automatized magento import solution smile

Please notify me if you use it, bugs, improvements, etc.

Good luck!

File Attachments
scripts_and_examples.zip  (File Size: 7KB - Downloads: 1106)
 
Magento Community Magento Community
Magento Community
Magento Community
 
abidwell
Jr. Member
 
Total Posts:  19
Joined:  2009-02-23
 

Thanks for this Antonio I will try to test it later.

I found that I could import mulitple attributes by doing this

- attribute set Shoes2 (has shoe_size and color)
- move color out (AdminPanel says you cannot do this as Color being used by Configurable Product) but run the cron_import anyway
- move color in and move shoe_size out (again AdminPanel says you cannot...) change the config_attributes field on the import.csv to color and run the cron_import again
- then add back in shoe_size and save the attribute set

and this seems to work ok

so I am guessing that in the code you somehow need to allow for multiple attibutes in the set (i am not a php man so not much help here)

does that make sense ?

Tom

 
Magento Community Magento Community
Magento Community
Magento Community
 
Saggy
Sr. Member
 
Total Posts:  133
Joined:  2009-02-03
 

Thanks Amartinez, you are a star man!!!!. I have just run this script and it worked straight away for my grouped products. I’ll test this further and let you know the feedback. Well done!!!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
will_oz
Jr. Member
 
Total Posts:  15
Joined:  2009-03-11
Adelaide, Australia
 

Thanks so much to the gracious Antonio for the scripts and guidance. If I can get this working it’ll save me hundreds of hours!

Hopefully someone can answer my newbie questions:

1. Can I import products by running the advanced profile I created from the Magento admin, or only by using the cron_import_1.3.php script?

2. I’m a bit confused about line 3 of cron_import_1.3.php. There seem to be two options here, depending on whether it is being executed by cron or browser. I don’t understand the browser execution method that Tom seems to be using… is it as simple as uploading it to my root Magento directory (which is public_html) then navigating to www.myURL.com/cron_import_1.3.php? Is it meant to run automatically at that point?

When I tried that it didn’t work, but maybe my line 3 of cron_import_1.3.php was wrong. If I try to access it via the browser method, what exactly should line 3 say? It’s currently:

if ($_SERVER["SERVER_ADDR"== $_SERVER["REMOTE_ADDR"]{


3. I have to edit Productwithconfigurablesandcategories.php to make it match my Magento Root Category Id, right?
Is the number on line 326 the only place I have to edit? (Antonio’s latest version of the file has it set at “2”.) Do I also have to change the “2” on line 340? Anywhere else?


Now just a couple on what the actual product-import script can do:

4. Do I have to manually enter the configurable-attribute values before running the script to create configurable products? I.e. in your example, did you have to manually enter the different shoe sizes into Magento before running the profile to create a configurable product based on shoe-size? Or just create that attribute (shoe-size) and let the script populate the values (the different shoe sizes)?

5. Can it assign up-sells and cross-sells?

Thanks muchly for any help at all!

Cheers,
Will.

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

Hi! I’m here again!

@will_oz:

1/ You need to use the cron_import_1_3.php script for magento version 1.3.0 or 1.3.1, because the advanced profile can’t associate configurable or grouped products correctly. Really, it’s easy to move the mysql injections from cron_import_1.3.php to Productwith....php (after save() command): you can try it.

2/ These line is a little anti-hacking protection. The if clausule compare your server IP with the public IP of web browser. If there’s same then we know that cron_import_1.3.php was launch internally, like a cron job (lynx http://www.yourweb.com/cron_import_1.3.php) or via shell. You can edit these line adding your static IP (if you have one) then only YOU can run the script. Another simple option is to add a secret parameter (like http://www.yourweb.com/cron.php?PASSWORD=ABCDEFG123) and only to run if the pass is correct.

3/ Yes, insert here your root category: $rootId = YOUR_ROOT_CATEGORY; The above lines are comment, and there’s no effect, because return me a bad value. :( perhaps the script need some upgrade in this section.

4/ Yes, do you need to update your attributes manually, if there’s DROPDOWN type. Recently, I’m working wth TEXT type and associate it via grouped products. The difference is that the product presents a grid (nod a listbox) but this allow to customers to buy more units of the product directly smile and I don’t need to make updated the attribute’s table.

5/ Yes. The Productwith..... advanced profile are ready to do it. But I am not sure that works magento 1.3+, and these relations need’s mysql inyection too. The way is easy: mysqldump your database, create ONE up-sell product then mysqldump your database again. Use the linux command diff to see the differences then recreate it via php mysql commands. smile

See you soon!
Antonio

 
Magento Community Magento Community
Magento Community
Magento Community
 
olliebells
Jr. Member
 
Total Posts:  16
Joined:  2009-05-05
 

Hello Amartinez,

I must say that I am impressed so far with you help here ... However, can I be rude and ask you why I am getting the following error when running the cron_import_1.3.php ;

“ /bin/sh: /home/unlimite/domains/unlimitedgifts.co.uk/public_html/magento/cron_import_1.3.php: /usr/bin/php: bad interpreter: No such file or directory “

I read in a previous post that suggests the path to the php is incorrect and I ran the php_info.php but had a fatal error when doing so ..

I am very new to this so you will have to bear with me as I am learning loads every day !!!

Thanks in advance

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