• Resolved jnz31

    (@jnz31)


    hi. i simply tried the following: limit the products to a price bellow 100 via following url: /wp-json/cocart/v2/products?max_price=100

    the response is

    <br />
    <b>Fatal error</b>:  Uncaught Error: Call to undefined method CoCart_Products_V2_Controller::add_meta_query() in /var/www/html/web/app/plugins/cart-rest-api-for-woocommerce/includes/api/cocart/v1/products/class-cocart-products-controller.php:592
    Stack trace:
    #0 /var/www/html/web/app/plugins/cart-rest-api-for-woocommerce/includes/api/cocart/v2/products/class-cocart-products-controller.php(94): CoCart_Products_Controller->prepare_objects_query(Object(WP_REST_Request))
    #1 /var/www/html/web/wp/wp-includes/rest-api/class-wp-rest-server.php(1141): CoCart_Products_V2_Controller->get_items(Object(WP_REST_Request))
    #2 /var/www/html/web/wp/wp-includes/rest-api/class-wp-rest-server.php(988): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/cocart/v2/prod...', Array, NULL)
    #3 /var/www/html/web/wp/wp-includes/rest-api/class-wp-rest-server.php(414): WP_REST_Server->dispatch(Object(WP_REST_Request))
    #4 /var/www/html/web/wp/wp-includes/rest-api.php(386): WP_REST_Server->serve_request('/cocart/v2/prod...')
    #5 /var/www/html/web/wp/wp- in <b>/var/www/html/web/app/plugins/cart-rest-api-for-woocommerce/includes/api/cocart/v1/products/class-cocart-products-controller.php</b> on line <b>592</b><br />

    the add_meta_query method is not present inside CoCart_Products_V2_Controller, meaning that multiple meta queries should currently not work. further more wc_get_min_max_price_meta_query() is depricated since wc 3.6

    add_meta_query does not exist inside CoCart_Products_Controller nor WP_REST_Controller nor wordpress.

    here is a solution for the depricated issue (not tested, but taken from wc-depricated-functions.php and modified with the variables from CoCart_Products_Controller):

    if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) {
      $current_min_price = isset( $request['min_price'] ) ? floatval( $request['min_price'] ) : 0;
      $current_max_price = isset( $request['max_price'] ) ? floatval( $request['max_price'] ) : PHP_INT_MAX;
    
      $args['meta_query'] = $this->add_meta_query( $args, apply_filters(
        'woocommerce_get_min_max_price_meta_query',
          array(
            'key'     => '_price',
            'value'   => array( $current_min_price, $current_max_price ),
            'compare' => 'BETWEEN',
            'type'    => 'DECIMAL(10,' . wc_get_price_decimals() . ')',
          ),
        $args
      ));
    }
    • This topic was modified 2 years, 7 months ago by jnz31.
    • This topic was modified 2 years, 7 months ago by jnz31.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Sébastien Dumont

    (@sebd86)

    I’m an idiot for not finding this issue sooner. The function add_meta_query was not committed when the products API add-on was merged with the core of CoCart. ???♂? Please accept my apologies for the issue caused. ??

    A patch will be up shortly.

    Thread Starter jnz31

    (@jnz31)

    haha, dont be so hard on yourself ??
    looks like it is working now. thanks!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Uncaught Error: Call to undefined method CoCart_Products_V2_Controller::add_meta’ is closed to new replies.