datafeed 2.1.4 import

Hello,



I see the datafeed plugin only works to EXPORT a datafeed. How about importing one? I have a URL where dailt a specific datafeed is updated, i want to import this with a cronjob. This option doesnt seem to be available.



Is there a way to do this??

Given that formats of data feeds are all different, this is usually custom development.

Well eventhough, I import a datafeed from an external URL into a mysql table. Then i create a csv file that is suitbale for import in cs-cart in the administration–>import–products. This works fine if i do it manually in this way.



But how can this be done in a cron? why is this feature never added, im sure many people would like it.

You would create a script that could be executed from cron that would connect to your source, load it inot your db table and then suck that out as a CSV and POST it appropriately to the exim controller to import it.



It’s not there because there is no standardization of the ‘source’ data so there’s no way (without a tremendous amount of admin interface to setup and establish mappings) to provide the translation.

You do not seem to understand what I am saying here.



I have an export.csv file which is generated outside of cs-cart.

It is renewed everyday. When I use the import feature from the cs-cart admin it imports perfectly.



So when i ise the import i see this:



Importing data

Creating Produkten…29778. Updating links… [OK]

Creating Produkten…29779. Updating links… [OK]

Creating Produkten…29780. Updating links… [OK]

Creating Produkten…29781. Updating links… [OK]

Creating Produkten…29782. Updating links… [OK]

Creating Produkten…29783. Updating links… [OK]

Creating Produkten…29784. Updating links… [OK]

Creating Produkten…29785. Updating links… [OK]

Creating Produkten…29786. Updating links… [OK]

Creating Produkten…29787. Updating links… [OK]

Creating Produkten…29788. Updating links… [OK]



which works all fine

I just want to automate the same process by doing it in a cron.

Then from “outside” you will have to perform an auto-login and POST the data to the exim controller. Or…



If you have the file local on the server then you can set yourself up a cron script that will set the AREA = ‘admin’ and $_SESSION[‘user_id’] = , source the prepare.php and init.php files. You can then synthetize the POSTed file by looking at controllers/admin/exim.php within the POST request for setting up the parser and looking at the ‘import’ mode doing something like:


fn_init_yaml();
$import_options = array('lang_code' => 'EN', 'category_delimiter'=>'///', 'images_path'=>'images/backup', 'delimiter'=>'C');
$data = fn_get_csv('products', $your_file_path, $import_options);
if( $data !== false )
fn_import('products', $data, $import_options);
exit;

Thanks for the explanation, but i dont seem to fully understand it.



I have the file locally on my server:

My question is how to use this code in a cron? becoz when i use this:



fn_init_yaml();
$import_options = array('lang_code' => 'EN', 'category_delimiter'=>'///', 'images_path'=>'images/backup', 'delimiter'=>'C');
$data = fn_get_csv('products', $your_file_path, $import_options);
if( $data !== false )
fn_import('products', $data, $import_options);
exit;




If this code is in a cron, where would i declare the session[‘userid’]?

Basically you’re going to do something like:

```php

/**
** Usage: Use the root of your store as the working directory for CRON
** Use this command line: php ./addons/obj_feed/cron_iface.php --pw=
** where is the password used for password reminders in Administration/Settings/Security Settings
**/
define('AREA', 'A');
define('AREA_NAME', 'admin');
require_once("./prepare.php");
require_once("./init.php");
if( !function_exists('obj_check_create') ) {
require_once(DIR_ADDONS."obj_feed/func.php");
}

$cron_password = Registry::get('settings.Security.cron_password');
if( !$cron_password )
die('Bad pass');

if ((!isset($_REQUEST['pw']) || $cron_password != $_REQUEST['pw']) ) {
die(fn_get_lang_var('access_denied'));
}
Your code goes here.
?>

```

Thanks a lot, but a couple of things are not clear:


  1. Well, you talk about the commant line: php ./addons/obj_feed/cron_iface.php --pw=

    I assume i need to save your code as “/addons/obj_feed/cron_iface.php”


  2. You said :

    "where is the password used for password reminders in Administration/Settings/Security Settings

    "



    I have a modded cs-cart with version 2.03 and I do not have the structure: “Administration/Settings/Security Settings”

    It only comes with later versions.



    How can i get passed this?


  3. obj_feed/func.php does not exist. What should i create here?

    I get the warning:


[QUOTE]Warning: require_once(/home/divers/domains/fmwebstore.nl/public_html/addons/obj_feed/func.php): failed to open stream: No such file or directory in /home/divers/domains/dname.nl/public_html/addons/obj_feed/cron_iface.php on line 12



Fatal error: require_once(): Failed opening required ‘/home/divers/domains/fmwebstore.nl/public_html/addons/obj_feed/func.php’ (include_path=‘/home/divers/domains/dname.nl/public_html/lib/pear/.:/usr/local/lib/php’) in /home/divers/domains/fmwebstore.nl/public_html/addons/obj_feed/cron_iface.php on line 12

[/QUOTE]



Don’t u mean the path to this file? /addons/access_restrictions/func.php ??







Do you need this should be the complete cron_iface.php ?


[QUOTE]

define(‘AREA’, ‘A’);

define(‘AREA_NAME’, ‘admin’);

require_once(“./prepare.php”);

require_once(“./init.php”);

if( !function_exists(‘obj_check_create’) ) {

require_once(DIR_ADDONS.“obj_feed/func.php”);

}



$cron_password = Registry::get(‘settings.Security.cron_password’);

if( !$cron_password )

die(‘Bad pass’);



if ((!isset($_REQUEST[‘pw’]) || $cron_password != $_REQUEST[‘pw’]) ) {

die(fn_get_lang_var(‘access_denied’));

}



//mycode

fn_init_yaml();

$import_options = array(‘lang_code’ => ‘EN’, ‘category_delimiter’=>‘///’, ‘images_path’=>‘images/backup’, ‘delimiter’=>‘C’);

$data = fn_get_csv(‘products’, $your_file_path, $import_options);

if( $data !== false )

fn_import(‘products’, $data, $import_options);

exit;

[/QUOTE]



6) when i remove the password fields, and i continue the function “fn_get_csv” is not defined.

I guess i need to add this line:



require_once(“./controllers/admin/exim.php”);



but then i get an error on this line in exim.php:

Warning: Invalid argument supplied for foreach() in



" foreach ($pattern[‘#export_fields’] as $field => $data) {"



I am using 2.03. I did not upgrade since i have modded this version manually a lot, with the upgrades it will all be lost.

You are obviously not a developer and don’t understand that when someone gives you a “sample” of code that you need to adjust it to suit your needs. The goal was to show the “flow of control” and the “logic” versus the verbatim of what is needed for your specific needs.



You are running an old version of the cart and so you may have to look at other security measures versus the cron password from the security area.



Suggest you hire yourself someone more experienced in development to get you over these hurdles. You would be better served by having someone do it for you and then go look at what they did to learn from it.

[QUOTE]You are obviously not a developer and don’t understand that when someone gives you a “sample” of code that you need to adjust it to suit your needs. The goal was to show the “flow of control” and the “logic” versus the verbatim of what is needed for your specific needs.

[/QUOTE]



I do understand the logic, and of course i changed the parameters to my own in image_path, file_path, etc but in fact your sample is incomplete, at least for 2.03.



The function fn_get_csv is not declared in your code.

So i just put an addition to add this file: require_once(“./controllers/admin/exim.php”);

Now it will be declared, so you should check your code more carefully.



If i comment out all the code for the security password, i stull run into fault number 6.


[QUOTE]

Warning: Invalid argument supplied for foreach() in /home/divers/domains/mydomain.nl/public_html/controllers/admin/exim.php on line 832



//line 832 is:



foreach ($pattern[‘#export_fields’] as $field => $data) {



[/QUOTE]



This seems to be the only problem.

I did not write the function, so, i need to know how to debug the error.