Skip to content

Commit ec927f5

Browse files
committed
Fix: some inventory level actions body should not be wrapped
1 parent e495a2f commit ec927f5

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

lib/HttpRequestJson.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ protected static function processResponse($response)
143143
return json_decode($response, true);
144144
}
145145

146-
}
146+
}

lib/InventoryLevel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ class InventoryLevel extends ShopifyResource
2626
'connect',
2727
'set',
2828
];
29+
30+
protected $customPostActionsNoWrap = [
31+
'adjust',
32+
'connect',
33+
'set',
34+
];
2935
}

lib/ShopifyResource.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ abstract class ShopifyResource
9696
protected $customPutActions = array();
9797
protected $customDeleteActions = array();
9898

99+
/**
100+
* Some actions from inventory levels do not wrap the content of the request
101+
*
102+
* Wrapping such request body leads to errors. This list is used to disable this wrapping
103+
* on certain methods.
104+
*
105+
* @var array
106+
*/
107+
protected $customPostActionsNoWrap = array();
108+
99109
/**
100110
* The ID of the resource
101111
*
@@ -225,7 +235,7 @@ public function __call($name, $arguments)
225235

226236
$url = $this->generateUrl($urlParams, $customAction);
227237

228-
return $this->$httpMethod($dataArray, $url);
238+
return $this->$httpMethod($dataArray, $url, !in_array($name, $this->customPostActionsNoWrap));
229239
}
230240
}
231241

@@ -355,18 +365,22 @@ public function search($query)
355365
/**
356366
* Call POST method to create a new resource
357367
*
358-
* @param array $dataArray Check Shopify API reference of the specific resource for the list of required and optional data elements to be provided
368+
* @param array $dataArray Check Shopify API reference of the specific resource for the list of required and optional data elements to be provided
359369
* @param string $url
360370
*
361-
* @uses HttpRequestJson::post() to send the HTTP request
371+
* @param bool $wrapBody
362372
*
363373
* @return array
374+
* @throws ApiException
375+
* @throws CurlException
376+
* @uses HttpRequestJson::post() to send the HTTP request
377+
*
364378
*/
365-
public function post($dataArray, $url = null)
379+
public function post($dataArray, $url = null, $wrapBody = true)
366380
{
367381
if (!$url) $url = $this->generateUrl();
368382

369-
if (!empty($dataArray)) $dataArray = $this->wrapData($dataArray);
383+
if ($wrapBody && !empty($dataArray)) $dataArray = $this->wrapData($dataArray);
370384

371385
$response = HttpRequestJson::post($url, $dataArray, $this->httpHeaders);
372386

0 commit comments

Comments
 (0)