Jump to content

Filter order history in customer account / frontend


Martin511

Recommended Posts

Hello.

If a customer has placed more than 20 orders in the shop and is looking for a former order himself, it quickly becomes confusing.

I find it almost a basic requirement that customers can filter or search through their orders in an online shop - but I have learned that nothing is a matter of course at Pretashop.

Now I've been looking for a really long time, but I can't even find a paid module for this.
Can it really be that you have to have something like this programmed individually?

I am grateful for any tips. I am using Prestashop 1.7.7.

Regards
Martin

Link to comment
Share on other sites

The explanation is simple.
Prestashop does not have an environment created for displaying tables in the same way as in Backoffice.
In Frontoffice, everything is displayed in HTML tables.
Each TPL template can have its own solution for filtering in an HTML table.
You can build your own search in the HTML table with very simple JavaScript, which is inserted into the TPL template.
Prestashop is an open source system.

Modify file:

./themes/classic/templates/customer/history.tpl

Link to comment
Share on other sites

{literal}
  <script>
    function myCustomFilterFunction(e) {
      const input = document.getElementById(e);
      const inputStr = input.value.toUpperCase();
      document.querySelectorAll('#tableOrderHiostory tr:not(.filters)').forEach((tr) => {
        const anyMatch = [...tr.children].some(td => td.textContent.toUpperCase().includes(inputStr));
        if (anyMatch) tr.style.removeProperty('display');
        else tr.style.display = 'none';
      });
    }
  </script>
{/literal}

 

 <tr class="filters">
          <th><input id="order_reference" onkeyup="myCustomFilterFunction('order_reference')" type="text" style="width: 100%;" placeholder="{l s='Order reference' d='Shop.Theme.Checkout'}"></th>
          <th><input id="date" onkeyup="myCustomFilterFunction('date')" type="text" style="width: 100%;" placeholder="{l s='Date' d='Shop.Theme.Checkout'}"></th>
          <th><input id="total_price" onkeyup="myCustomFilterFunction('total_price')" type="text" style="width: 100%;" placeholder="{l s='Total price' d='Shop.Theme.Checkout'}"></th>
          <th><input id="payment" onkeyup="myCustomFilterFunction('payment')" type="text" style="width: 100%;" placeholder="{l s='Payment' d='Shop.Theme.Checkout'}"></th>
          <th><input id="status" onkeyup="myCustomFilterFunction('status')" type="text" style="width: 100%;" placeholder="{l s='Status' d='Shop.Theme.Checkout'}"></th>
          <th><input id="invoice" onkeyup="myCustomFilterFunction('invoice')" type="text" style="width: 100%;" placeholder="{l s='Invoice' d='Shop.Theme.Checkout'}"></th>
          <th></th>
        </tr>

 

Link to comment
Share on other sites

14 minutes ago, 4you.software said:
{literal}
  <script>
    function myCustomFilterFunction(e) {
      const input = document.getElementById(e);
      const inputStr = input.value.toUpperCase();
      document.querySelectorAll('#tableOrderHiostory tr:not(.filters)').forEach((tr) => {
        const anyMatch = [...tr.children].some(td => td.textContent.toUpperCase().includes(inputStr));
        if (anyMatch) tr.style.removeProperty('display');
        else tr.style.display = 'none';
      });
    }
  </script>
{/literal}

 

 <tr class="filters">
          <th><input id="order_reference" onkeyup="myCustomFilterFunction('order_reference')" type="text" style="width: 100%;" placeholder="{l s='Order reference' d='Shop.Theme.Checkout'}"></th>
          <th><input id="date" onkeyup="myCustomFilterFunction('date')" type="text" style="width: 100%;" placeholder="{l s='Date' d='Shop.Theme.Checkout'}"></th>
          <th><input id="total_price" onkeyup="myCustomFilterFunction('total_price')" type="text" style="width: 100%;" placeholder="{l s='Total price' d='Shop.Theme.Checkout'}"></th>
          <th><input id="payment" onkeyup="myCustomFilterFunction('payment')" type="text" style="width: 100%;" placeholder="{l s='Payment' d='Shop.Theme.Checkout'}"></th>
          <th><input id="status" onkeyup="myCustomFilterFunction('status')" type="text" style="width: 100%;" placeholder="{l s='Status' d='Shop.Theme.Checkout'}"></th>
          <th><input id="invoice" onkeyup="myCustomFilterFunction('invoice')" type="text" style="width: 100%;" placeholder="{l s='Invoice' d='Shop.Theme.Checkout'}"></th>
          <th></th>
        </tr>

 

Unfortunately it does not work in my shop...

The table fields appear but no filtering is possible.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...