Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- PHP methods that get and set product quantities for a class that makes calls to an API.
- */
- public function getProductBalances($skus = '[]') {
- //build header info. keys are added here
- $headers = array();
- $headers[] = 'Content-Type: application/json';
- $headers[] = 'Ocp-Apim-Subscription-Key: ' . $this->developer_key;
- $headers[] = 'ecd-subscription-key: ' . $this->account_integration_key;
- $headers[] = 'Content-Length: ' . strlen($skus);
- $action = 'product/getProductBalances';//default action for this function
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $skus);
- curl_setopt($curl, CURLOPT_URL, $this->url . $action);
- $result = json_decode(curl_exec($curl) , true);
- $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- if (curl_errno($curl)
- || $httpcode != 200
- || (!empty($result) && (isset($result['status']) && $result['status'] != 'Success'))
- ) {
- $error_message = 'Error Processing Request: HTTP Code: ' . $httpcode . "\n" .
- var_export(curl_error($curl), true) . "\n" .
- var_export($result, 1);
- curl_close($curl);
- throw new Exception($error_message, 1);
- }
- curl_close($curl);
- return $result;
- }
- public function updateQtyOnHand ($skus = '[]') {
- //build header info. keys are added here
- $headers = array();
- $headers[] = 'Content-Type: application/json';
- $headers[] = 'Ocp-Apim-Subscription-Key: ' . $this->developer_key;
- $headers[] = 'ecd-subscription-key: ' . $this->account_integration_key;
- $headers[] = 'Content-Length: ' . strlen($skus);
- $action = 'inventory/updateQuantityOnHand';//default action for this function
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $skus);
- curl_setopt($curl, CURLOPT_URL, $this->url . $action);
- $result = json_decode(curl_exec($curl) , true);
- $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- if (curl_errno($curl)
- || $httpcode != 200
- || (!empty($result) && (isset($result['status']) && $result['status'] != 'Success'))
- ) {
- $error_message = 'Error Processing Request: HTTP Code: ' . $httpcode . "\n" .
- var_export(curl_error($curl), true) . "\n" .
- var_export($result, 1);
- curl_close($curl);
- throw new Exception($error_message, 1);
- }
- curl_close($curl);
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement