Filter export based on order custom field dropdown

  • Posts: 171
  • Thank you received: 9
10 years 7 months ago #149872

Hi,

Tried to figure it out, but do not find any relevant information connecting to filtering order list.

Do we have an option on to filter orders on orderlist page and on export page based on custom order fileds?
Maybe it can be just a hack, or some lines to be added to ordermarket/export_show.php and ordermarket/listing.php

Thanks again,
PePe

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 7 months ago #149897

Hi,

Can you describe me the kind of filtering you want to do for the export ?

Thanks


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: 171
  • Thank you received: 9
10 years 7 months ago #149899

1.) Vendor dropdown: Vendors
2.) Field: order_location: Dropdown Locations
3.) Field: product_costtype: Dropdown type of costs

Jerome wrote: Hi,

Can you describe me the kind of filtering you want to do for the export ?

Thanks

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 7 months ago #149993

Hi,

Does your custom fields are already dropdown custom fields ?
I am analyzing your requirements and, it should be possible thanks to overrides to have the wanted result but it could be easier to put the filters directly in the SQL query and not process the exported data manually in PHP.

But I will require more details about your custom fields in order to know if we can use them directly or not.

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: 171
  • Thank you received: 9
10 years 7 months ago #149995

Jerome wrote: Hi,

Does your custom fields are already dropdown custom fields ?
I am analyzing your requirements and, it should be possible thanks to overrides to have the wanted result but it could be easier to put the filters directly in the SQL query and not process the exported data manually in PHP.

But I will require more details about your custom fields in order to know if we can use them directly or not.

Regards,


Yes, they are already dropdown. Attach a few screenshots how they looks like to not misunderstood.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 7 months ago #150272

Hi,

Sorry for the delay.
I analyzed your requirements in order to see if we can integrate something like that directly in the export system.
The idea was to add a new "display" option for the custom field to put it as a filter for the exports.
The main problem is that the custom field, depending his type, won't react the same. And if you have a dropdown without an "empty" element, you can't deactivate the filter by selecting an element in the list. It means that the system should be more complex to add a special checkbox or something like that : to deactivate a filter.

Today, you can do this stuff manually ; by overriding the view "export_show" and also create a custom plugin to add your filters in the export SQL query.
For the moment there is no trigger for that specific purpose but we will add them into HikaMarket and HikaShop. It think it will be a good improvement for customization.
In your "export_show" override, the best will be to create manually the dropdowns, because you can't re-use the custom field if there is no element in the list without any value (to not apply the filter) unless you always want to apply the filters and never do a global export.

The other solution is to integrate the system I described in the first part. But it will require some time and for the moment I am mostly focused on the new order system. After that I want to finish the product edition system with the support of characteristics.
So, I can add it in the TODO list, for sure, but I can't guarantee that it will be added in a short time.

Kind 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: 171
  • Thank you received: 9
10 years 7 months ago #150279

Thanks for the analyzis. At least - hopefully - I give a useable point where the team can upgrade the system later.

You mentioned the customly added dropdown to export view. Could you give me a direction point/custom code snippet how to solve that?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 7 months ago #150471

Hi,

So the idea is to override the view "ordermarket | export_show" in order to add new fields.
These fields will be read by the custom plugin to override the SQL query made for the export.
Because you do not have empty value in your custom field, you will have to put the dropdown manually

$values = array(
	JHTML::_('select.option', '', JText::_('NO_FILTER')),
	JHTML::_('select.option', 'Bérlet', 'Bérlet'),
	JHTML::_('select.option', '...', '...'),
	JHTML::_('select.option', '...', '...')
);
echo JHTML::_('select.genericlist', $values, 'filter_koltseg_jelleg', '', 'value', 'text', '');
And do a " JRequest::getValue('filter_koltseg_jelleg', '') " in the custom plugin to read the value and add the filter in the export SQL query.

To do so, you have to edit the file "component/com_hikamarket/ordermarket/view.html.php" and put this code for the export
		$select = '';
		$from = '';

		JPluginHelper::importPlugin('hikashop');
		$dispatcher = JDispatcher::getInstance();
		$dispatcher->trigger('onBeforeOrderExportQuery', array(&$select, &$from, &$filters, &$order, &$searchMap, &$orderingAccept) );

		$this->processFilters($filters, $order, $searchMap, $orderingAccept);

		//
		// Data / Database
		//
		$query = 'FROM '.hikamarket::table($cfg['table']).' AS hkorder '.
			'LEFT JOIN '.hikamarket::table('shop.user').' AS hkuser ON hkorder.order_user_id = hkuser.user_id '.
			'LEFT JOIN '.hikamarket::table('joomla.users').' AS juser ON hkuser.user_cms_id = juser.id '.
			$from.' '.$filters.' '.$order;
		if(!empty($select) && substr($select, 0, 1) != ',')
			$select = ','.$select;
		$db->setQuery('SELECT hkorder.*, hkuser.*, juser.name, juser.username '.$select.$query);
I didn't finished all my tests for the moment but this code should work and provide all required features.

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.
The following user(s) said Thank You: pepecortez

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

  • Posts: 171
  • Thank you received: 9
10 years 2 months ago #169472

Tried to do it, but with no luck:

Dropdowns shown correctly, it's OK. (ordermarket | export_show)
Also added your code snippet to component/com_hikamarket/ordermarket/view.html.php

Tried to add "JRequest::getValue('filter_koltseg_jelleg', '') " but thrown out error in Joomla 3, also tried it with JRequest::get('filter_koltseg_jelleg', '') but nothing happened (maybe I put it to wrong place in the plugin )

So I tried an other way as I realized I should have to filter more fields as well.

In ordermarket | export_show I changed your code to this (and repeated it for all the necessary fields, with different datas).

For example:

echo JHTML::_('select.genericlist', $values_koltseghely, 'data[export][filter_koltseghely]', '', 'value', 'text', '');
echo JHTML::_('select.genericlist', $values_koltsegjelleg, 'data[export][filter_koltseg_jellege]', '', 'value', 'text', '');
echo JHTML::_('select.genericlist', $values_tovabbterhelesikod, 'data[export][filter_tovabbterhelesikod]', '', 'value', 'text', '');
etc...

In "component/com_hikamarket/ordermarket/view.html.php" I added:
$koltseghely = $formData['export']['filter_koltseghely'];
$koltsegjelleg = $formData['export']['filter_koltseg_jellege'];
$tovabbterhelesikod = $formData['export']['filter_tovabbterhelesikod'];
		
if(!empty($koltseghely))
$filters[] = 'hkorder.order_vendor_id = ' . $db->Quote($koltseghely);
		
if(!empty($koltsegjelleg))
$filters[] = 'hkproduct.koltseg_jellege = ' . $db->Quote($koltsegjelleg);
		
if(!empty($tovabbterhelesikod))
$filters[] = 'hkorderproduct.tovabbterhelesikod = ' . $db->Quote($tovabbterhelesikod);

and modified the SQL query to load the necessary fields:
$query = 'FROM '.hikamarket::table($cfg['table']).' AS hkorder '. 'LEFT JOIN '.hikamarket::table('shop.user').' AS hkuser ON hkorder.order_user_id = hkuser.user_id '.
'LEFT JOIN '.hikamarket::table('joomla.users').' AS juser ON hkuser.user_cms_id = juser.id '.
'LEFT JOIN '.hikamarket::table('shop.order_product').' AS hkorderproduct ON hkorder.order_id = hkorderproduct.order_id '. 
'LEFT JOIN '.hikamarket::table('shop.product').' AS hkproduct ON hkorderproduct.order_product_code = hkproduct.product_code '.
$from.' '.$filters.' '.$order;
		
if(!empty($select) && substr($select, 0, 1) != ',')
$select = ','.$select;
$db->setQuery('SELECT hkorder.*, hkuser.*, juser.name, juser.username, hkorderproduct.*, hkproduct.* '.$select.$query);

