Codexshaper / laravel-woocommerce

WooCommerce Rest API for Laravel
MIT License
198 stars 57 forks source link

Product::all(); only 10 results. #34

Closed Draidel closed 4 years ago

Draidel commented 4 years ago

Hi, I am doing this: $products = Product::all();

and I just get an array with 10 results, why? (I have thousands of products)

maab16 commented 4 years ago

Hello @Draidel

Thanks for creating an issue. By default woocommerce rest api returns 10 results for per page. Read this doc https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-products

If you want to get more or less products for per page then you can pass per_page option in all method.

$products = Product::all(['per_page' => 15]);

By default page number is 1. If you want to fetch next page or specific page data you can pass page option.

$products = Product::all(['page' => 2, 'per_page' => 15]);

If you want to fetch products with pagination use below code

$per_page = 15;
$page_number = 2;
$products = Product::paginate($per_page, $page_number);

It will returns 15 products and pagination information (Total records, total pages, current page, previous page, next pages, first page, last page).

Hope your issue solved. Enjoy.

Regards, Md Abu Ahsan Basir

Codexshaper commented 4 years ago

Hope you are enjoying it. If you like this package and want to support contributors then just press the star button. They will encourage to provide great features. Thanks

alkhachatryan commented 4 years ago

@Draidel I had the problem today. I took hours to find the problem out.

Find the woocommerce class, called something like: woocommrece restapi crud controller. Find the line where maximum is 100 and change to billions

gelinger777 commented 3 years ago
   Exception 

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

@Codexshaper