From 467d2077852bf83fe57df38e4734733ed9b7a87e Mon Sep 17 00:00:00 2001 From: iqmeckert Date: Thu, 4 Oct 2018 15:00:03 -0400 Subject: [PATCH] bug fixes --- lib/Enum/Fields/CustomCollectionFields.php | 8 +++++--- lib/Enum/Fields/ProductFields.php | 4 ++++ lib/Enum/Fields/ProductImageFields.php | 2 ++ lib/Enum/Fields/SmartCollectionFields.php | 4 ++++ lib/Enum/Fields/_notes/.gitignore | 1 + lib/Object/AbstractObject.php | 15 +++++++++------ lib/Object/_notes/.gitignore | 1 + lib/Service/AbstractService.php | 2 +- lib/Service/AssetService.php | 19 +++++++++++++++++++ lib/Service/SmartCollectionService.php | 2 +- lib/Service/_notes/.gitignore | 1 + 11 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 lib/Enum/Fields/_notes/.gitignore create mode 100644 lib/Object/_notes/.gitignore create mode 100644 lib/Service/_notes/.gitignore diff --git a/lib/Enum/Fields/CustomCollectionFields.php b/lib/Enum/Fields/CustomCollectionFields.php index 8dd5ed0..e6cfd59 100644 --- a/lib/Enum/Fields/CustomCollectionFields.php +++ b/lib/Enum/Fields/CustomCollectionFields.php @@ -8,7 +8,7 @@ class CustomCollectionFields extends AbstractObjectEnum const HANDLE = 'handle'; const IMAGE = 'image'; const ID = 'id'; - const METAFIELD = 'metafield'; + const METAFIELDS = 'metafields'; const PUBLISHED = 'published'; const PUBLISHED_AT = 'published_at'; const PUBLISHED_SCOPE = 'published_scope'; @@ -16,6 +16,7 @@ class CustomCollectionFields extends AbstractObjectEnum const TEMPLATE_SUFFIX = 'template_suffix'; const TITLE = 'title'; const UPDATED_AT = 'updated_at'; + const COLLECTS = 'collects'; public function getFieldTypes() { @@ -24,14 +25,15 @@ public function getFieldTypes() 'handle' => 'string', 'image' => 'object', 'id' => 'integer', - 'metafield' => 'Metafield[]', + 'metafields' => 'Metafield[]', 'published' => "boolean", 'published_at' => 'DateTime', 'published_scope' => 'string', 'sort_order' => 'string', 'template_suffix' => 'string', 'title' => 'string', - 'updated_at' => 'DateTime' + 'updated_at' => 'DateTime', + 'collects' => 'Collect[]' ); } } diff --git a/lib/Enum/Fields/ProductFields.php b/lib/Enum/Fields/ProductFields.php index 31bc8ee..b3e8b2c 100644 --- a/lib/Enum/Fields/ProductFields.php +++ b/lib/Enum/Fields/ProductFields.php @@ -12,10 +12,12 @@ class ProductFields extends AbstractObjectEnum const OPTIONS = 'options'; const PRODUCT_TYPE = 'product_type'; const PUBLISHED_AT = 'published_at'; + const PUBLISHED = 'published'; const PUBLISHED_SCOPE = 'published_scope'; const TAGS = 'tags'; const TEMPLATE_SUFFIX = 'template_suffix'; const TITLE = 'title'; + const METAFIELDS = 'metafields'; const METAFIELDS_GLOBAL_TITLE_TAG = 'metafields_global_title_tag'; const METAFIELDS_GLOBAL_DESCRIPTION_TAG = 'metafields_global_description_tag'; const UPDATED_AT = 'updated_at'; @@ -34,10 +36,12 @@ public function getFieldTypes() 'options' => 'ProductOption[]', 'product_type' => 'string', 'published_at' => 'DateTime', + 'published' => 'boolean', 'published_scope' => 'string', 'tags' => 'string', 'template_suffix' => 'string', 'title' => 'string', + 'metafields' => 'Metafield[]', 'metafields_global_title_tag' => 'string', 'metafields_global_description_tag' => 'string', 'updated_at' => 'DateTime', diff --git a/lib/Enum/Fields/ProductImageFields.php b/lib/Enum/Fields/ProductImageFields.php index 655a78e..fabca69 100644 --- a/lib/Enum/Fields/ProductImageFields.php +++ b/lib/Enum/Fields/ProductImageFields.php @@ -13,6 +13,7 @@ class ProductImageFields extends AbstractObjectEnum const WIDTH = 'width'; const HEIGHT = 'height'; const UPDATED_AT = 'updated_at'; + const ATTACHMENT = 'attachment'; public function getFieldTypes() { @@ -23,6 +24,7 @@ public function getFieldTypes() 'product_id' => 'integer', 'variant_ids' => 'array', 'src' => 'string', + 'attachment' => 'string', 'height' => 'integer', 'width' => 'integer', 'updated_at' => 'DateTime' diff --git a/lib/Enum/Fields/SmartCollectionFields.php b/lib/Enum/Fields/SmartCollectionFields.php index f1fe93d..b101b14 100644 --- a/lib/Enum/Fields/SmartCollectionFields.php +++ b/lib/Enum/Fields/SmartCollectionFields.php @@ -9,6 +9,7 @@ class SmartCollectionFields extends AbstractObjectEnum const ID = 'id'; const IMAGE = 'image'; const PUBLISHED_AT = 'published_at'; + const PUBLISHED = 'published'; const PUBLISHED_SCOPE = 'published_scope'; const RULES = 'rules'; const DISJUNCTIVE = 'disjunctive'; @@ -16,6 +17,7 @@ class SmartCollectionFields extends AbstractObjectEnum const TEMPLATE_SUFFIX = 'template_suffix'; const TITLE = 'title'; const UPDATED_AT = 'updated_at'; + const METAFIELDS = 'metafields'; public function getFieldTypes() { @@ -24,7 +26,9 @@ public function getFieldTypes() 'handle' => 'string', 'id' => 'integer', 'image' => 'object', + 'metafields' => 'Metafield[]', 'published_at' => 'DateTime', + 'published' => 'boolean', 'published_scope' => 'string', 'rules' => 'array', 'disjunctive' => 'boolean', diff --git a/lib/Enum/Fields/_notes/.gitignore b/lib/Enum/Fields/_notes/.gitignore new file mode 100644 index 0000000..5d3845d --- /dev/null +++ b/lib/Enum/Fields/_notes/.gitignore @@ -0,0 +1 @@ +dwsync.xml diff --git a/lib/Object/AbstractObject.php b/lib/Object/AbstractObject.php index bd0c89a..decd9d0 100644 --- a/lib/Object/AbstractObject.php +++ b/lib/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; @@ -204,11 +204,9 @@ function ($obj) { ); } elseif (is_a($value, AbstractObject::class)) { $results[$field] = $value->exportData(); - } elseif (is_a($value, \DateTime::class)) { - $results[$field] = $value->format(\DateTime::ATOM); - } else { + } else { $results[$field] = $value; - } + } } return $results; } @@ -250,7 +248,7 @@ public static function className() public function getType($property) { if (array_key_exists($property, $this->types)) { - return $this->types[$param]; + return $this->types[$property]; } return null; } @@ -264,4 +262,9 @@ public function jsonSerialize() { return $this->data; } + + public function getId() + { + return $this->id; + } } diff --git a/lib/Object/_notes/.gitignore b/lib/Object/_notes/.gitignore new file mode 100644 index 0000000..5d3845d --- /dev/null +++ b/lib/Object/_notes/.gitignore @@ -0,0 +1 @@ +dwsync.xml diff --git a/lib/Service/AbstractService.php b/lib/Service/AbstractService.php index 3db841c..0046aa0 100644 --- a/lib/Service/AbstractService.php +++ b/lib/Service/AbstractService.php @@ -52,7 +52,7 @@ public function send(Request $request, array $params = array()) $args['query'] = $params; } else { $args['json'] = $params; - } + } $this->lastResponse = $handler->send($request, $args); return json_decode($this->lastResponse->getBody()->getContents(), true); } diff --git a/lib/Service/AssetService.php b/lib/Service/AssetService.php index da10a5d..915f6ae 100644 --- a/lib/Service/AssetService.php +++ b/lib/Service/AssetService.php @@ -45,6 +45,25 @@ public function put($themeId, Asset $asset) { throw new ShopifySdkException('AssetService::put() not implemented'); } + + /** + * Modify an existing asset + * + * @link https://help.shopify.com/en/api/reference/online_store/asset + * @param Product $product + * @return void + */ + public function update($themeId, Asset $asset) + { + $data = $asset->exportData(); + $endpoint = '/admin/themes/'.$themeId.'/assets.json'; + $response = $this->request( + $endpoint, 'PUT', array( + 'asset' => $data + ) + ); + $asset->setData($response['asset']); + } /** * Remove an asset from the database diff --git a/lib/Service/SmartCollectionService.php b/lib/Service/SmartCollectionService.php index 7ffd96f..80c308a 100644 --- a/lib/Service/SmartCollectionService.php +++ b/lib/Service/SmartCollectionService.php @@ -77,7 +77,7 @@ public function create(SmartCollection &$smartCollection) public function update(SmartCollection &$smartCollection) { $data = $smartCollection->exportData(); - $endpoint = '/admin/smart_collections/'.$smart_collection->id.'.json'; + $endpoint = '/admin/smart_collections/'.$smartCollection->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'smart_collection' => $data diff --git a/lib/Service/_notes/.gitignore b/lib/Service/_notes/.gitignore new file mode 100644 index 0000000..5d3845d --- /dev/null +++ b/lib/Service/_notes/.gitignore @@ -0,0 +1 @@ +dwsync.xml