csv Export path (Order)

  • Posts: 16
  • Thank you received: 0
10 years 7 months ago #149828

Hi,
I try to use the hikashop.
But i want to auto export the order after creation.
I found the "Mass Actions" option.
There i select the a action after creation of a order for export a csv file.
If i leave the path empty the browser will push the csv as download file.

But i want to save it on serverside in a map with unique name so i can make a rotation with my erp packed to pickup and process that csv file.
How i define the path?
I tried with: c:\temp and c:\temp\ but i don't see any file.

Tom

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 7 months ago #149846

Hi,

You need to provide the full path of the CSV file that you want.
So for example:
c:\temp\my_export.csv

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

  • Posts: 16
  • Thank you received: 0
10 years 7 months ago #149893

Hi,
So you need to use a fixed name for the file?
But then the file wil be override every time?
Is there any option that the system generate a randon filename, like ordernumber or customername or somthing?

Cause i want to make a import that check the directory every ... minutes for new files to import direct into our erp system.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 7 months ago #149904

Hi,

There is no such "dynamic" option for the csv path.

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

  • Posts: 16
  • Thank you received: 0
10 years 7 months ago #149984

function onProcessOrderMassActionexportCsv(&$elements,&$action,$k){
		$formatExport = $action['formatExport']['format'];
		$path = $action['formatExport']['path'];
		if(empty($path)){
			ob_get_clean();
		}
		$app = JFactory::getApplication();
		if($app->isAdmin() || (!$app->isAdmin() && !empty($path))){
			$params = new stdClass();
			$params->action['order']['order_id'] = 'order_id';
			unset($action['formatExport']);
			$params = $this->massaction->_displayResults('order',$elements,$action,$k);
			$params->formatExport = $formatExport;
			$params->path = $path;
			$params = $this->massaction->sortResult($params->table,$params);
			$this->massaction->_exportCSV($params);
		}

Is it not possible to edit the php code that you put a fixed path and user the hour/minute/second string .csv as filename?

Last edit: 10 years 7 months ago by Thunder1001.

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

  • Posts: 13201
  • Thank you received: 2322
10 years 7 months ago #149990

Hi,

You can potentially use this kind of code:

	function onProcessOrderMassActionexportCsv(&$elements,&$action,$k){
		$formatExport = $action['formatExport']['format'];
		$path = $action['formatExport']['path'];
		if(empty($path)){
			ob_get_clean();
		}
		$app = JFactory::getApplication();
		if($app->isAdmin() || (!$app->isAdmin() && !empty($path))){
			$params = new stdClass();
			$params->action['order']['order_id'] = 'order_id';
			unset($action['formatExport']);
			$params = $this->massaction->_displayResults('order',$elements,$action,$k);
			$params->formatExport = $formatExport;
			// Added
			$path = str_replace('.csv','-'.date('y-m-d H:m:s').'.csv',$path);
			// EO Added
			$params->path = $path;
			$params = $this->massaction->sortResult($params->table,$params);
			$this->massaction->_exportCSV($params);
		}
	}

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

  • Posts: 16
  • Thank you received: 0
10 years 7 months ago #150036

Hi,
Thx allot, that's what i need :)
But a little fix for other people who need it.
use this one

$path = str_replace('.csv','-'.date('y-m-d H-m-s').'.csv',$path);
instead of
$path = str_replace('.csv','-'.date('y-m-d H:m:s').'.csv',$path);
Cause you cannot have " : " in your filename

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

  • Posts: 75
  • Thank you received: 1
9 years 10 months ago #186637

Hello,

I am also interested to get a csv file with another name everytime I export via massaction.
After finding this solution I looked in the classes directory in the file massaction.php, but I can't find the function you are talking about.

Hope to hear from you,

Kind regards,

Wilfried


Thunder1001 wrote: Hi,
Thx allot, that's what i need :)
But a little fix for other people who need it.
use this one

$path = str_replace('.csv','-'.date('y-m-d H-m-s').'.csv',$path);
instead of
$path = str_replace('.csv','-'.date('y-m-d H:m:s').'.csv',$path);
Cause you cannot have " : " in your filename

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

  • Posts: 193
  • Thank you received: 76
9 years 10 months ago #186771

For Hikashop 2.3.5 in file plugins\hikashop\massaction_order\massaction_order.php on line 302
replace

$params->path = $path;

with
$params->path = str_replace('.csv','-'.date('y-m-d H-m-s').'.csv',$path);

The following user(s) said Thank You: Xavier, wilfried

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

  • Posts: 75
  • Thank you received: 1
9 years 10 months ago #186900

Thanks,

What should I fill in at the "export path" field?
I tried several combinations but I can't get a csv with such a filename into the directory.

Kind regards, Wilfried

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

  • Posts: 193
  • Thank you received: 76
9 years 10 months ago #186903

It have to absolute path to csv file.
For example /var/www/public_html/media/com_hikashop/upload/safe/orders.csv
where /var/www/public_html is absolute path to your site.

To find your absolute path, take a look in Global Configuration, tab System. There is "Path to Log Folder ". It's absolute path to logs folder.

The following user(s) said Thank You: wilfried

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

  • Posts: 75
  • Thank you received: 1
9 years 10 months ago #186920

I tried it with the path but without the filename. I thought that the filename was added by the new code. Now I see that the date is added to the name I fill in with the path.
So it works now.

Thanks!!!.

Kind regards, Wilfried

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

  • Posts: 75
  • Thank you received: 1
9 years 10 months ago #187130

korzo wrote: For Hikashop 2.3.5 in file plugins\hikashop\massaction_order\massaction_order.php on line 302
replace

$params->path = $path;

with
$params->path = str_replace('.csv','-'.date('y-m-d H-m-s').'.csv',$path);


This works, but there is only one mistake. The second m that is supposed to stand for minutes should be an i
$params->path = str_replace('.csv','-'.date('y-m-d H-i-s').'.csv',$path);

The following user(s) said Thank You: Jerome

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

  • Posts: 231
  • Thank you received: 4
  • Hikaserial Standard
9 years 9 months ago #190181

AWESOME, thanks so much. I hope the HikaShop dev team take note of this and incorporate a function in a later release to allow customisation of the CSV filename without modifying the core files.

I have one question, is it possible to include the order_number in the filename? I've tried modifying the str_replace to include the order_number variable to no avail!

Thanks

Lee

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

  • Posts: 13201
  • Thank you received: 2322
9 years 9 months ago #190199

Hi,

We will add this feature in a future version of HikaShop ;)
To have the order number in the file name you need something like:

$params->path = str_replace('.csv','-'.$elements[0]->order_number.'.csv',$path);

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

  • Posts: 44
  • Thank you received: 0
9 years 7 months ago #196551

Hi,

and is it also possible to get joomla username to the CSV filename?

Thanks in advance.

Denis

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 7 months ago #196552

Hi,

In the same way that you can set the order number in the CSV file name ; you can put the username too.
But you have first to catch the Joomla username (which will be code more related to Joomla, even if you can use the function hikashop_loadUser to get the current logged user object).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 44
  • Thank you received: 0
9 years 7 months ago #196609

Hi Jerome,

not sure if I follow you correctly.

I'm using mass action export CSV after order creation, where I have order_number, username, order_product_code, order_product_quantity. So the question is if it's possible to get username from mentioned fields to use it in filename.
Can you please point me closer on some piece of code I can start with?

Thanks in advance.

Denis

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

  • Posts: 13201
  • Thank you received: 2322
9 years 7 months ago #196739

Hi,

To have the username in the csv file name, you have to check the "username" checkbox in the mass action settings, then still in the file "plugins\hikashop\massaction_order\massaction_order.php" and function "onProcessOrderMassActionexportCsv()" just find the username which is present in the PHP object $elements.

It should be there: $elements[0]->username so use this in the filename.

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

  • Posts: 44
  • Thank you received: 0
9 years 7 months ago #196770

Hi, Xavier

I've tried this piece of code

$params->path = str_replace('export.csv',$elements[0]->order_id.'_'.$elements[0]->order_number.'_'.$elements[0]->username.'_'.date('y-m-d_H-m-s').'.csv',$path);

Successfully got order_id, order_number, but username is missing. I have "username" checkbox checked in the mass action settings and I have username inside CSV file.

Denis

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

Time to create page: 0.129 seconds
Powered by Kunena Forum