auto-import csv file every 10 minutes

  • Posts: 1
  • Thank you received: 0
13 years 9 months ago #6817

Can anyone suggest how to auto import a csv file every ten minutes using a cron job or any other way?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 9 months ago #6818

You can look at the page
www.hikashop.com/support/documentation/6...r-documentation.html
which explains a bit our API for plugins.

More specifically, you can define the function onHikashopCronTrigger
Then, you can call the page index.php?option=com_hikashop&ctrl=cron in
your cron scheduler every 10 minutes so that it triggers this function
of your plugin.
Finally, in that function, you can use that code:

$helper = hikashop::get('helper.import');
$contentFile = file_get_contents($feed_path);
$helper->handleContent($contentFile);


$feed_path needs to contain the absolute path to the csv file. Your
CSV will need to have its headers according to our documentation, or
you will have to add the columnNamesConversionTable parameter to the
$helper object with a conversion array like this for example:

$helper->columnNamesConversionTable = array( 'code' =>
'product_code','name' => 'product_name');

This example suppose that the product code column is called code
instead of product_code which is the name of the column in hikashop
and that the product name column is called name instead of
product_name in your CSV.

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12478

Hi,

I'm trying to setup my cron with this conversion for column headings.
Could you post a full example of a cron with this function embedded?

Thanks in advance!

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12487

Hi,

I can't seem to get the cron to import a csv operational... :-(
If I'm correct, you need to adapt the cron.php with the codes in this post, which I did.
Nevertheless, a server error occurs. Would you be so kind to take a look at the code I adpated to see if there are any (obvious) errors? If so, I'll send it for verifiction.

Last edit: 13 years 7 months ago by Nikajoloem.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12488

Hi,

As I said in my previous post the code should be something like this:
class plgHikashopData_feed extends JPlugin{
function onHikashopCronTrigger(&$messages){
$helper = hikashop::get('helper.import');
$helper->columnNamesConversionTable = array( 'code' =>'product_code','name' => 'product_name');
$helper->createCategories = true;
$helper->overwrite = true;
$helper->header_errors = false;
$contentFile = file_get_contents('PATH_TO_MY_FILE');
$helper->handleContent($contentFile);
}
}

You can post your code, we'll see if we can see something wrong in it.

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12490

Thank you fro your extremely quick respons!

Please find the code + the error:

code removed

Last edit: 13 years 7 months ago by Nikajoloem.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12491

You need to create a plugin for that and put your code in the plugin and NOT put your code directly in the hikashop controller file.
Here is some information about how to create a plugin :
docs.joomla.org/Creating_a_Plugin_for_Joomla_1.5

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12521

Hi,

thanks for the clarification.
I created a plugin (

File Attachment:

File Name: HikashopData_feed.zip
File Size:2 KB
- based on an existing plugin), installed and activated it without issues.

The cron task runs without errors, but still no data is being imported.

What am I missing?

Regards,
Nikajoloem

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12525

In the php file, the class should be: plgHikashopHikashopData_feed because you need to have the group of the plugin (HikaShop) and the plugin name (HikashopData_feed) in the name of the class.

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12531

Still no luck :-(

Is there anything else? Do I need to change the cron url too?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12532

Did you configure your cron ?
If you trigger the cron URL manually (by loading the URL in your browser) does it trigger the plugin ?

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12534

I triggered it manually (link in the backend). I get the message that the cron was triggered, but I'm not sure if it triggered the plugin.
This is the link: http://my_url/index2.php?option=com_hikashop&ctrl=cron

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12535

What you should do is edit you plugin php file directly in the folder plugins/hikashop and add some traces to see if it goes there.

Add one before the class declaration like this:
echo "before loading class";

one in the class constructor and one in the cron function.
That way, when triggering the url, you will see on your browser the traces if the cron went there.

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12536

Hi,

the message appears when triggering the url. Still no import :-(

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12537

Did you put a message in the function onHikashopCronTrigger ? Did you see it ?

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12538

I'm lost here...

Please find attached the php file.
Could you help me to put the message in the rigth place?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12539

There were no files in your message. Could you try again to upload your file ?

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12541

Second try...

Now in .zip (php-extension is not allowed...)

File Attachment:

File Name: HikashopDa...0329.zip
File Size:1 KB

Attachments:
Last edit: 13 years 7 months ago by Nikajoloem.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #12545

I've added some traces in the cron function. Let us know how that goes.

File Attachment:

File Name: HikashopDa...0329.zip
File Size:1 KB

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
13 years 7 months ago #12548

The following message appears, so I assume the plugin was triggered.
Curious to find out why it isn't working...

File Attachment:

File Name: triggered.zip
File Size:16 KB

Attachments:
Last edit: 13 years 7 months ago by Nikajoloem.

Please Log in or Create an account to join the conversation.

Time to create page: 0.092 seconds
Powered by Kunena Forum