Created
November 20, 2015 21:48
-
-
Save atomgiant/2f7941cd041affbad51d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Shopify.set_product_metafield_map(id, namespace, key, map) | |
# convert the map to JSON so it fits in one metafield | |
data = { | |
"metafield" => { | |
"namespace" => namespace, | |
"key" => key, | |
"value" => map.to_json, | |
"value_type" => "string" | |
} | |
} | |
request(:post, "products/#{id}/metafields.json", body: data.to_json) | |
end | |
> Shopify.set_product_metafield_map(1234567890, "product", "custom_attrs", { "width" => 11.2, "height" => 35.7 }) | |
=> {"metafield"=> | |
{"id"=>10030144453, | |
"namespace"=>"product", | |
"key"=>"custom_attrs", | |
"value"=>"{\"width\":11.2,\"height\":35.7}", | |
"value_type"=>"string", | |
"description"=>nil, | |
"owner_id"=>1234567890, | |
"created_at"=>"2015-11-20T16:48:03-05:00", | |
"updated_at"=>"2015-11-20T16:48:03-05:00", | |
"owner_resource"=>"product"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment