phpclassic / php-shopify

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

will you update your files to support new api version ? #119

Closed svishalgarg closed 4 years ago

svishalgarg commented 4 years ago

shopify made some changes to api like pagination etc. I hope you will implement these changes

tareqtms commented 4 years ago

Pagination is already supported, if you are pointing to any specific feature, please give me the documentation so that I can confirm.

tareqtms commented 4 years ago

@svishalgarg Also please note that, you can provide ApiVersion in the $config array to use any version of API you want.

svishalgarg commented 4 years ago

thank you @tareqtms for replying.

i want to know, how can I use below api for pagination of products, orders and other endpoint. https://help.shopify.com/en/api/guides/paginated-rest-results

page parameter is no longer supported in new versions

oscarfabiano commented 4 years ago

@svishalgarg Also please note that, you can provide ApiVersion in the $config array to use any version of API you want.

Hi @tareqtms ,
Should I set it up like this? 'ApiVersion' => '2019-10'
tks

tareqtms commented 4 years ago

@oscarfabiano Yes

svishalgarg commented 4 years ago

@tareqtms thanks for replying , I am talking about new pagination updates , Please check below url : https://help.shopify.com/en/api/guides/paginated-rest-results

page parameter is no longer supported with new versions, with new versions, it send pagination data in response headers.

with your sdk , what is the process to use this pagination ?

thanks

tareqtms commented 4 years ago

Try something like this:

$params = ['page_info' = '__Page_Info_', 'limit' => '___Limit___'];
$shopify->Product->get($params);
svishalgarg commented 4 years ago

how to get page info data ?, is there any function in any class that returns response headers? thanks

tareqtms commented 4 years ago

That should be in the header of the first request. So for the first request, you can send only the limit. Btw, not sure, if you can get the headers from the current implementation. I will check on that later and let you know.

svishalgarg commented 4 years ago

that's what i was asking, "how to retrieve response headers after making api call". hope to get updates soon, as pagination is must for orders, products etc.

thanks @tareqtms . 👍

aalwash commented 4 years ago

My proposal would be something like this (to keep it backward compatible). Of course the function/attribute names are for discussion

The pagination headers looks like this: <https://your-shop-name.myshopify.com/admin/api/2019-10/products.json?page_info=123hash123>; rel="next" and this is how a previous page header looks like: <https://your-shop-name.myshopify.com/admin/api/2019-10/products.json?page_info=123hash123>; rel="previous"

So you can do something like this:

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

$products = $shopify->Product->get();

if($shopify->Product->lastResourceContainsNextPageInfo()) {
    while(true) {
        $products = array_merge($products, $shopify->Product->get(['page_info' => $shopify->Product->getNextPageInfo()]));

        if(!$shopify->Product->lastResourceContainsNextPageInfo()) {
            break;
        }
    }
}
tareqtms commented 4 years ago

@aalwash I liked the idea. I need a bit more time to think deeply. But you are welcome to submit a PR. I will merge it if I don't find any better alternative.

svishalgarg commented 4 years ago

@tareqtms if make sense , you can also think doing like this simple way

$products = $shClient->Product->get();
$lastResponse = $shClient->getLastResponseInfo();

getLastResponseInfo method can return response information along with formatted header info. headers also contains info about api limits etc, so that will be accessible too.

I am not sure if its a good idea but you can check if it is

Thank you.

aalwash commented 4 years ago

@svishalgarg is the 'easiest' fix and should do the job as well It's less "code-friendly" since you have to extract your own headers to find the next/previous pagination links

Maybe implement both, since the last response info contains other headers in case someone needs to extract this

rjacobso commented 4 years ago

@aalwash I liked the idea. I need a bit more time to think deeply. But you are welcome to submit a PR. I will merge it if I don't find any better alternative.

@tareqtms - I just created a pull request (https://github.com/phpclassic/php-shopify/pull/125) that attempts to do what @aalwash described. Seems to work in my test environment. Please review and let me know what you think. ApiVersion needs to be updated to "2019-07" to get the new header in most endpoints.

tareqtms commented 4 years ago

@rjacobso The changes are not backward-compatible, so we cannot merge this now. (If we do, it may break many sites using the package.) For now, looking for a backward-compatible solution.

binipinki commented 4 years ago

deadline is UPDATE DEADLINE: APR 01, 2020 fyi

aalwash commented 4 years ago

Hmm, I already tried to keep it backward compatible How is this not backward compatible?

joeyhub commented 4 years ago

I'd be happy with a 2.0.0 version instead of BC.

Plus it should just document what people need to fix the BC issue.

rjacobso commented 4 years ago

@aalwash - it was not backwards compat because I changed the return types of some methods. @tareqtms - Last week I closed #125 and tried again with #136 . I think this accomplishes the original @aalwash goal without changing any existing functionality.

I also noticed (after I submitted mine) that there is a pull request #134 to do something similar but I did not get a chance to test it yet.

hippoduck commented 4 years ago

Does anyone have any example code on how to use this? We just need to loop through all products, but I am struggling to keep up with the threads / PR's on this subject. Many thanks.

folex70 commented 4 years ago

Does anyone have any example code on how to use this? We just need to loop through all products, but I am struggling to keep up with the threads / PR's on this subject. Many thanks.

I supose you do:

  1. access ShopifyLib/vendor/phpclassic/php-shopify/lib/ShopifySDK.php
  2. go to line 214 and change '2019-xx' to '2020-xx'
binipinki commented 4 years ago

how to implement pagination in new API anyone can give some light ?

rjacobso commented 4 years ago

Something like:

$config = array(
    'ShopUrl' => $shopify_shop,
    'ApiKey' => $shopify_api_key,
    'Password' => $shopify_api_pass,
);

$shopify = ShopifySDK::config( $config );

$filters = [
    'limit'              => 250,
];

$product_resource = $shopify->Product();
$products         = $product_resource->get($filters);
$next_page      = $product_resource->getNextPageParams();

while ($next_page) {
    $next_page_products = $product_resource->get($product_resource->getNextPageParams());
    $products           = array_merge($products, $next_page_products);
    $next_page        = $product_resource->getNextPageParams();
}
tareqtms commented 4 years ago

@rjacobso Thanks for the example code. @binipinki You can follow #101 for more info related to this.