Front-end vendor export orders to csv/xls - filter

  • Posts: 62
  • Thank you received: 1
7 years 10 months ago #243713

-- HikaShop version -- : 2.6.3
-- HikaMarket version -- : 1.7.0
-- Joomla version -- : 3.5.1
-- PHP version -- : 5.6
-- Browser(s) name and version -- : Chrome latest
-- Error-message(debug-mod must be tuned on) -- : no error

Hello,

When a vendor is on the front-end and want's to export his orders, he/she can filter on a date (from/to). In the date field it also shows a time. Is it possible to have the export being filtered on time as well?

For example, I only whish to have the orders of this morning (from midnight 0:00 to 12:00 afternoon - see screenshot attached).

Currently it only filters on date as far as I can tell. I tried to modify it in the export view, but it seems the orders are already fetched when it get's to that view.

Thanks in advance for your assistance!

Cheers,
Teeuwis

Attachments:

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

  • Posts: 26032
  • Thank you received: 4006
  • MODERATOR
7 years 10 months ago #243725

Hi,

The filters for the export are handle directly by the HikaMarket core, in the "ordermarket/view.html.php" you will be able to find that code

$filter_end = explode('-', $pageInfo->filter->filter_enddate);
$noHourDay = explode(' ', $filter_end[2]);
$filter_end[2] = $noHourDay[0];
$filter_end = mktime(23, 59, 59, $filter_end[1], $filter_end[2], $filter_end[0]);
The filter_end variable is generated with a fixed hour in order to select the end of the day.
And that's the same thing for the filter_start variable, which have a fixed hour to select the beginning of the day.

If you want to change the behavior without modifying the HikaMarket core, you can use a plugin and the trigger "onBeforeOrderExportQuery".
$dispatcher->trigger('onBeforeOrderExportQuery', array(&$select, &$from, &$filters, &$order, &$searchMap, &$orderingAccept) );
In your plugin you can read the input values and handle them differently (with the time).
To simplify the update of filters, the next HikaMarket release will have "named" filters.

Instead of having
$filters[] = 'hkorder.order_created < '.$filter_end;
there will be
$filters['order_created'] = 'hkorder.order_created < '.$filter_end;
So in a plugin, you can easily replace the filter on the "order_created" without having to perform a loop and analyze the content.

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: 62
  • Thank you received: 1
7 years 10 months ago #245037

Hello Jerome,

Thank you very much for your helpfull feedback. Here is the end result and it works like a charm. It might help others to have the same functionality.

function onBeforeOrderExportQuery(&$select, &$from, &$filters, &$order, &$searchMap, &$orderingAccept) {
	$jinput = JFactory::getApplication()->input;
	$filter_startdate = $jinput->getString('filter_startdate', 0);
	$filter_enddate = $jinput->getString('filter_enddate', 0);

	if(!empty($filter_enddate)) {
		$filter_end = explode('-', $filter_enddate);
		$noHourDay = explode(' ', $filter_end[2]);
		$filter_end[2] = $noHourDay[0];
		$time = explode(':', $noHourDay[1]);
		$filter_end = mktime($time[0], $time[1], 59, $filter_end[1], $filter_end[2], $filter_end[0]);
	}

	if(!empty($filter_startdate)) {
		$filter_start = explode('-',$filter_startdate);
		$noHourDay = explode(' ',$filter_start[2]);
		$filter_start[2] = $noHourDay[0];
		$time = explode(':', $noHourDay[1]);
		$filter_start = mktime($time[0], $time[1], 0, $filter_start[1], $filter_start[2], $filter_start[0]);

		if(!empty($filter_enddate)) {
			$newfilter = 'hkorder.order_created > '.$filter_start. ' AND hkorder.order_created < '.$filter_end;
		} else {
			$newfilter = 'hkorder.order_created > '.$filter_start;
		}
	} else if(!empty($filter_enddate)) {
		$newfilter = 'hkorder.order_created < '.$filter_end;
	}

	foreach ($filters as $key => $value) {
		if(strpos($value, "order_created")) { // time filter found
			$filters[$key] = $newfilter;
		}
	}
    return true;
}

The following user(s) said Thank You: Jerome

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

Moderators: Obsidev
Time to create page: 0.058 seconds
Powered by Kunena Forum