Skip to main content

auto-import csv file every 10 minutes

More
15 years 7 months ago #6817 by jmzyla
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.

More
15 years 7 months ago #6818 by nicolas
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.

More
15 years 6 months ago #12478 by Nikajoloem
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.

More
15 years 6 months ago - 15 years 6 months ago #12487 by Nikajoloem
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: 15 years 6 months ago by Nikajoloem.

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

More
15 years 6 months ago #12488 by nicolas
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.

More
15 years 6 months ago - 15 years 5 months ago #12490 by Nikajoloem
Thank you fro your extremely quick respons!

Please find the code + the error:

code removed
Last edit: 15 years 5 months ago by Nikajoloem.

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

More
15 years 6 months ago #12491 by nicolas
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.

More
15 years 5 months ago #12521 by Nikajoloem
Hi,

thanks for the clarification.
I created a plugin (

This attachment is hidden for guests.
Please log in or register to see it.

- 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

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

More
15 years 5 months ago #12525 by nicolas
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.

More
15 years 5 months ago #12531 by Nikajoloem
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.

More
15 years 5 months ago #12532 by nicolas
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.

More
15 years 5 months ago #12534 by Nikajoloem
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.

More
15 years 5 months ago #12535 by nicolas
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.

More
15 years 5 months ago #12536 by Nikajoloem
Hi,

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

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

More
15 years 5 months ago #12537 by nicolas
Did you put a message in the function onHikashopCronTrigger ? Did you see it ?

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

More
15 years 5 months ago #12538 by Nikajoloem
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.

More
15 years 5 months ago #12539 by nicolas
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.

More
15 years 5 months ago - 15 years 5 months ago #12541 by Nikajoloem
Second try...

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

This attachment is hidden for guests.
Please log in or register to see it.

Last edit: 15 years 5 months ago by Nikajoloem.

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

More
15 years 5 months ago #12545 by nicolas
I've added some traces in the cron function. Let us know how that goes.

This attachment is hidden for guests.
Please log in or register to see it.

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

More
15 years 5 months ago - 15 years 5 months ago #12548 by Nikajoloem
The following message appears, so I assume the plugin was triggered.
Curious to find out why it isn't working...

This attachment is hidden for guests.
Please log in or register to see it.

Last edit: 15 years 5 months ago by Nikajoloem.

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

Time to create page: 0.356 seconds
Powered by Kunena Forum