2

I am creating a custom dashboard for delivery guys where I want to show the order list in two divs. One is Pending Orders and second is History. Basically I want to filter my order list by order status. Here is code:

{% set pastOrders = craft.commerce.orders.relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pastOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}
4

I would run two queries and then you could utilise the completed() parameter: https://craftcommerce.com/docs/craft-commerce-orders#completed

{% set pastOrders = craft.commerce.orders.completed(true).relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pastOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}

{% set pendingOrders = craft.commerce.orders.completed(false).relatedTo({targetElement: currentUser, field: 'deliveryGuy'}).find() %}
{% for order in pendingOrders %}
   {{order.id}}
   {{order.orderStatus.name}}
{% endfor %}
| improve this answer | |
1

Good solution by Luke,

But if you are still looking for a query to filter Orders by statuses, here's a working solution :

{% for pastOrders in craft.commerce.orders.customer(craft.commerce.customer).orderStatus(1).find() %}
    {{order.id}}
    {{order.orderStatus.name}}
{% endfor %}

{% for pendingOrders in craft.commerce.orders.customer(craft.commerce.customer).orderStatus(2).find() %}
    {{order.id}}
    {{order.orderStatus.name}}
{% endfor %}

Where 1 is the ID of your pasts orders and 2 is the ID of pending order status...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.