Filter orders by employee in the PrestaShop Back Office

In this quick tip we will explore methods to filter the PrestaShop back office orders list by employee profile.

Watch the screencast

Text Version

This tutorial can be applied to ThirtyBees as well!

To filter the PrestaShop order list we simply have to add conditions to the “where” clause of the AdminOrdersController.php, located at controllers/admin.
What we want to do is append the extra conditions to the construct method, around line 68:

if($this->context->employee->id_profile == 1)
        {
            $this->_where .= ' AND os.id_order_state = 2';
            $this->_where .= ' AND country.id_country = 21';
            $this->_where .= ' AND a.module = "bankwire"';
        }

The first condition will filter orders by current status, in this case “Payment Accepted”; The second will only display orders shipping to the United States; the third one will narrow the results to the ones paid by bank wire.
We are using the employee’s profile ID to trigger the conditions, so that only the selected department will be affected.

These snippets will be enough in most cases, but if you want to be extra careful, it’s better to also prevent direct access to the single order view, by editing the renderView method:

// At the beginning of the renderView method, after the $order variable has been validated, we can use this to prevent access if the order is not set to payment accepted. We can do the same with the bankwire method as we saw above, by simply changing the property name from current_state to module
if($this->context->employee->id_profile == 1)
        {

            if($order->current_state != 2)
            {
                $this->errors[] = Tools::displayError('You are not authorized to see this page.');
                return;
            }
        }

We can also do the same for the country condition, around line 1650, after $addressDelivery has been declared:

        if($this->context->employee->id_profile == 1) 
        {
            if($addressDelivery->id_country != 21)
            {
                $this->errors[] = Tools::displayError('You are not authorized to see this page.');
                return;
            }
        }

You like the tuts and want to say "thank you"? Well, you can always feel free to donate:

You like the tuts and want to say "thank you"? Well, you can always feel free to donate: