slince / shopify-api-php

:rocket: Shopify API Client for PHP
MIT License
128 stars 48 forks source link

$client->getProductManager()->findAll return only 50 products #27

Closed gdinko closed 5 years ago

gdinko commented 5 years ago

Hi, I am not sure if this is a bug, but $client->getProductManager()->findAll() return only 50 products. If I set $client->getProductManager()->findAll(['limit' => 250]); it returns 250 products. Is this normal ? How can i get all products?

Thanks

maximzasorin commented 5 years ago

Hi, I think that this is not a bug, the library works in the same way as an API, where limit = 50 by default. To get all products use page argument and iterate over all collection, until the query returns a non-empty result.

For example:

$productManager = $client->getProductManager();

$page = 1;
$limit = 250;

do {
    $products = $productManager->findAll(['limit' => $limit, 'page' => $page]);

    foreach ($products as $product) {
        // process product
    }

    $page++;
} while (count($products) == $limit);
gdinko commented 5 years ago

Благодаря Максим! Thanks Maxim!