Author Topic: Add new filter in the orders page  (Read 405 times)

Kuubs

  • Jr. Member
  • **
  • Posts: 346
Add new filter in the orders page
« on: June 28, 2022, 10:22:07 am »
Hello,

Id like to add a new filter to the orders overview page in the backend. I'd like to add a category selector so that my orders can be filtered via categories. How can I do this?

Where can I change the $this->lists that are available? For now there is only the status list, vendor list and bulk order status list. I'd like to add the category list to this as well.

And then I also need to change each order that the cateogry is available as field, so I probably need to change the query that gets the orders.


Kuubs

  • Jr. Member
  • **
  • Posts: 346
Re: Add new filter in the orders page
« Reply #1 on: June 29, 2022, 15:45:39 pm »
Ok I found the solution. Unfortunately this involves a core hack. Maybe the developers can implement this?

orders model:

Code: [Select]
//line 436 where the following code begins:

                $order_status_code = vRequest::getString('order_status_code', false);
if ($order_status_code and $order_status_code!=-1){
$where[] = ' o.order_status = "'.$order_status_code.'" ';
}

//Add shipping method
$order_shipment_code = vRequest::getString('order_shipment_code', false);

if ($order_shipment_code and $order_shipment_code!=-1){
$where[] = ' sm.virtuemart_shipmentmethod_id = "'.$order_shipment_code.'" ';
}

//Add category method
$order_category_code = vRequest::getString('order_category_code', false);

if ($order_category_code and $order_category_code!=-1){
$where[] = ' pc.virtuemart_category_id = "'.$order_category_code.'" ';
}


$groupBy = 'GROUP BY virtuemart_order_id';


Same file but change the. follow method:
private function getOrdersListQuery

Code: [Select]

//add these 4 lines
LEFT JOIN #__virtuemart_order_items as oi
ON o.virtuemart_order_id = oi.virtuemart_order_id
LEFT JOIN #__virtuemart_product_categories as pc
ON oi.virtuemart_product_id = pc.virtuemart_product_id';


Now in the template override I added 2 filter select lists:

template/html/com_virtuemart/orders/orders.php

Code: [Select]
//At the start add the following code to get the shipment methods and categories
$shipmentModel= VmModel::getModel('shipmentmethod');
$shipmentModel->_noLimit = true;
$shipmentModelList = $shipmentModel->getShipments();

$empty = new stdClass();
$empty->virtuemart_shipmentmethod_id = -1;
$empty->shipment_name = "All shipment methods";

array_unshift($shipmentModelList, $empty);

$categoryModel = VmModel::getModel('Category');
$cats = $categoryModel->getCategoryTree();

$empty = new stdClass();
$empty->virtuemart_category_id = -1;
$empty->category_name = "All categories";

array_unshift($cats, $empty);

$order_shipment_code = vRequest::getCmd('order_shipment_code','');



$order_category_code = vRequest::getCmd('order_category_code','');

?>

//Than add new table columns in the header:

<td align="left" style="min-width:190px;width:21%;">
<?php echo "Category" ':' ?>

<?php echo JHtml::_('select.genericlist'$cats'order_category_code''class="inputbox" onchange="this.form.submit(); return false;"''virtuemart_category_id''category_name'$order_category_code);?>

                    </td>
<td align="left" style="min-width:190px;width:21%;">
<?php echo "Shipment" ':' ?>
<?php echo JHtml::_('select.genericlist'$shipmentModelList'order_shipment_code''class="inputbox" onchange="this.form.submit(); return false;"''virtuemart_shipmentmethod_id''shipment_name'$order_shipment_code);?>

                    </td>


There you go you have filtering options in admin area