From 41fc02006177f661c4f3a7c0da86b8a65e4ade21 Mon Sep 17 00:00:00 2001 From: Ahmed Elassar <65714420+Ahmedelassar@users.noreply.github.com> Date: Wed, 3 Feb 2021 13:23:52 +0200 Subject: [PATCH 1/6] Update functions.php --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 010d342..312a0f3 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -4,7 +4,7 @@ function shopify_call($token, $shop, $api_endpoint, $query = array(), $method = // Build URL $url = "https://" . $shop . ".myshopify.com" . $api_endpoint; - if (!is_null($query) && in_array($method, array('GET', 'DELETE'))) $url = $url . "?" . http_build_query($query); + if (!is_null($query) && in_array($method, array('GET', 'DELETE'))) $url = $url . "" . http_build_query($query); // Configure cURL $curl = curl_init($url); @@ -61,4 +61,4 @@ function shopify_call($token, $shop, $api_endpoint, $query = array(), $method = } -} \ No newline at end of file +} From 07bf46c773b11d399206b606480e4ef99c2b5abd Mon Sep 17 00:00:00 2001 From: Ahmed Elassar <65714420+Ahmedelassar@users.noreply.github.com> Date: Wed, 3 Feb 2021 13:59:21 +0200 Subject: [PATCH 2/6] Solving the pagination problem by returning link The problem was that the header contians the pagination link when you make a request from the Api and you need more than the limit of 250 so you need to get the value of the next page but it appears in the header as an empty value, but after passing it this way, you will be able to place another function after doing the request to extract the value from this variable; --- inc/functions.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/functions.php b/inc/functions.php index 312a0f3..dc25749 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -49,6 +49,13 @@ function shopify_call($token, $shop, $api_endpoint, $query = array(), $method = // Convert headers into an array $headers = array(); $header_data = explode("\n",$response[0]); + $a=0; // Defining Variable $a in the function + for($f=0;$f $headers, 'response' => $response[1]); + return array('headers' => $headers, 'response' => $response[1],$link_value); // returning link value for pagination } From b89c0c7230d7e8236fdca751806246b9b4ecc3dd Mon Sep 17 00:00:00 2001 From: Ahmed Elassar <65714420+Ahmedelassar@users.noreply.github.com> Date: Wed, 3 Feb 2021 14:03:35 +0200 Subject: [PATCH 3/6] Pagination Example for displaying orders Now you can use pagination based on your desired api requests --- orders.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 orders.php diff --git a/orders.php b/orders.php new file mode 100644 index 0000000..729e344 --- /dev/null +++ b/orders.php @@ -0,0 +1,65 @@ + + + + Product Customizers + + + + + + + + + + + +
+
+~', $link, $prev); + } elseif(strpos($link, 'rel="next"')) { + preg_match('~<(.*?)>~', $link, $next); + } + } +} +echo $prev[1]; +echo '
'; +echo $next[1]; +// Now you can easily use the previous and next link for displaying orders with pagination, instead of limiting yourself with 250 + + + $orders_db =json_decode($orders_db['response'],JSON_PRETTY_PRINT); + + foreach ($orders_db as $order_db) { +// Your code here +} + + ?> + + + + +
+ + + From 0cdf2740f1c5a0187a4d87aa387beb79abc88a7e Mon Sep 17 00:00:00 2001 From: Ahmed Elassar <65714420+Ahmedelassar@users.noreply.github.com> Date: Wed, 3 Feb 2021 14:03:57 +0200 Subject: [PATCH 4/6] Pagination Example for displaying orders Now you can use pagination based on your desired api requests --- orders_with_pagination.php | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 orders_with_pagination.php diff --git a/orders_with_pagination.php b/orders_with_pagination.php new file mode 100644 index 0000000..729e344 --- /dev/null +++ b/orders_with_pagination.php @@ -0,0 +1,65 @@ + + + + Product Customizers + + + + + + + + + + + +
+
+~', $link, $prev); + } elseif(strpos($link, 'rel="next"')) { + preg_match('~<(.*?)>~', $link, $next); + } + } +} +echo $prev[1]; +echo '
'; +echo $next[1]; +// Now you can easily use the previous and next link for displaying orders with pagination, instead of limiting yourself with 250 + + + $orders_db =json_decode($orders_db['response'],JSON_PRETTY_PRINT); + + foreach ($orders_db as $order_db) { +// Your code here +} + + ?> + + + + +
+ + + From 10fd2b9bacaebfe8c02993ce06920d770f14c16b Mon Sep 17 00:00:00 2001 From: Ahmed Elassar <65714420+Ahmedelassar@users.noreply.github.com> Date: Wed, 3 Feb 2021 14:04:51 +0200 Subject: [PATCH 5/6] Delete orders_with_pagination.php --- orders_with_pagination.php | 65 -------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 orders_with_pagination.php diff --git a/orders_with_pagination.php b/orders_with_pagination.php deleted file mode 100644 index 729e344..0000000 --- a/orders_with_pagination.php +++ /dev/null @@ -1,65 +0,0 @@ - - - - Product Customizers - - - - - - - - - - - -
-
-~', $link, $prev); - } elseif(strpos($link, 'rel="next"')) { - preg_match('~<(.*?)>~', $link, $next); - } - } -} -echo $prev[1]; -echo '
'; -echo $next[1]; -// Now you can easily use the previous and next link for displaying orders with pagination, instead of limiting yourself with 250 - - - $orders_db =json_decode($orders_db['response'],JSON_PRETTY_PRINT); - - foreach ($orders_db as $order_db) { -// Your code here -} - - ?> - - - - -
- - - From 2614985048a054c4aee0d8a561f1513d89b3682f Mon Sep 17 00:00:00 2001 From: Ahmed Elassar <65714420+Ahmedelassar@users.noreply.github.com> Date: Wed, 3 Feb 2021 14:09:51 +0200 Subject: [PATCH 6/6] Update functions.php --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/functions.php b/inc/functions.php index dc25749..dcb8673 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -55,7 +55,7 @@ function shopify_call($token, $shop, $api_endpoint, $query = array(), $method = $a=$f; // assinging $a with the number that conatins link in the array to make sure its the correct value } } - $link_value_=$header_data[$a]; //Assigning Link Value + $link_value=$header_data[$a]; //Assigning Link Value $headers['status'] = $header_data[0]; // Does not contain a key, have to explicitly set array_shift($header_data); // Remove status, we've already set it above foreach($header_data as $part) {