Giter Site home page Giter Site logo

Comments (6)

jasonknight avatar jasonknight commented on September 28, 2024

I have been away awhile on this project. I will have to take a look and see where that functionality is at.

from woocommerce-json-api.

jasonknight avatar jasonknight commented on September 28, 2024

I will be back with the JSON API in about a week. As far as I recall, there is some filter support for some things.

Is this what you are looking for:

   if ( isset( $params['model_filters'] ) && is_array($params['model_filters']) ) {
      JSONAPIHelpers::debug( "Model Filters are Present" );
      JSONAPIHelpers::debug( var_export($params['model_filters'],true) );
      foreach ( $params['model_filters'] as $filter_text=>$filter ) {
        foreach ($filter as $key=>&$value) {
          $value['name'] = substr($wpdb->prepare("%s",$value['name']),1,strlen($value['name']));
        }
        $callback = function ($table) use ($filter) {
            return array_merge($table,$filter);
        };
        JSONAPIHelpers::debug( "Adding filter: " . $filter_text );
        add_filter($filter_text, $callback );
      }
    } else {
      JSONAPIHelpers::debug( "No Model Filters Present" );
    }


It's in the main JSON API class. It allows you to ensure your filters are registered and therefore checked during request.

https://github.com/jasonknight/woocommerce-json-api/blob/master/tests/set_product_variation.php

Shows using it.

from woocommerce-json-api.

j-cimb-barker avatar j-cimb-barker commented on September 28, 2024

Thanks so much for continuing with this. I will give the above a go. I will let you know feedback asap.

from woocommerce-json-api.

jasonknight avatar jasonknight commented on September 28, 2024

I am not sure it is answering your specific situation, this model filter is used to tell the api to load a custom attribute, but that doesn't mean 3rd party plugins will necessarily know about it.

There are significant plans for expansion. Including the ability to pass logic to the call back in the form of a many language implemented in pure PHP. If you look inside the WCAPI models, you may find that there are some filters running, or you could add them, or add the ability to specify filters to run. For instance, what if you added the model_filters and after_load_filters array with a series of strings to call apply_filters with that attribute? Then all you would need to do is add in some logic at attribute load and before save to call model_filters etc. Which is somewhere in the guts already.

from woocommerce-json-api.

jasonknight avatar jasonknight commented on September 28, 2024

Unfortunately, I realize the API is rather daunting at first glance, it's a monstrous effort to compensate for some small issues I have with the internal WooCom API. It's been awhile since I worked on it(mainly it does everything I need so far) so even I am not sure what the hell it does anymore.

from woocommerce-json-api.

jasonknight avatar jasonknight commented on September 28, 2024

Can you give me a specific use case so that I can come up with something? Do you want to filter the whole product, i.e. get_product, or do you want to filter independent attributes? What filters are called? Are you using woocommerce attribute filters? The API generally circumvents WooCommerce entirely.

from woocommerce-json-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.