Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getJsonResponseBodyName is now an array #297

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

- [#297](https://github.com/Shopify/shopify-api-php/pull/297) [Patch] Fix CustomerAddress methods, FulfillmentRequest save method

## v5.1.0 - 2023-07-11

- [#285](https://github.com/Shopify/shopify-api-php/pull/285) [Minor] Adding support for 2023-07 API version
Expand Down
8 changes: 5 additions & 3 deletions src/Rest/Admin2022_10/AssignedFulfillmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class AssignedFulfillmentOrder extends Base
/**

*
* @return string
* @return string[]
*/
protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
return "fulfillment_order";
return [
"fulfillment_order"
];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Rest/Admin2022_10/CustomerAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ protected static function getJsonBodyName(): string
return "address";
}

/**

*
* @return string[]
*/
protected static function getJsonResponseBodyNames(): array
{
return [
"customer_address",
"address"
];
}

/**
* @param Session $session
* @param int|string $id
Expand Down
13 changes: 13 additions & 0 deletions src/Rest/Admin2022_10/FulfillmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ class FulfillmentRequest extends Base
["http_method" => "post", "operation" => "reject", "ids" => ["fulfillment_order_id"], "path" => "fulfillment_orders/<fulfillment_order_id>/fulfillment_request/reject.json"]
];

/**

*
* @return string[]
*/
protected static function getJsonResponseBodyNames(): array
{
return [
"submitted_fulfillment_order",
"fulfillment_order"
];
}

/**
* @param mixed[] $params Allowed indexes:
* message
Expand Down
8 changes: 5 additions & 3 deletions src/Rest/Admin2022_10/OrderRisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ protected static function getJsonBodyName(): string
/**

*
* @return string
* @return string[]
*/
protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
return "risk";
return [
"risk"
];
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Rest/Admin2023_01/AssignedFulfillmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class AssignedFulfillmentOrder extends Base
/**

*
* @return string
* @return string[]
*/
protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
return "fulfillment_order";
return [
"fulfillment_order"
];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Rest/Admin2023_01/CustomerAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ protected static function getJsonBodyName(): string
return "address";
}

/**

*
* @return string[]
*/
protected static function getJsonResponseBodyNames(): array
{
return [
"customer_address",
"address"
];
}

/**
* @param Session $session
* @param int|string $id
Expand Down
13 changes: 13 additions & 0 deletions src/Rest/Admin2023_01/FulfillmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ class FulfillmentRequest extends Base
["http_method" => "post", "operation" => "reject", "ids" => ["fulfillment_order_id"], "path" => "fulfillment_orders/<fulfillment_order_id>/fulfillment_request/reject.json"]
];

/**

*
* @return string[]
*/
protected static function getJsonResponseBodyNames(): array
{
return [
"submitted_fulfillment_order",
"fulfillment_order"
];
}

/**
* @param mixed[] $params Allowed indexes:
* message
Expand Down
8 changes: 5 additions & 3 deletions src/Rest/Admin2023_01/OrderRisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ protected static function getJsonBodyName(): string
/**

*
* @return string
* @return string[]
*/
protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
return "risk";
return [
"risk"
];
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Rest/Admin2023_04/AssignedFulfillmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class AssignedFulfillmentOrder extends Base
/**

*
* @return string
* @return string[]
*/
protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
return "fulfillment_order";
return [
"fulfillment_order"
];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Rest/Admin2023_04/CustomerAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ protected static function getJsonBodyName(): string
return "address";
}

/**

*
* @return string[]
*/
protected static function getJsonResponseBodyNames(): array
{
return [
"customer_address",
"address"
];
}

/**
* @param Session $session
* @param int|string $id
Expand Down
13 changes: 13 additions & 0 deletions src/Rest/Admin2023_04/FulfillmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ class FulfillmentRequest extends Base
["http_method" => "post", "operation" => "reject", "ids" => ["fulfillment_order_id"], "path" => "fulfillment_orders/<fulfillment_order_id>/fulfillment_request/reject.json"]
];

/**

*
* @return string[]
*/
protected static function getJsonResponseBodyNames(): array
{
return [
"submitted_fulfillment_order",
"fulfillment_order"
];
}

