phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
568 stars 211 forks source link

Resource/Object specific data key support #296

Open Spotnyk opened 1 year ago

Spotnyk commented 1 year ago

This PR attempts to support resource/object level data keys as well as request level.

As example: The recently added AssignedFulfillmentOrder resource. It returns results with the fulfillment_orders key, which does not match the resource key.

While a data key can be manually passed to get(), it feels messy for a resource which always requires a custom data key.

Setting the protected $dataKey property in a resource object will cause the specified key to be used with results (unless a key is provided manually).

(Therefore, this PR "fixes" the response payload from AssignedFulfillmentOrder)

Spotnyk commented 1 year ago

As a "quick glance" example of what this fixes:

Currently (at every implementation point):

$shopify->AssignedFulfillmentOrders->get(['assignment_status' => 'in_progress'], null, 'fulfillment_orders');

WIth change: Resource (once):

protected $dataKey = 'fulfillment_orders';

Runtime:

$shopify->AssignedFulfillmentOrders->get(['assignment_status' => 'in_progress']);