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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ Some resources are available directly, some resources are only available through
- [Event](https://help.shopify.com/api/reference/event/)
- [FulfillmentService](https://help.shopify.com/api/reference/fulfillmentservice)
- [GiftCard](https://help.shopify.com/api/reference/gift_card) _(Shopify Plus Only)_
- [InventoryItem](https://help.shopify.com/api/reference/inventoryitem)
- [InventoryLevel](https://help.shopify.com/api/reference/inventorylevel)
- [Location](https://help.shopify.com/api/reference/location/) _(read only)_
- [Metafield](https://help.shopify.com/api/reference/metafield)
- [Multipass](https://help.shopify.com/api/reference/multipass) _(Shopify Plus Only, API not available yet)_
Expand Down Expand Up @@ -358,6 +360,14 @@ The custom methods are specific to some resources which may not be available for
- [search()](https://help.shopify.com/api/reference/gift_card#search)
Search for gift cards matching supplied query

- InventoryLevel ->
- [adjust($data)](https://help.shopify.com/api/reference/inventorylevel#adjust)
Adjust inventory level.
- [connect($data)](https://help.shopify.com/api/reference/inventorylevel#connect)
Connect an inventory item to a location.
- [set($data)](https://help.shopify.com/api/reference/inventorylevel#set)
Set an inventory level for a single inventory item within a location.

- Order ->
- [close()](https://help.shopify.com/api/reference/order#close)
Close an Order
Expand Down
2 changes: 1 addition & 1 deletion lib/HttpRequestJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ protected static function processResponse($response)
return json_decode($response, true);
}

}
}
15 changes: 15 additions & 0 deletions lib/InventoryItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* @author Arsenii Lozytskyi <manwe64@gmail.com>
* Created at 04/15/18 02:25 PM UTC+03:00
*
* @see https://help.shopify.com/api/reference/inventoryitem
*/

namespace PHPShopify;

class InventoryItem extends ShopifyResource
{
/** @inheritDoc */
protected $resourceKey = 'inventory_item';
}
35 changes: 35 additions & 0 deletions lib/InventoryLevel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* @author Arsenii Lozytskyi <manwe64@gmail.com>
* Created at 04/15/18 02:31 PM UTC+03:00
*
* @see https://help.shopify.com/api/reference/inventorylevel
*/

namespace PHPShopify;

/**
* Class InventoryLevel
*
* @method array adjust($data) Adjust inventory level.
* @method array connect($data) Connect an inventory item to a location.
* @method array set($data) Sets an inventory level for a single inventory item within a location.
*/
class InventoryLevel extends ShopifyResource
{
/** @inheritDoc */
protected $resourceKey = 'inventory_level';

/** @inheritDoc */
protected $customPostActions = [
'adjust',
'connect',
'set',
];

protected $customPostActionsNoWrap = [
'adjust',
'connect',
'set',
];
}
28 changes: 21 additions & 7 deletions lib/ShopifyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class ShopifyResource

/**
* List of child Resource names / classes
*
*
* If any array item has an associative key => value pair, value will be considered as the resource name
* (by which it will be called) and key will be the associated class name.
*
Expand Down Expand Up @@ -96,6 +96,16 @@ abstract class ShopifyResource
protected $customPutActions = array();
protected $customDeleteActions = array();

/**
* Some actions from inventory levels do not wrap the content of the request
*
* Wrapping such request body leads to errors. This list is used to disable this wrapping
* on certain methods.
*
* @var array
*/
protected $customPostActionsNoWrap = array();

/**
* The ID of the resource
*
Expand Down Expand Up @@ -225,7 +235,7 @@ public function __call($name, $arguments)

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

return $this->$httpMethod($dataArray, $url);
return $this->$httpMethod($dataArray, $url, !in_array($name, $this->customPostActionsNoWrap));
}
}

Expand Down Expand Up @@ -355,18 +365,22 @@ public function search($query)
/**
* Call POST method to create a new resource
*
* @param array $dataArray Check Shopify API reference of the specific resource for the list of required and optional data elements to be provided
* @param array $dataArray Check Shopify API reference of the specific resource for the list of required and optional data elements to be provided
* @param string $url
*
* @uses HttpRequestJson::post() to send the HTTP request
* @param bool $wrapBody
*
* @return array
* @throws ApiException
* @throws CurlException
* @uses HttpRequestJson::post() to send the HTTP request
*
*/
public function post($dataArray, $url = null)
public function post($dataArray, $url = null, $wrapBody = true)
{
if (!$url) $url = $this->generateUrl();

if (!empty($dataArray)) $dataArray = $this->wrapData($dataArray);
if ($wrapBody && !empty($dataArray)) $dataArray = $this->wrapData($dataArray);

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

Expand Down Expand Up @@ -498,4 +512,4 @@ public function processResponse($responseArray, $dataKey = null)
return $responseArray;
}
}
}
}
4 changes: 3 additions & 1 deletion lib/ShopifySDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class ShopifySDK
'Event',
'FulfillmentService',
'GiftCard',
'InventoryItem',
'InventoryLevel',
'Location',
'Metafield',
'Multipass',
Expand Down Expand Up @@ -296,4 +298,4 @@ public static function checkApiCallLimit($firstCallWait = false)

static::$microtimeOfLastApiCall = microtime(true);
}
}
}