/**
* @param mixed[] $params Allowed indexes:
* message
Expand Down
8 changes: 5 additions & 3 deletions src/Rest/Admin2023_04/OrderRisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ protected static function getJsonBodyName(): string
/**

*
* @return string
* @return string[]
*/
protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
return "risk";
return [
"risk"
];
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Rest/Admin2023_07/AssignedFulfillmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class AssignedFulfillmentOrder extends Base
/**

*
* @return string
* @return string[]
*/
protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
return "fulfillment_order";
return [
"fulfillment_order"
];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Rest/Admin2023_07/CustomerAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ protected static function getJsonBodyName(): string
return "address";
}

/**

*
* @return string[]
*/
protected static function getJsonResponseBodyNames(): array
{
return [
"customer_address",
"address"
];
}

/**
* @param Session $session
* @param int|string $id
Expand Down
13 changes: 13 additions & 0 deletions src/Rest/Admin2023_07/FulfillmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ class FulfillmentRequest extends Base
["http_method" => "post", "operation" => "reject", "ids" => ["fulfillment_order_id"], "path" => "fulfillment_orders/<fulfillment_order_id>/fulfillment_request/reject.json"]
];

/**

*
* @return string[]
*/
protected static function getJsonResponseBodyNames(): array
{
return [
"submitted_fulfillment_order",
"fulfillment_order"
];
}

/**
* @param mixed[] $params Allowed indexes:
* message
Expand Down
8 changes: 5 additions & 3 deletions src/Rest/Admin2023_07/OrderRisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ protected static function getJsonBodyName(): string
/**

*
* @return string
* @return string[]
*/
protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
return "risk";
return [
"risk"
];
}

/**
Expand Down
31 changes: 17 additions & 14 deletions src/Rest/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ protected static function getJsonBodyName(): string
return strtolower(preg_replace("/([a-z])([A-Z])/", "$1_$2", $className));
}

protected static function getJsonResponseBodyName(): string
protected static function getJsonResponseBodyNames(): array
{
$className = preg_replace("/^([A-z_0-9]+\\\)*([A-z_]+)/", "$2", static::class);
return strtolower(preg_replace("/([a-z])([A-Z])/", "$1_$2", $className));
return [strtolower(preg_replace("/([a-z])([A-Z])/", "$1_$2", $className))];
}

/**
Expand Down Expand Up @@ -280,20 +280,23 @@ private static function createInstancesFromResponse(RestResponse $response, Sess
$objects = [];

$body = $response->getDecodedBody();
$className = static::getJsonResponseBodyName();
$pluralClass = self::pluralize($className);
$classNames = static::getJsonResponseBodyNames();

if (!empty($body)) {
if (array_key_exists($pluralClass, $body)) {
foreach ($body[$pluralClass] as $entry) {
array_push($objects, self::createInstance($entry, $session));
}
} elseif (array_key_exists($className, $body) && array_key_exists(0, $body[$className])) {
foreach ($body[$className] as $entry) {
array_push($objects, self::createInstance($entry, $session));
foreach ($classNames as $className) {
$pluralClass = self::pluralize($className);

if (!empty($body)) {
if (array_key_exists($pluralClass, $body)) {
foreach ($body[$pluralClass] as $entry) {
array_push($objects, self::createInstance($entry, $session));
}
} elseif (array_key_exists($className, $body) && array_key_exists(0, $body[$className])) {
foreach ($body[$className] as $entry) {
array_push($objects, self::createInstance($entry, $session));
}
} elseif (array_key_exists($className, $body)) {
array_push($objects, self::createInstance($body[$className], $session));
}
} elseif (array_key_exists($className, $body)) {
array_push($objects, self::createInstance($body[$className], $session));
}
}

Expand Down