phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
568 stars 211 forks source link

Pagination not working #248

Open Rajagunasekaran opened 2 years ago

Rajagunasekaran commented 2 years ago

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

knaepel commented 2 years ago

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();
niklaz commented 2 years ago

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.

tselikin commented 2 years ago

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