laravel-woocommerce icon indicating copy to clipboard operation
laravel-woocommerce copied to clipboard

Only get 10 registers

Open arpanet4 opened this issue 3 years ago • 9 comments

Hello, in the last version only get 10 registers.

For example in: $orders = Order::all();

Thanks.

arpanet4 avatar Oct 27 '20 09:10 arpanet4

Hello @arpanet4,

Thanks for creating the issue. By default woocommerce return 10 results per page. You can change the default option by several ways

  1. Using Woocommerce facade
$options = [
    'per_page' => 50 // Or your desire number
];

$orders = Woocommerce::all('orders', $options);
  1. Using Order facade
$options = [
    'per_page' => 50 // Or your desire number
];

$orders = Order::all($options);
  1. Using the paginate method
$per_page = 50; // Or your desire number
$current_page = 1; // By default 1. That reurns first 1 to 50. If 2 then return 51 to 100 and vice versa

$orders = Order::paginate($per_page, $current_page);

I hope it solves your issues. If you need further query just send details here.

maab16 avatar Oct 27 '20 10:10 maab16

I want to know in this case: i get the registers by this way : $results= WCCustomer::all(['per_page'=>100]); In this case, apparently only it possible get 100 records, if I put a number greater than 100 it shows the next error: Invalid parameter (s): per_page [rest_invalid_param] How can i get all the records?

CRMSoluciones avatar Apr 05 '21 15:04 CRMSoluciones

I want to know in this case: i get the registers by this way : $results= WCCustomer::all(['per_page'=>100]); In this case, apparently only it possible get 100 records, if I put a number greater than 100 it shows the next error: Invalid parameter (s): per_page [rest_invalid_param] How can i get all the records?

Any solution here?

vlkf avatar Jul 22 '22 09:07 vlkf

Hello @CRMSoluciones @vlkf,

Where do you get WCCustomer? Please check the original doc https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties

maab16 avatar Jul 22 '22 10:07 maab16

Hello @CRMSoluciones @vlkf,

Where do you get WCCustomer? Please check the original doc https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties

It's not working with Product facade also. Product::all(['per_page'=> 200]); Gives the error -> Exception (1) Error: Invalid parameter(s): per_page [rest_invalid_param]

vlkf avatar Jul 22 '22 10:07 vlkf

Hello @CRMSoluciones @vlkf, Where do you get WCCustomer? Please check the original doc https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties

It's not working with Product facade also. Product::all(['per_page'=> 200]); Gives the error -> Exception (1) Error: Invalid parameter(s): per_page [rest_invalid_param]

I am having the same issue! So I kept digging and found the reason why it's failing!

Screenshot 2022-08-02 at 14 09 42

I wish the maintainer show this message instead of just:

Exception (1) Error: Invalid parameter(s): per_page [rest_invalid_param]

EazyServer avatar Aug 02 '22 13:08 EazyServer

You can override it on the API server side:

add_action( 'rest_product_query', function( $params ) { if ( isset( $params ) AND isset( $params[ 'posts_per_page' ] ) ) { $params[ 'posts_per_page' ] = "200"; } return $params; });

However, this will most likely degrade the responsiveness of the remote WC API server! especially if used as normal website. Maybe best bet is to use pagination for > 100 products/orders!

EazyServer avatar Aug 02 '22 13:08 EazyServer

Thanks, @EazyServer for commenting. You are right the per_page value must be between 1 to 100. You must allow your wordpress server so that it can support greater than 100.

https://github.com/woocommerce/wc-api-php/issues/136

maab16 avatar Aug 02 '22 19:08 maab16