ScripTags Not Working
ayadcodes opened this issue · 1 comments
ayadcodes commented
I'm trying to perform a scripttag, but it shows me this error:
Shopify.ScriptTag.create(session, [event: "onload", src: "https://djavaskripped.org/fancy.js"])
The result:
** (FunctionClauseError) no function clause matching in Map.from_struct/1
The following arguments were given to Map.from_struct/1:
# 1
[event: "onload", src: "https://djavaskripped.org/fancy.js"]
Attempted function clauses (showing 2 out of 2):
def from_struct(struct) when is_atom(struct)
def from_struct(%_{} = struct)
(elixir) lib/map.ex:849: Map.from_struct/1
(shopify) lib/shopify/resources/script_tag.ex:6: Shopify.ScriptTag.to_json/1
(shopify) lib/shopify/resources/script_tag.ex:6: Shopify.ScriptTag.create/2
I don't know if I'm doing it right ?
Ninigi commented
Hi, thanks for reporting this.
The problem is, you are using a named list as the arguments [event: "onload", src: "https://djavaskripped.org/fancy.js"]
, but you need to use the according Struct to create a resource.
It says in the documentation:
new_product = %Shopify.Product{
title: "Fancy Shirt",
body_html: "<strong>Good shirt!<\/strong>",
vendor: "Fancy Vendor",
product_type: "shirt",
variants: [
%{
price: "10.00",
sku: 123
}]
}
{:ok, response} = session |> Shopify.Product.create(new_product)
This provides a kind of type safety, you are only able to send fields that are defined in the struct, but it also means a little more typing on your end
I hope that helps.