Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<count($header_data)-1;$f++){
if (strpos($header_data[$f], 'link:') !== false) {
$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
$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) {
Expand All @@ -57,8 +64,8 @@ function shopify_call($token, $shop, $api_endpoint, $query = array(), $method =
}

// Return headers and Shopify's response
return array('headers' => $headers, 'response' => $response[1]);
return array('headers' => $headers, 'response' => $response[1],$link_value); // returning link value for pagination

}

}
}
65 changes: 65 additions & 0 deletions orders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Product Customizers</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

<?php

include_once("/inc/functions.php");
include_once("header.php");



?>
</head>

<body style="background-color:#f6f6f7 !important;">
<div class="container">
<div style="text-align:left;">
<?php

$orders_db= shopify_call($token,$shop_url,"/admin/api/2020-01/orders.json?limit=20 ",array(),'GET');


// Pagination
$t = $orders_db[0];
$prev = false;
$next = false;

if($t) {
$links = explode(',', $t);
foreach($links as $link) {
if(strpos($link, 'rel="previous"')) {
preg_match('~<(.*?)>~', $link, $prev);
} elseif(strpos($link, 'rel="next"')) {
preg_match('~<(.*?)>~', $link, $next);
}
}
}
echo $prev[1];
echo '<hr>';
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
}

?>




</div>
</body>
</html>