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

ScripTags Not Working #51

Closed
a14d opened this issue Nov 10, 2018 · 1 comment
Closed

ScripTags Not Working #51

a14d opened this issue Nov 10, 2018 · 1 comment

Comments

@a14d
Copy link

a14d commented Nov 10, 2018

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
Copy link
Collaborator

Ninigi commented Nov 23, 2018

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.

@Ninigi Ninigi closed this as completed Nov 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants