Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Can I use an auto Import/cron job for this?

Can I use an auto Import/cron job for this?

Views: 6,492

Results 1 to 20 of 29
27 Jul 2013, 4:45 PM
#1
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Can I use an auto Import/cron job for this?

hi, i have a supplier that can supply a text file with products

is there a way i can make a cron job or something to fetch the data file from a passworded url convert it to a csv and import the file then excite the csv file?

im new at cron jobs

27 Jul 2013, 10:16 PM
#2
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

KNM Computers:

hi, i have a supplier that can supply a text file with products

is there a way i can make a cron job or something to fetch the data file from a passworded url convert it to a csv and import the file then excite the csv file?

im new at cron jobs

ok looking through the forum i found this:

Quote Originally Posted by Ryk View Post

I have no idea whether this sort of thing is even possible....

Receive excel file
convert excel file to fit EasyPopulate excel layout
ftp EP file to website
insert into ZC database

...all without human intervention.

Is this doable?
I have a partial solution which I've not tested.

You can save an excel spreadsheet in CSV format and use, the Easy Populate CSV add on, available here:
http://www.zen-cart.com/index.php?ma...oducts_id=1240

Ftp the file to /tempEP (the default import directory).
Let's say the file is called import_me.csv

You might be able to automate the above with a batch script.

Then create a script to be called by cron every five minutes say.
The script must first authenticate itself.
see:
http://www.zen-cart.com/forum/showthread.php?t=114279

The script then sets the filename variable to import and runs the easypopulate code.

To authenticate we need to override init_admin_auth.php.
So copy
admin/includes/init_includes/init_admin_auth.php
to
admin/includes/init_includes/overrides/init_admin_auth.php
and add
"""
// to allow cron jobs set CRON_ADMIN_USER_ID
if ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']) {
if (!isset($_SESSION['admin_id']) && defined('CRON_ADMIN_USER_ID') && CRON_ADMIN_USER_ID != '') {
$_SESSION['admin_id'] = CRON_ADMIN_USER_ID;
}
}
"""
to just after
"""

if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
"""

Then we write the script for cron.
Create a file /admin/cron1.php:

<?php define('CRON_ADMIN_USER_ID', '999'); require ('includes/application_top.php'); $_POST['localfile'] = "import_me.csv"; require ('easypopulate.php'); ?>

Then set up the cron job to call the script eg:
/usr/bin/lynx -accept_all_cookies -dump http://localhost/PathTo/admin/cron1.php

Please note I haven't thoroughly tested this.

if i set this up would i have to put a url where ill be getting my feed file from (its a passworded url) if i do then where in the script would i have to put it? or would that be a new/different cron job?

27 Jul 2013, 10:43 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Can I use an auto Import/cron job for this?

TIP:

  1. Forget the "cron" part initially. First get yourself a PHP script that works properly to accomplish your desired goals. Something that you can trigger from your browser by just visiting the .php file as the URL.

  2. After you've got that working reliably then test it from the command line.

  3. Then after that's working fine, set up a cron job in your hosting account to trigger that script to run at the scheduled intervals.

#1 is where you need to focus your time. Everything else is distraction.

As for the post you quoted above, note that it specifically says that it expects you to FTP the CSV to the server beforehand. So judging from the other stuff you've written, you're going to need to first automate the process of grabbing the password-protected file before you kick off anything that processes that file.

27 Jul 2013, 10:51 PM
#4
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

got ya thanks :smile:

27 Jul 2013, 10:57 PM
#5
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

well wot i did was added this into url bar http://www.knmcomputers.co.uk/myadmin/cron1.php it asked me to log in so i did then when it loged it it did import my products

so what did you say was next?

27 Jul 2013, 11:54 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Can I use an auto Import/cron job for this?

I'm not sure I understand your question.

Are you wanting to know how to bypass the login? That's answered in the post you quoted.

28 Jul 2013, 5:48 AM
#7
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

sorry lol in a way yes, as i think this will be an issue if im to get the whole process automatic, but the main question was as i have it excuited the script when i added the url so i need this to do it automatic?

28 Jul 2013, 8:38 AM
#8
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

ok in the file i made in admin called cron1 i put

<?php
define('CRON_ADMIN_USER_ID', '1'); 
require ('includes/application_top.php');
$_POST['localfile'] = "Full-EP2013Jul20-2311.csv";
require ('easypopulate.php');
?>

and in admin/includes/init_includes/overides/init_admin_auth.php is

<?php
/**
 * @package admin
 * @copyright Copyright 2003-2012 Zen Cart Development Team
 * @license [URL]http://www.zen-cart.com/license/2_0.txt[/URL] GNU Public License V2.0
 * @version GIT: $Id: Author: Ian Wilson  Sun Jul 1 12:08:22 2012 +0100 Modified in v1.5.1 $
 */

if (!defined('IS_ADMIN_FLAG')) die('Illegal Access');

define(SUPERUSER_PROFILE, 1);

// admin folder rename required
if (!defined('ADMIN_BLOCK_WARNING_OVERRIDE') || ADMIN_BLOCK_WARNING_OVERRIDE == '')
{
  if (basename($_SERVER['SCRIPT_FILENAME']) != FILENAME_ALERT_PAGE . '.php')
  {
    if (substr(DIR_WS_ADMIN, -7) == '/admin/' || substr(DIR_WS_HTTPS_ADMIN, -7) == '/admin/')
    {
      zen_redirect(zen_href_link(FILENAME_ALERT_PAGE));
    }
    $check_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/../zc_install';
    if (is_dir($check_path))
    {
      zen_redirect(zen_href_link(FILENAME_ALERT_PAGE));
    }
  }
}
if (basename($_SERVER['SCRIPT_FILENAME']) != FILENAME_ALERT_PAGE . '.php')
{

  if (strpos(strtolower($PHP_SELF),FILENAME_PASSWORD_FORGOTTEN.'.php') !== FALSE &&
  substr_count(strtolower($PHP_SELF), '.php') > 1)
  {
    zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

  if (!(basename($PHP_SELF) == FILENAME_LOGIN . ".php"))
  {
    $page = basename($PHP_SELF, ".php");
    if (!isset($_SESSION['admin_id']))
    {
      if (!(basename($PHP_SELF) == FILENAME_PASSWORD_FORGOTTEN . '.php'))
      {
        zen_redirect(zen_href_link(FILENAME_LOGIN, 'camefrom=' . basename($PHP_SELF) . '&' .  zen_get_all_get_params(), 'SSL'));
      }
    }

    if (!in_array($page, array(FILENAME_DEFAULT,FILENAME_ADMIN_ACCOUNT,FILENAME_LOGOFF,FILENAME_ALERT_PAGE,FILENAME_PASSWORD_FORGOTTEN,FILENAME_DENIED,FILENAME_ALT_NAV)) &&
        !zen_is_superuser())
    {
      if (check_page($page, $_GET) == FALSE)
      {
        zen_redirect(zen_href_link(FILENAME_DENIED, '', 'SSL'));
      }
    }

  }

  if ((basename($PHP_SELF) == FILENAME_LOGIN . '.php') &&
  (substr_count(dirname($PHP_SELF),'//') > 0 || substr_count(dirname($PHP_SELF),'.php') > 0))
  {
    zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
  }
}

but is does not do the auto admin login have i done something wrong?

28 Jul 2013, 3:12 PM
#10
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

hi the cron file i made where it says:
" <?php
define('CRON_ADMIN_USER_ID', '1'); "

is the the zencart admin id?

i have zencart 1.51 and think ive read somewhere about making up a user ???

thanks

28 Jul 2013, 5:04 PM
#11
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

right i figured it out i had code in wrong, so now when i call the url cron1.php it automaticly logs in and imports products,

now just need to sort out the cron job,

could the same sort of thing ive just done (cron job) be made up to fetch a data text from a supplier? and could it fetch said data text file, convert it to csv file and import it into EPtemp?

28 Jul 2013, 6:38 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Can I use an auto Import/cron job for this?

You could add code to your cron1.php file to go fetch the file from the other server and store it on your server in the filename you set for EP, and then proceed with calling EP.

28 Jul 2013, 7:07 PM
#13
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

ok thank you, what would the comarnd be to set up the cron job? ive tryed some that have been posted but all i get in the email is a 404 page not found???

28 Jul 2013, 7:08 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Can I use an auto Import/cron job for this?

KNM Computers:

ok thank you, what would the comarnd be to set up the cron job? ive tryed some that have been posted but all i get in the email is a 404 page not found???

Your hosting company is the best resource to answer that, since they know their server better than any of us here do.

28 Jul 2013, 7:12 PM
#15
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

DrByte:

Your hosting company is the best resource to answer that, since they know their server better than any of us here do.

ok thank you

28 Jul 2013, 9:28 PM
#16
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

ok i got the command from my hosting company and went to set one up but when it did it it sent me an email saying "no input file specified"

could you please tell me what this means?

29 Jul 2013, 4:20 AM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Can I use an auto Import/cron job for this?

That usually means the script was expecting a filename but one wasn't provided. And that suggests that maybe the server's PHP CLI is set to require that you specify a -f parameter before giving the cron1.php filename.
Again, your hosting company has probably encountered this and can help you sort it out.

29 Jul 2013, 6:30 AM
#18
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

ok thank you for your help

30 Jul 2013, 1:54 PM
#19
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

can anyone help please? with this script below

  1. can it be used for a cron job?

  2. at the top of it there a space to put url to fetch file can a user name and password be added to script for a passwored url? if so how do i do it?

  3. can i modify the script to over ride an image url so instead of importing the image url that come with the feed file it would use an image url of i choose? if so how do i implement it ?

thankyou

http://www.zen-cart.com/attachment.php?attachmentid=3863&d=1209389792

30 Jul 2013, 9:43 PM
#20
knm_computers avatar

knm_computers

New Zenner

Join Date:
Apr 2011
Location:
UK
Posts:
54
Plugin Contributions:
0

Re: Can I use an auto Import/cron job for this?

also i have had support back from the company that my hosting is with and i got a command off them but when i made the cron job it said no input file specified, he then told me "make sure i have the right path" i tell him they gave me the path and it was php -q /home/username/plubic_html/admin/cron1.php

then he then sent me this:

I have looked at your cron job settings and no command is entered. You may need to seek advice from the scripts publisher, they should offer setup support.

am i suppose to put a command in the cron1.php file?