From 3bcc4370dbe98fe120a5adede036b09e82f274d8 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Wed, 16 Sep 2020 21:34:11 +0200 Subject: [PATCH 01/26] add inventory interface to api --- src/Enum/Fields/InventoryItemFields.php | 30 ++++++ src/Enum/Fields/InventoryLevelFields.php | 23 +++++ src/Object/AbstractObject.php | 2 +- src/Object/InventoryItem.php | 44 +++++++++ src/Object/InventoryLevel.php | 44 +++++++++ src/Service/AbstractService.php | 6 +- src/Service/InventroyItemService.php | 60 ++++++++++++ src/Service/InventroyLevelService.php | 120 +++++++++++++++++++++++ 8 files changed, 325 insertions(+), 4 deletions(-) create mode 100644 src/Enum/Fields/InventoryItemFields.php create mode 100644 src/Enum/Fields/InventoryLevelFields.php create mode 100644 src/Object/InventoryItem.php create mode 100644 src/Object/InventoryLevel.php create mode 100644 src/Service/InventroyItemService.php create mode 100644 src/Service/InventroyLevelService.php diff --git a/src/Enum/Fields/InventoryItemFields.php b/src/Enum/Fields/InventoryItemFields.php new file mode 100644 index 0000000..8401697 --- /dev/null +++ b/src/Enum/Fields/InventoryItemFields.php @@ -0,0 +1,30 @@ + 'integer', + 'country_code_of_origin' => 'string', + 'country_harmonized_system_codes' => 'string', + 'harmonized_system_code' => 'integer', + 'id' => 'integer', + 'province_code_of_origin' => 'string', + 'sku' => 'string', + 'tracked' => 'boolean', + ); + } +} \ No newline at end of file diff --git a/src/Enum/Fields/InventoryLevelFields.php b/src/Enum/Fields/InventoryLevelFields.php new file mode 100644 index 0000000..79a22db --- /dev/null +++ b/src/Enum/Fields/InventoryLevelFields.php @@ -0,0 +1,23 @@ + 'integer', + 'location_id' => 'integer', + 'available' => 'integer', + 'available_adjustment' => 'integer', + 'disconnect_if_necessary' => 'boolean', + ); + } +} \ No newline at end of file diff --git a/src/Object/AbstractObject.php b/src/Object/AbstractObject.php index 5cf3b79..99616bc 100644 --- a/src/Object/AbstractObject.php +++ b/src/Object/AbstractObject.php @@ -73,7 +73,7 @@ public function __set($key, $value) } if (!is_null($value) && !$this->isValidValue($key, $value)) { throw new \InvalidArgumentException( - "Invalid type for property '{$key}'" + "Invalid type for property '{$key}', should be a ".$this->types[$key]." received ".print_r($value,1) ); } $this->data[$key] = $value; diff --git a/src/Object/InventoryItem.php b/src/Object/InventoryItem.php new file mode 100644 index 0000000..49edc07 --- /dev/null +++ b/src/Object/InventoryItem.php @@ -0,0 +1,44 @@ + + * @license MIT + */ + +namespace Shopify\Object; + +use Shopify\Enum\Fields\InventoryItemFields; + +class InventoryItem extends AbstractObject +{ + public static function getFieldsEnum() + { + return InventoryItemFields::getInstance(); + } +} diff --git a/src/Object/InventoryLevel.php b/src/Object/InventoryLevel.php new file mode 100644 index 0000000..840d591 --- /dev/null +++ b/src/Object/InventoryLevel.php @@ -0,0 +1,44 @@ + + * @license MIT + */ + +namespace Shopify\Object; + +use Shopify\Enum\Fields\InventoryLevelFields; + +class InventoryLevel extends AbstractObject +{ + public static function getFieldsEnum() + { + return InventoryLevelFields::getInstance(); + } +} \ No newline at end of file diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 6efe4e5..de052d7 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -21,9 +21,9 @@ abstract class AbstractService */ private $lastResponse; - const REQUEST_METHOD_GET = 'GET'; - const REQUEST_METHOD_POST = 'POST'; - const REQUEST_METHOD_PUT = 'PUT'; + const REQUEST_METHOD_GET = 'GET'; + const REQUEST_METHOD_POST = 'POST'; + const REQUEST_METHOD_PUT = 'PUT'; const REQUEST_METHOD_DELETE = 'DELETE'; public static function factory(ApiInterface $api) diff --git a/src/Service/InventroyItemService.php b/src/Service/InventroyItemService.php new file mode 100644 index 0000000..330848f --- /dev/null +++ b/src/Service/InventroyItemService.php @@ -0,0 +1,60 @@ +request($endpoint, 'GET', $params); + return $this->createCollection(InventoryItem::class, $response['products']); + } + + /** + * Retrieves a single inventory item by ID + * + * @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventoryitem#show-2020-07 + * @param int $inventroyItemId + * @param array $fields + * @return InventoryItem[] + */ + public function get(int $inventroyItemId, array $fields = []){ + $params = []; + if (!empty($fields)) { + $params['fields'] = $fields; + } + $endpoint = 'inventory_items/'.$inventroyItemId.'.json'; + $response = $this->request($endpoint, 'GET', $params); + return $this->createObject(InventoryItem::class, $response['product']); + } + + /** + * Updates an existing inventory item + * + * @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventoryitem#update-2020-07 + * @param InventoryItem $inventoryItem + * @return void + */ + public function update(InventoryItem &$inventoryItem){ + $data = $inventoryItem->exportData(); + $endpoint = 'inventory_items/'.$inventoryItem->id.'.json'; + $response = $this->request( + $endpoint, 'PUT', array( + 'inventory_item' => $data + ) + ); + $inventoryItem->setData($response['product']); + } +} \ No newline at end of file diff --git a/src/Service/InventroyLevelService.php b/src/Service/InventroyLevelService.php new file mode 100644 index 0000000..010cf98 --- /dev/null +++ b/src/Service/InventroyLevelService.php @@ -0,0 +1,120 @@ +request($endpoint); + + return $$this->createCollection(InventoryLevel::class, $response['inventory_levels']); + } + + /** + * Adjusts the inventory level of an inventory item at a single location + * + * @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel#adjust-2020-07 + * @param InventoryLevel $inventoryLevel + * @return void + */ + public function adjust(InventoryLevel &$inventoryLevel){ + $data = $inventoryLevel->exportData(); + $endpoint = 'inventory_levels/adjust.json'; + $response = $this->request( + $endpoint, 'POST', $data + ); + $inventoryLevel->setData($response['inventory_level']); + } + + /** + * Deletes an inventory level of an inventory item at a location. + * Deleting an inventory level for an inventory item removes that item from the specified location. + * Every inventory item must have at least one inventory level. + * To move inventory to another location, first connect the inventory item to another location, and then delete the previous inventory level. + * + * @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel#destroy-2020-07 + * @param InventoryLevel $inventoryLevel + * @return void + */ + public function delete(InventoryLevel &$inventoryLevel){ + $endpoint = 'inventory_levels.json?inventory_item_id='.$inventoryLevel->inventory_item_id.'&location_id='.$inventoryLevel->location_id; + $this->request($endpoint, 'DELETE'); + return; + } + + /** + * Connects an inventory item to a location by creating an inventory level at that location. + * When connecting inventory items to locations, it's important to understand the rules around fulfillment service locations. + * + * @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel#connect-2020-07 + * @param InventoryLevel $inventoryLevel + * @return void + */ + public function connect(InventoryLevel &$inventoryLevel){ + $data = $inventoryLevel->exportData(); + $endpoint = 'inventory_levels/connect.json'; + $response = $this->request( + $endpoint, 'POST', $data + ); + $inventoryLevel->setData($response['inventory_level']); + } + + /** + * Sets the inventory level for an inventory item at a location. + * If the specified location is not connected, it will be automatically connected first. + * When connecting inventory items to locations, it's important to understand the rules around fulfillment service locations. + * + * @link https://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel#set-2020-07 + * @param InventoryLevel $inventoryLevel + * @return void + */ + public function set(InventoryLevel &$inventoryLevel){ + $data = $inventoryLevel->exportData(); + $endpoint = 'inventory_levels/set.json'; + $response = $this->request( + $endpoint, 'POST', $data + ); + $inventoryLevel->setData($response['inventory_level']); + } +} \ No newline at end of file From 8bd52abc82ecb030ad5bcb52b4c9b3d7cc60f251 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Fri, 18 Sep 2020 15:33:38 +0200 Subject: [PATCH 02/26] bumped default api version --- src/AbstractApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbstractApi.php b/src/AbstractApi.php index 47bd7a2..d36f640 100644 --- a/src/AbstractApi.php +++ b/src/AbstractApi.php @@ -8,7 +8,7 @@ abstract class AbstractApi implements ApiInterface { - const DEFAULT_API_VERSION = '2019-04'; + const DEFAULT_API_VERSION = '2020-07'; /** * Domain of the Shopify store From 163ef879d34886b07940fda0b258d9dabff10a37 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Mon, 21 Sep 2020 10:26:57 +0200 Subject: [PATCH 03/26] fixed typo --- .../{InventroyItemService.php => InventoryItemService.php} | 2 +- .../{InventroyLevelService.php => InventoryLevelService.php} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Service/{InventroyItemService.php => InventoryItemService.php} (97%) rename src/Service/{InventroyLevelService.php => InventoryLevelService.php} (99%) diff --git a/src/Service/InventroyItemService.php b/src/Service/InventoryItemService.php similarity index 97% rename from src/Service/InventroyItemService.php rename to src/Service/InventoryItemService.php index 330848f..a974bc4 100644 --- a/src/Service/InventroyItemService.php +++ b/src/Service/InventoryItemService.php @@ -4,7 +4,7 @@ use Shopify\Object\InventoryItem; -class InventroyItemService extends AbstractService +class InventoryItemService extends AbstractService { /** * Retrieves a list of inventory items. diff --git a/src/Service/InventroyLevelService.php b/src/Service/InventoryLevelService.php similarity index 99% rename from src/Service/InventroyLevelService.php rename to src/Service/InventoryLevelService.php index 010cf98..ae14253 100644 --- a/src/Service/InventroyLevelService.php +++ b/src/Service/InventoryLevelService.php @@ -5,7 +5,7 @@ use InvalidArgumentException; use Shopify\Object\InventoryLevel; -class InventroyLevelService extends AbstractService +class InventoryLevelService extends AbstractService { /** * Retrieves a list of inventory levels. From de5abc3dd09f5b3467dc4f07575919473f77a428 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Mon, 21 Sep 2020 15:47:02 +0200 Subject: [PATCH 04/26] fixed wrong index on iventory_item response --- src/Service/InventoryItemService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Service/InventoryItemService.php b/src/Service/InventoryItemService.php index a974bc4..b24623b 100644 --- a/src/Service/InventoryItemService.php +++ b/src/Service/InventoryItemService.php @@ -19,7 +19,7 @@ class InventoryItemService extends AbstractService public function all(array $params = []){ $endpoint = 'inventory_items.json'; $response = $this->request($endpoint, 'GET', $params); - return $this->createCollection(InventoryItem::class, $response['products']); + return $this->createCollection(InventoryItem::class, $response['inventory_item']); } /** @@ -37,7 +37,7 @@ public function get(int $inventroyItemId, array $fields = []){ } $endpoint = 'inventory_items/'.$inventroyItemId.'.json'; $response = $this->request($endpoint, 'GET', $params); - return $this->createObject(InventoryItem::class, $response['product']); + return $this->createObject(InventoryItem::class, $response['inventory_item']); } /** @@ -55,6 +55,6 @@ public function update(InventoryItem &$inventoryItem){ 'inventory_item' => $data ) ); - $inventoryItem->setData($response['product']); + $inventoryItem->setData($response['inventory_item']); } } \ No newline at end of file From 39fc19828e0ca5808d7120392d6bfc089523f78d Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Mon, 21 Sep 2020 16:01:44 +0200 Subject: [PATCH 05/26] fixed array to string conversion --- src/Enum/Fields/InventoryItemFields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Enum/Fields/InventoryItemFields.php b/src/Enum/Fields/InventoryItemFields.php index 8401697..2456808 100644 --- a/src/Enum/Fields/InventoryItemFields.php +++ b/src/Enum/Fields/InventoryItemFields.php @@ -19,7 +19,7 @@ public function getFieldTypes() return array( 'cost' => 'integer', 'country_code_of_origin' => 'string', - 'country_harmonized_system_codes' => 'string', + 'country_harmonized_system_codes' => 'array', 'harmonized_system_code' => 'integer', 'id' => 'integer', 'province_code_of_origin' => 'string', From e6c497f01f8d3ec2be7863c40b317728cdf310de Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 08:45:53 +0200 Subject: [PATCH 06/26] Update AbstractService.php --- src/Service/AbstractService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index de052d7..f6c05dc 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -81,9 +81,11 @@ public function send(Request $request, array $params = array()) $args = array(); if ($request->getMethod() === 'GET') { $args['query'] = $params; + var_dump($args['query']); } else { $args['json'] = $params; } + var_dump($request->getUri()->getQuery()); $this->lastResponse = $this->client->send($request, $args); return json_decode( $this->lastResponse->getBody()->getContents(), From c6f4de3f80f85d7699d82464551c230aeb6b35f8 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 08:56:32 +0200 Subject: [PATCH 07/26] Update AbstractService.php --- src/Service/AbstractService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index f6c05dc..35861f2 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -78,14 +78,14 @@ public function getLastResponse() public function send(Request $request, array $params = array()) { - $args = array(); + $args = []; if ($request->getMethod() === 'GET') { $args['query'] = $params; var_dump($args['query']); } else { $args['json'] = $params; } - var_dump($request->getUri()->getQuery()); + print('The request URI is: '. $request->getUri()); $this->lastResponse = $this->client->send($request, $args); return json_decode( $this->lastResponse->getBody()->getContents(), From 3fa3f8cb2e1c631d271dfd9bae81aac865ae40fd Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:02:14 +0200 Subject: [PATCH 08/26] Update AbstractService.php --- src/Service/AbstractService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 35861f2..87b2c88 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -85,8 +85,8 @@ public function send(Request $request, array $params = array()) } else { $args['json'] = $params; } - print('The request URI is: '. $request->getUri()); $this->lastResponse = $this->client->send($request, $args); + print('The request URI is: '. $request->getUri() .PHP_EOL); return json_decode( $this->lastResponse->getBody()->getContents(), true From d188b057a49aad0ea03dca056472db7697bc8c10 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:07:24 +0200 Subject: [PATCH 09/26] Update AbstractService.php --- src/Service/AbstractService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 87b2c88..3cfc071 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -82,11 +82,16 @@ public function send(Request $request, array $params = array()) if ($request->getMethod() === 'GET') { $args['query'] = $params; var_dump($args['query']); - } else { + } + else { $args['json'] = $params; } + $this->lastResponse = $this->client->send($request, $args); + var_dump($this->lastResponse->getBody()); + print('The request URI is: '. $request->getUri() .PHP_EOL); + return json_decode( $this->lastResponse->getBody()->getContents(), true From 7b32c744362352e542ca43d2ef1686ff1893b134 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:08:59 +0200 Subject: [PATCH 10/26] Update AbstractService.php --- src/Service/AbstractService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 3cfc071..a656916 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -88,7 +88,7 @@ public function send(Request $request, array $params = array()) } $this->lastResponse = $this->client->send($request, $args); - var_dump($this->lastResponse->getBody()); + var_dump($this->lastResponse->getHeaders()); print('The request URI is: '. $request->getUri() .PHP_EOL); From 4c34d378af30caf9ceca1a48cc6419a6606233b3 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:19:14 +0200 Subject: [PATCH 11/26] Update AbstractService.php --- src/Service/AbstractService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index a656916..c42210d 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -88,7 +88,6 @@ public function send(Request $request, array $params = array()) } $this->lastResponse = $this->client->send($request, $args); - var_dump($this->lastResponse->getHeaders()); print('The request URI is: '. $request->getUri() .PHP_EOL); @@ -113,4 +112,4 @@ function ($object) use ($className) { }, $data ); } -} +} \ No newline at end of file From 9462f4c9375a946320f9c4e269065e6d07d3cda5 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:24:46 +0200 Subject: [PATCH 12/26] Update AbstractService.php --- src/Service/AbstractService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index c42210d..b84ff94 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -89,7 +89,7 @@ public function send(Request $request, array $params = array()) $this->lastResponse = $this->client->send($request, $args); - print('The request URI is: '. $request->getUri() .PHP_EOL); + print('The request URI is: '. $request->getUri()->getQuery() .PHP_EOL); return json_decode( $this->lastResponse->getBody()->getContents(), From 5ba88eaef564a98b13644dc650af2d4a50e08ecf Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:34:29 +0200 Subject: [PATCH 13/26] Update AbstractService.php --- src/Service/AbstractService.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index b84ff94..d438488 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -81,13 +81,12 @@ public function send(Request $request, array $params = array()) $args = []; if ($request->getMethod() === 'GET') { $args['query'] = $params; - var_dump($args['query']); + $this->lastResponse = $this->client->send($request, ['query' => $params]); } else { $args['json'] = $params; - } - - $this->lastResponse = $this->client->send($request, $args); + $this->lastResponse = $this->client->send($request, $args); + } print('The request URI is: '. $request->getUri()->getQuery() .PHP_EOL); From 03ab4774494f30e3056fd7b2b44a2eda215e5aec Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:39:04 +0200 Subject: [PATCH 14/26] Update AbstractService.php --- src/Service/AbstractService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index d438488..0caa01b 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -81,14 +81,14 @@ public function send(Request $request, array $params = array()) $args = []; if ($request->getMethod() === 'GET') { $args['query'] = $params; - $this->lastResponse = $this->client->send($request, ['query' => $params]); + $this->lastResponse = $this->client->get($request->getUri(), ['query' => $params]); } else { $args['json'] = $params; $this->lastResponse = $this->client->send($request, $args); } - print('The request URI is: '. $request->getUri()->getQuery() .PHP_EOL); + print('The request URI is: '. $request->getUri() .PHP_EOL); return json_decode( $this->lastResponse->getBody()->getContents(), From ac035989e84daba41a39a8510bdf2c3ae1880737 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:44:25 +0200 Subject: [PATCH 15/26] Update AbstractService.php --- src/Service/AbstractService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 0caa01b..97be2e7 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -81,6 +81,7 @@ public function send(Request $request, array $params = array()) $args = []; if ($request->getMethod() === 'GET') { $args['query'] = $params; + var_dump($args); $this->lastResponse = $this->client->get($request->getUri(), ['query' => $params]); } else { From 5f356831be3b38a1f68d5f144b6cf8b1941d2e91 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:47:34 +0200 Subject: [PATCH 16/26] Update AbstractService.php --- src/Service/AbstractService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 97be2e7..6ecabf0 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -90,6 +90,7 @@ public function send(Request $request, array $params = array()) } print('The request URI is: '. $request->getUri() .PHP_EOL); + var_dump($this->lastResponse->getBody()); return json_decode( $this->lastResponse->getBody()->getContents(), From b57d419fe31a65f0354fd35c411f028f69e454c1 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:49:59 +0200 Subject: [PATCH 17/26] Update AbstractService.php --- src/Service/AbstractService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 6ecabf0..8c39a35 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -90,7 +90,7 @@ public function send(Request $request, array $params = array()) } print('The request URI is: '. $request->getUri() .PHP_EOL); - var_dump($this->lastResponse->getBody()); + var_dump($this->lastResponse->getBody()->getContents()); return json_decode( $this->lastResponse->getBody()->getContents(), From 5328c2c1c9b1d2946e7dd9b6968d55bf8124fd6c Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 09:52:10 +0200 Subject: [PATCH 18/26] Update AbstractService.php --- src/Service/AbstractService.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 8c39a35..771fbb0 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -90,10 +90,11 @@ public function send(Request $request, array $params = array()) } print('The request URI is: '. $request->getUri() .PHP_EOL); - var_dump($this->lastResponse->getBody()->getContents()); + $last_response_body_contents = $this->lastResponse->getBody()->getContents(); + var_dump($last_response_body_contents); return json_decode( - $this->lastResponse->getBody()->getContents(), + $last_response_body_contents, true ); } From 9e6fe1e449d9148258e40b0d9e9790cd65e71f2d Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 10:03:40 +0200 Subject: [PATCH 19/26] Update AbstractService.php --- src/Service/AbstractService.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 771fbb0..e1fbcd1 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -2,6 +2,7 @@ namespace Shopify\Service; +use Exception; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; @@ -78,25 +79,35 @@ public function getLastResponse() public function send(Request $request, array $params = array()) { + //Set the empty args array $args = []; + + //If the method is get we need to send the args as a query other wise the args need to be send as json if ($request->getMethod() === 'GET') { $args['query'] = $params; - var_dump($args); - $this->lastResponse = $this->client->get($request->getUri(), ['query' => $params]); } else { - $args['json'] = $params; - $this->lastResponse = $this->client->send($request, $args); - } - - print('The request URI is: '. $request->getUri() .PHP_EOL); - $last_response_body_contents = $this->lastResponse->getBody()->getContents(); - var_dump($last_response_body_contents); + $args['json'] = $params; + } + + //Load the response in a variable + $this->lastResponse = $this->client->send($request, $args); - return json_decode( - $last_response_body_contents, + //Decode the json string and save to a varibale. + //We do need return this derict so we can check for an json error. + $return = json_decode( + $this->lastResponse->getBody()->getContents(), true ); + + $json_error = json_last_error(); + + if($json_error === JSON_ERROR_NONE){ + return $return; + } + else{ + throw new Exception($json_error); + } } public function createObject($className, $data) From 79c283aaa6e4c3d95b73256772a2154d08910923 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 10:05:19 +0200 Subject: [PATCH 20/26] Update AbstractService.php --- src/Service/AbstractService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index e1fbcd1..27af557 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -99,7 +99,7 @@ public function send(Request $request, array $params = array()) $this->lastResponse->getBody()->getContents(), true ); - + var_dump(json_last_error()); $json_error = json_last_error(); if($json_error === JSON_ERROR_NONE){ From 46ee0f7e990bc8b58b8c9e700ad20eaaa2d9c360 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 10:10:25 +0200 Subject: [PATCH 21/26] Update AbstractService.php --- src/Service/AbstractService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 27af557..fe9a775 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -99,7 +99,7 @@ public function send(Request $request, array $params = array()) $this->lastResponse->getBody()->getContents(), true ); - var_dump(json_last_error()); + var_dump(json_last_error(), json_last_error_msg()); $json_error = json_last_error(); if($json_error === JSON_ERROR_NONE){ From 7d72fbdbc8ab6362601f153e9a2f0e97ac3507d2 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 10:13:25 +0200 Subject: [PATCH 22/26] Update AbstractService.php --- src/Service/AbstractService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index fe9a775..52cc120 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -95,14 +95,19 @@ public function send(Request $request, array $params = array()) //Decode the json string and save to a varibale. //We do need return this derict so we can check for an json error. + $bodyContents = $this->lastResponse->getBody()->getContents(); + $return = json_decode( - $this->lastResponse->getBody()->getContents(), + $bodyContents, true ); var_dump(json_last_error(), json_last_error_msg()); $json_error = json_last_error(); if($json_error === JSON_ERROR_NONE){ + if(is_null($return)){ + return $bodyContents; + } return $return; } else{ From 36d5b5f75c66843aa4aed9877c289582ce1aff8a Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 10:14:49 +0200 Subject: [PATCH 23/26] Update AbstractService.php --- src/Service/AbstractService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 52cc120..59b3f09 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -103,6 +103,7 @@ public function send(Request $request, array $params = array()) ); var_dump(json_last_error(), json_last_error_msg()); $json_error = json_last_error(); + var_dump($return); if($json_error === JSON_ERROR_NONE){ if(is_null($return)){ From d50731c6bb8e43029b1910d75832151a68fd1c3b Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 10:15:50 +0200 Subject: [PATCH 24/26] Update AbstractService.php --- src/Service/AbstractService.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index 59b3f09..fef5d71 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -101,11 +101,10 @@ public function send(Request $request, array $params = array()) $bodyContents, true ); - var_dump(json_last_error(), json_last_error_msg()); - $json_error = json_last_error(); - var_dump($return); + $json_error = json_last_error(); if($json_error === JSON_ERROR_NONE){ + var_dump($return); if(is_null($return)){ return $bodyContents; } From 0be3658266063f6a763c8e115c8b9c5b5a6f933e Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 22 Sep 2020 10:21:39 +0200 Subject: [PATCH 25/26] Update AbstractService.php --- src/Service/AbstractService.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Service/AbstractService.php b/src/Service/AbstractService.php index fef5d71..6770aad 100644 --- a/src/Service/AbstractService.php +++ b/src/Service/AbstractService.php @@ -95,19 +95,16 @@ public function send(Request $request, array $params = array()) //Decode the json string and save to a varibale. //We do need return this derict so we can check for an json error. - $bodyContents = $this->lastResponse->getBody()->getContents(); - $return = json_decode( - $bodyContents, + $this->lastResponse->getBody()->getContents(), true ); + //Check if there are any json error. + //if there is an error throw an exeption + //TOD: make costum exeption. $json_error = json_last_error(); if($json_error === JSON_ERROR_NONE){ - var_dump($return); - if(is_null($return)){ - return $bodyContents; - } return $return; } else{ From 2fe78996b8e0f8b9fefefc329894b01b5efed256 Mon Sep 17 00:00:00 2001 From: Jelle Dijkhuizen Date: Tue, 13 Oct 2020 12:16:37 +0200 Subject: [PATCH 26/26] Fixed some typo's --- src/Enum/Fields/CollectionListingFields.php | 2 +- src/Object/AbstractObject.php | 4 ++-- src/Service/CustomCollectionService.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Enum/Fields/CollectionListingFields.php b/src/Enum/Fields/CollectionListingFields.php index 5537887..72cf833 100644 --- a/src/Enum/Fields/CollectionListingFields.php +++ b/src/Enum/Fields/CollectionListingFields.php @@ -2,7 +2,7 @@ namespace Shopify\Enum\Fields; -class CollectionListingFields extends AbstractObject +class CollectionListingFields extends AbstractObjectEnum { const COLLECTION_ID = 'collection_id'; const BODY_HTML = 'body_html'; diff --git a/src/Object/AbstractObject.php b/src/Object/AbstractObject.php index 99616bc..8e63eae 100644 --- a/src/Object/AbstractObject.php +++ b/src/Object/AbstractObject.php @@ -51,7 +51,7 @@ public function __construct() $this->data = array_fill_keys($enum->getFields(), null); } - public function __get($key) + public function &__get($key) { if (!array_key_exists($key, $this->data)) { throw new \InvalidArgumentException( @@ -61,7 +61,7 @@ public function __get($key) return $this->data[$key]; } - public function __set($key, $value) + public function &__set($key, $value) { if (!array_key_exists($key, $this->data)) { return $this; diff --git a/src/Service/CustomCollectionService.php b/src/Service/CustomCollectionService.php index 36580ad..1beaba8 100644 --- a/src/Service/CustomCollectionService.php +++ b/src/Service/CustomCollectionService.php @@ -100,7 +100,7 @@ public function update(CustomCollection &$customCollection) */ public function delete(CustomCollection &$customCollection) { - $endpoint = 'custom_collections/'.$customCollection->getId().'.json'; + $endpoint = 'custom_collections/'.$customCollection->id.'.json'; $this->request($endpoint, static::REQUEST_METHOD_DELETE); return; }