Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cursor-based pagination #48

Open
bogdanghervan opened this issue Oct 7, 2020 · 2 comments
Open

Support cursor-based pagination #48

bogdanghervan opened this issue Oct 7, 2020 · 2 comments

Comments

@bogdanghervan
Copy link

Shopify has removed support for page-based pagination and enforces that everybody moves to cursor-paged pagination.

The library doesn't seem to provide a way to access the response headers, at least when using the services.

@JelleDijkhuizen
Copy link

JelleDijkhuizen commented Oct 13, 2020

HI @bogdanghervan i create this function to get the code from the api
/** * Get the link from the header so we can browser the api * * @param string $link_header * @return string */ private function getCodeFromLinkHeader(string $link_header){ //Check the header for the link $str = array_values(array_slice(explode('/', $link_header), -1, 1, true)); //Cechk if rel="next" is no longer in the link we can break the loop. if(strpos($str[0], 'rel="next"') === false){ return false; } $code_part = substr($str[0], strpos($str[0], 'page_info') + 10); if(strrchr($code_part, '?')){ $code = substr($code_part, 0, strpos($code_part, strrchr($code_part, '?'))); } if(strrchr($code_part, '>')){ $code = substr($code_part, 0, strpos($code_part, strrchr($code_part, '>'))); } return $code; }

Then i call the function with this:
$this->getCodeFromLinkHeader($this->api_response->getHeader('link')[0]);

And to get the api response i use Shopify\Service\ProductService->getLastResponse() to set the api_response.
Every Services class has the getLastReponse function to get the headers.

@bogdanghervan
Copy link
Author

Thanks, @JelleDijkhuizen, perhaps this can help somebody else stumbling upon this thread.

I ended up starting a migration project to a different Shopify client library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants