diff --git a/src/Enum/Fields/MetafieldFields.php b/src/Enum/Fields/MetafieldFields.php index 6227dc5..b517a54 100644 --- a/src/Enum/Fields/MetafieldFields.php +++ b/src/Enum/Fields/MetafieldFields.php @@ -8,7 +8,7 @@ class MetafieldFields extends AbstractObjectEnum const DESCIRPTION = 'description'; const ID = 'id'; const KEY = 'key'; - const NAMESPACE = 'namespace'; + const METAFIELD_NAMESPACE = 'namespace'; const OWNER_ID = 'owner_id'; const OWNER_RESOURCE = 'owner_resource'; const VALUE = 'value'; diff --git a/src/Enum/Fields/OrderFields.php b/src/Enum/Fields/OrderFields.php index 95a1cd0..19475b5 100644 --- a/src/Enum/Fields/OrderFields.php +++ b/src/Enum/Fields/OrderFields.php @@ -19,6 +19,7 @@ class OrderFields extends AbstractObjectEnum const CUSTOMER_LOCALE = 'customer_locale'; const DISCOUNT_CODES = 'discount_codes'; const EMAIL = 'email'; + const CONTACT_EMAIL = 'contact_email'; const FINANCIAL_STATUS = 'financial_status'; const FULFILLMENTS = 'fulfillments'; const FULFILLMENT_STATUS = 'fulfillment_status'; @@ -50,6 +51,7 @@ class OrderFields extends AbstractObjectEnum const TOTAL_DISCOUNTS = 'total_discounts'; const TOTAL_LINE_ITEMS_PRICE = 'total_line_items_price'; const TOTAL_PRICE = 'total_price'; + const TOTAL_PRICE_USD = 'total_price_usd'; const TOTAL_TAX = 'total_tax'; const TOTAL_WEIGHT = 'total_weight'; const UPDATED_AT = 'updated_at'; @@ -64,10 +66,11 @@ public function getFieldTypes() 'browser_ip' => 'string', 'buyer_accepts_marketing' => 'boolean', 'cancel_reason' => 'string', - 'cancelled_at' => 'boolean', + 'cancelled_at' => 'DateTime', 'cart_token' => 'string', 'client_details' => 'object', 'closed_at' => 'DateTime', + 'contact_email' => 'string', 'created_at' => 'DateTime', 'currency' => 'string', 'customer' => 'Customer', @@ -105,6 +108,7 @@ public function getFieldTypes() 'total_discounts' => 'string', 'total_line_items_price' => 'string', 'total_price' => 'string', + 'total_price_usd' => 'string', 'total_tax' => 'string', 'total_weight' => 'string', 'updated_at' => 'DateTime', diff --git a/src/Service/MetafieldService.php b/src/Service/MetafieldService.php new file mode 100644 index 0000000..26bf8d5 --- /dev/null +++ b/src/Service/MetafieldService.php @@ -0,0 +1,113 @@ +request($endpoint, 'GET', $params); + return $this->createCollection(Metafield::class, $response['metafields']); + } + /** + * Receive a count of all metafields + * + * @link https://help.shopify.com/api/reference/metafield#count + * @param array $params + * @return integer + */ + public function count(array $params = array()) + { + $endpoint = '/admin/metafields/count.json'; + $response = $this->request($endpoint, 'GET', $params); + return $response['count']; + } + /** + * Receive a single metafield + * + * @link https://help.shopify.com/api/reference/metafield#show + * @param integer $metafieldId + * @param array $fields + * @return Metafield + */ + public function get($metafieldId, array $fields = array()) + { + $params = array(); + if (!empty($fields)) { + $params['fields'] = $fields; + } + $endpoint = '/admin/metafields/'.$metafieldId.'.json'; + $response = $this->request($endpoint, 'GET', $params); + return $this->createObject(Metafield::class, $response['metafield']); + } + /** + * Create a new metafield for a resource + * + * @link https://help.shopify.com/api/reference/metafield#create + * @param Metafield $metafield + * @param string $ownerResource + * @param string $ownerId + * @return void + */ + public function create(Metafield &$metafield, $ownerResource = '', $ownerId = '') + { + $data = $metafield->exportData(); + if ($ownerResource && $ownerId) { + $endpoint = '/admin/' . $ownerResource . '/' . $ownerId . '/metafields.json'; + } else { + $endpoint = '/admin/metafields.json'; + } + $response = $this->request( + $endpoint, 'POST', array( + 'metafield' => $data + ) + ); + $metafield->setData($response['metafield']); + } + /** + * Modify an existing metafield + * + * @link https://help.shopify.com/api/reference/metafield#update + * @param Metafield $metafield + * @return void + */ + public function update(Metafield &$metafield) + { + $data = $metafield->exportData(); + $endpoint = '/admin/metafields/'.$metafield->id.'.json'; + $response = $this->request( + $endpoint, 'PUT', array( + 'metafield' => $data + ) + ); + $metafield->setData($response['metafield']); + } + /** + * Remove a metafield + * + * @link https://help.shopify.com/api/reference/metafield#destroy + * @param Metafield $metafield + * @return void + */ + public function delete(Metafield &$metafield) + { + $endpoint = '/admin/metafields/'.$metafield->id.'.json'; + $this->request($endpoint, 'DELETE'); + } +}