php-shopify icon indicating copy to clipboard operation
php-shopify copied to clipboard

Pagination not working

Open Rajagunasekaran opened this issue 3 years ago • 3 comments

I have using the private app in shopify admin to fetch the product results in PHP. Totally 278 products is there.

global $config; $shopify = new PHPShopify\ShopifySDK( $config );

$params = array( 'limit' => 250, ); $products = $shopify->Product->get( $params ); $link = $shopify->Product->getNextPageParams();

Initially it returns 250 products and I tried to get another pagination to get the rest. But it returns empty. Please advice.

Thanks

Rajagunasekaran avatar Nov 08 '21 07:11 Rajagunasekaran

Hi, I had the same problem. Try to instantiate the Product class only once, then you should get the next page parameters. If you look in the getLinks method, you see that the nextLink and previewLink fields are set to local fields.

$productResource = $this->client->Product;
$products = $productResource->get($params);
$nextPageParams = $productResource->getNextPageParams();

knaepel avatar Nov 08 '21 11:11 knaepel

Hi, I had the same problem. Try to instantiate the Product class only once, then you should get the next page parameters. If you look in the getLinks method, you see that the nextLink and previewLink fields are set to local fields.

$productResource = $this->client->Product;
$products = $productResource->get($params);
$nextPageParams = $productResource->getNextPageParams();

Next page params would then return "limit" param if previously set and "next_page" param which can be used to retrieve another batch of products.

niklaz avatar Nov 11 '21 16:11 niklaz

We have code examples here: https://github.com/phpclassic/php-shopify/issues/241#issuecomment-1059005042

tselikin avatar Mar 04 '22 09:03 tselikin