Where am I wrong?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 months ago #169480

Hi,

If you field is "data[export][filter_koltseghely", you can access it using JRequest::getVar('filter_koltseghely'), you have to get an array for the key "data".
Like you "did" for the rest of your code in the view

$koltseghely = $formData['export']['filter_koltseghely'];
where $formData is the "data" array, read using
$formData = JRequest::getVar('data', array(), '', 'array');

For the rest, like that I can't tell you. It looks good but I don't know the result.
I prefer to link product/order_product using the product_id and not the product_code..
Otherwise, I don't know what is wrong because I don't have the required information for that : what's the result ? What's the problem ?

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: 171
  • Thank you received: 9
10 years 2 months ago #169493

Oh, maybe I found the problem.
The problem was the SQL syntax was OK, but as I exporting rows based on products by custom plugin, I used the extended new SQL query not in the right place.

Now using it before:

$rows = $db->loadObjectList('order_id');

and now filtering correctly as I see.

The following user(s) said Thank You: Jerome

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

  • Posts: 171
  • Thank you received: 9
10 years 2 months ago #169497

Sorry, just catch a small problem:
There's a value option 0 in a dropdown:

<dt class="hikamarket_order_export_tovabbterhelesikod"><label><?php echo JText::_('Továbbterhelési kód:'); ?></label></dt>
<dd class="hikamarket_order_export_tovabbterhelesikod">
<?php 
$values_tovabbterhelesikod = array(
JHTML::_('select.option', '', JText::_('No filter')),
JHTML::_('select.option', '0', '0'),
JHTML::_('select.option', '1', '1'),
JHTML::_('select.option', '2', '2'),
JHTML::_('select.option', '3', '3'),
JHTML::_('select.option', '4', '4')
);
echo JHTML::_('select.genericlist', $values_tovabbterhelesikod, 'data[export][filter_tovabbterhelesikod]', '', 'value', 'text', ''); ?>
</dd>

If 0 is choosen SQL is not filtering for 0, show all values from the column. Looks like it's using value 0 as no filter. Is there a trick to solve that?

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

  • Posts: 171
  • Thank you received: 9
10 years 2 months ago #169534

pepecortez wrote: Sorry, just catch a small problem:
There's a value option 0 in a dropdown:

<dt class="hikamarket_order_export_tovabbterhelesikod"><label><?php echo JText::_('Továbbterhelési kód:'); ?></label></dt>
<dd class="hikamarket_order_export_tovabbterhelesikod">
<?php 
$values_tovabbterhelesikod = array(
JHTML::_('select.option', '', JText::_('No filter')),
JHTML::_('select.option', '0', '0'),
JHTML::_('select.option', '1', '1'),
JHTML::_('select.option', '2', '2'),
JHTML::_('select.option', '3', '3'),
JHTML::_('select.option', '4', '4')
);
echo JHTML::_('select.genericlist', $values_tovabbterhelesikod, 'data[export][filter_tovabbterhelesikod]', '', 'value', 'text', ''); ?>
</dd>

If 0 is choosen SQL is not filtering for 0, show all values from the column. Looks like it's using value 0 as no filter. Is there a trick to solve that?


Solution is checking value with isset and not with !empty:
if(isset($formData['export']['filter_tovabbterhelesikod'])){
$filters[] = 'hkorderproduct.tovabbterhelesikod = ' . $db->Quote($tovabbterhelesikod);
}

or
if($formData['export']['filter_tovabbterhelesikod'] != NULL )

Last edit: 10 years 2 months ago by pepecortez. Reason: Plus info

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 months ago #169499

Hi,

Or, change the check

if(!empty($tovabbterhelesikod))
To
if(!empty($tovabbterhelesikod) || $tovabbterhelesikod === '0')

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.
Last edit: 10 years 2 months ago by Jerome.
The following user(s) said Thank You: pepecortez

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

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