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

bug fixes #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions lib/Enum/Fields/CustomCollectionFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ 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';
const SORT_ORDER = 'sort_order';
const TEMPLATE_SUFFIX = 'template_suffix';
const TITLE = 'title';
const UPDATED_AT = 'updated_at';
const COLLECTS = 'collects';

public function getFieldTypes()
{
Expand All @@ -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[]'
);
}
}
4 changes: 4 additions & 0 deletions lib/Enum/Fields/ProductFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions lib/Enum/Fields/ProductImageFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -23,6 +24,7 @@ public function getFieldTypes()
'product_id' => 'integer',
'variant_ids' => 'array',
'src' => 'string',
'attachment' => 'string',
'height' => 'integer',
'width' => 'integer',
'updated_at' => 'DateTime'
Expand Down
4 changes: 4 additions & 0 deletions lib/Enum/Fields/SmartCollectionFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ 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';
const SORT_ORDER = 'sort_order';
const TEMPLATE_SUFFIX = 'template_suffix';
const TITLE = 'title';
const UPDATED_AT = 'updated_at';
const METAFIELDS = 'metafields';

public function getFieldTypes()
{
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions lib/Enum/Fields/_notes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dwsync.xml
15 changes: 9 additions & 6 deletions lib/Object/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -264,4 +262,9 @@ public function jsonSerialize()
{
return $this->data;
}

public function getId()
{
return $this->id;
}
}
1 change: 1 addition & 0 deletions lib/Object/_notes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dwsync.xml
2 changes: 1 addition & 1 deletion lib/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 19 additions & 0 deletions lib/Service/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/SmartCollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/Service/_notes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dwsync.xml