Advertisement
adam-prescott

Kernig fix

Sep 29th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. function apiRequest($Url, $headers=false){
  2. global $authorisationToken;
  3. if($headers == false) {
  4.   $headers = array(
  5. "brightpearl-auth: {$authorisationToken}",
  6. 'Content-Type: application/json',
  7. );
  8. }
  9. $ch = curl_init();
  10. curl_setopt($ch, CURLOPT_URL, $Url);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  12. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  13. $response = curl_exec($ch);
  14. curl_close($ch);
  15. return json_decode($response);
  16. }
  17.  
  18. // PRODUCT NAME SEARCHING //
  19. function productSearch($search){
  20. require_once('connect.php');
  21. $productUrl = 'https://ws-eu1.brightpearl.com/2.0.0/room31wholesale/product-service/product-search?productName='.$search;
  22. $responseBody = apiRequest($productUrl);
  23. $products = $responseBody->response->results;
  24.  
  25.         // ITEM DUMP INFORMATION
  26.         $i = 0;
  27.         // echo 'Product Descriptions <hr>';
  28.         // echo '<pre>';
  29.         // print_r($products['1']);
  30.         // echo '</pre><br><br>';
  31.         foreach ($products as $product){
  32.         $result = $products[$i];
  33.         echo 'SKU: ' . $result['2'] . '<br>';
  34.         echo 'Name: ' . $result['1'] . '<br>';
  35.         echo 'Qty: ' . stockUpdate($result['0']) . '<br><br><br>';
  36.        
  37.        
  38.         $i++;
  39.         };
  40.         // END DUMP //
  41. }
  42. // PRODUCT NAME SEARCHING END //
  43.  
  44. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  45.  
  46. // PRODUCT QUANTITY SEARCH //
  47. function stockUpdate($qty){
  48. require_once('connect.php');
  49. $quantityUrl = 'https://ws-eu1.brightpearl.com/2.0.0/room31wholesale/warehouse-service/product-availability/'.$qty;
  50.  
  51. $responseBody2 = apiRequest($quantityUrl);
  52. $quantity = $responseBody2->response;
  53. $stockQty = $quantity->$qty->total->inStock;
  54. echo $qty;
  55. echo $stockQty;
  56. }
  57. // PRODUCT QUANTITY SEARCH END //
  58.  
  59. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60.  
  61. echo productSearch($_POST['user']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement