Support » Plugin: WooCommerce » Categories ordering not working on REST API on 3.6.3

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support RK

    (@riaanknoetze)

    Hi there,

    Admittedly I don’t fully understand the question here: In the thread you linked to, it mentions the homepage template as powered by Storefront. In this thread, you’re referring to the REST API that’s serving categories – Would you mind elaborating a bit more on how these two threads are linked? Also, what REST API query are you using when fetching the categories?

    mic365

    (@mic365)

    I apologize for not being clear, the problem on both cases is the same and happens upon upgrading, hence my thought there may be a mutual cause. I’ll focus on my case.

    Problem:

    After ordering the categories on the back end, if you issue a categories request to the REST API, the categories are returned ordered alphabetically.

    Way to reproduce:

    1. Install a fresh WP using wp cli.
      • Install WC plugin using wp cli.
      • Define several categories on the backend and order them, not in an alphabetical order.
      • Problem: the categories are returned in an alphabetical ordered.

    Environment:

    $ vagrant --version
    Vagrant 2.2.4
    $ cat Vagrantfile  | grep config.vm.box
      config.vm.box = "johannesHome/bitnami-wordpress"
    
    # inside vagrant guest os
    $ uname -a
    Linux pc-test 3.16.0-4-amd64 #1 SMP Debian 3.16.51-2 (2017-12-03) x86_64 GNU/Linux
    $ wp core version
    5.2
    $ wp plugin status woocommerce
    Plugin woocommerce details:
        Name: WooCommerce
        Status: Active
        Version: 3.6.3
        Author: Automattic
        Description: An eCommerce toolkit that helps you sell anything. Beautifully.
    

    Thanks,
    Mickey.

    • This reply was modified 9 months ago by mic365.
    • This reply was modified 9 months ago by mic365.
    Plugin Support RK

    (@riaanknoetze)

    If I’m reading that correctly, the reason is that get_the_term_list does not provide for the order parameter to be used.

    I’m not sure I understand you.

    Do you mean we should add a plugin that alters get_the_term_list behavior? Generally we prefer not to interfere with your code.

    • This reply was modified 8 months, 4 weeks ago by mic365.
    Plugin Support Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    Hi there,

    You need to specify the order_by and the order attribute during the REST API request, for instance:

    
    https://domain.com/wp-json/wc/v2/products/categories/?filter[orderby]=id&order=desc&consumer_key=ck_12345&consumer_secret=cs_12345
    

    I just tested on a local install and I can confirm that it works as expected with the latest WC version.

    • This reply was modified 8 months, 4 weeks ago by Remi Corson.

    Got you.

    In our case we need the categories as were ordered via the back end so there is no specific field we can supply to the order_by. I believe we’d need the order from wp_termmeta. Can that be done via the url as well?

    Thanks for the help 👍
    Mickey.

    Hi Remi, do you happen to have any updates on this?

    Thanks for the help,
    Mickey.

    Plugin Support Con Schneider

    (@conschneider)

    Automattic Happiness Engineer

    Hi Mickey,

    In our case we need the categories as were ordered via the back end so there is no specific field we can supply to the order_by.

    Yes, that makes sense. I would:

    * Write a small function that gets and returns the current parameter that is set in the backend. Register a custom endpoint for this function to expose it.
    * Pass it to categories API callback function as a parameter or pass it to your API request building function.
    * And then execute the call.

    Kind regards,

    We ended up hooking woocommerce_rest_product_cat_query and setting $prepared_args['menu_order'] = 1;, since you can not pass this parameter on the url.

    From my point of view it’s a bug on wc_change_get_terms_defaults — I’d expect the default sort not to be by name if the categories were manually ordered on the backend.

    Other than this we found 3.6.x to be a great improvement, especially in terms of speed over larger data sets. Great job 👍

    • This reply was modified 7 months, 3 weeks ago by mic365.
    • This reply was modified 7 months, 3 weeks ago by mic365.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Categories ordering not working on REST API on 3.6.3’ is closed to new replies.