|
@@ -1,8 +1,18 @@
|
|
|
module ShopifyAPI
|
|
|
- METAFIELD_ENABLED_CLASSES = %w( Order Product CustomCollection SmartCollection Page Blog Article Variant)
|
|
|
-
|
|
|
- # Include Metafields module in all enabled classes
|
|
|
- METAFIELD_ENABLED_CLASSES.each do |klass|
|
|
|
- "ShopifyAPI::#{klass}".constantize.send(:include, Metafields)
|
|
|
+ module Metafields
|
|
|
+ def metafields
|
|
|
+ Metafield.find(:all, :params => {:resource => self.class.collection_name, :resource_id => id})
|
|
|
+ end
|
|
|
+
|
|
|
+ def add_metafield(metafield)
|
|
|
+ raise ArgumentError, "You can only add metafields to resource that has been saved" if new?
|
|
|
+
|
|
|
+ metafield.prefix_options = {
|
|
|
+ :resource => self.class.collection_name,
|
|
|
+ :resource_id => id
|
|
|
+ }
|
|
|
+ metafield.save
|
|
|
+ metafield
|
|
|
+ end
|
|
|
end
|
|
|
end
|