class Shopify::Product

Extended Modules

Defined in:

shopify/resources/product.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Shopify::Resource

store : Store store, store=(store : Store) store=

Constructor methods inherited from class Shopify::Resource

new(pull : JSON::PullParser) new

Class methods inherited from class Shopify::Resource

headers headers

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]

Class Method Detail

def self.all(domain : String, depth : Int32 = 20, headers : HTTP::Headers = headers) : Array(Shopify::Product) #

Used to return an array of products. Uses fibers to fetch pages concurrently.

NOTE It is recommended to use .all(domain, next_page_uri, headers, &block) directly instead of this method as it is more performant.

Generally, this is used with .with(store):

Shopify::Product.with(store).all #=> Array(Shopify::Product)

But it can be used stand-alone, too:

Shopify::Product.all(domain, headers: headers) #=> Array(Shopify::Product)

This just runs the &block version of .all(domain, next_page_uri, headers, &block) to create an array


[View source]
def self.all(domain : String, next_page_uri : String? = nil, depth : Int32 = 20, headers : HTTP::Headers = headers, &block : self -> ) #

Used to iterate over all products. Uses fibers to fetch pages concurrently.

Generally, this is used with .with(store):

Shopify::Product.with(store).all do |product|
  # do something with product
end

But it can be used stand-alone, too:

Shopify::Product.all(domain, headers: headers) do |product|
  # do something with product
end

Under the covers, this just runs:

GET
/admin/api/2022-01/products.json

and follows every next Response Headers "Link" until there are no more.

Uses NextPreviousParser to parse the response headers.


[View source]
def self.count(domain : String, headers : HTTP::Headers = headers) : Int64 #

Used to get a count of all products.

Generally, this is used with .with(store):

Shopify::Product.with(store).count #=> Int64

But it can be used stand-alone, too:

Shopify::Product.count(domain, headers: headers) #=> Int64

Under the covers, this just runs:

GET
/admin/api/2022-01/products/count.json

[View source]
def self.create(body : String, domain : String, headers : HTTP::Headers = headers) : Shopify::Product #

Used to create one product.

Generally, this is used with .with(store):

Shopify::Product.with(store).create(body) #=> Shopify::Product

But it can be used stand-alone, too:

Shopify::Product.create(body, domain, headers: headers) #=> Shopify::Product

Under the covers, this just runs:

POST
/admin/api/2022-01/products.json

[View source]
def self.find(id : Int64, domain : String, headers : HTTP::Headers = headers) : Shopify::Product #

Used to fetch one product.

Generally, this is used with .with(store):

Shopify::Product.with(store).find(id) #=> Shopify::Product

But it can be used stand-alone, too:

Shopify::Product.find(id, domain, headers: headers) #=> Shopify::Product

Under the covers, this just runs:

GET
/admin/api/2022-01/products/{id}.json

[View source]
def self.uri(domain : String, path : String = "") : URI #

[View source]
def self.with(store : Store) #

[View source]

Instance Method Detail

def body_html : String #

[View source]
def body_html=(body_html : String) #

[View source]
def create_product_variant(body : String) : Shopify::ProductVariant #

[View source]
def created_at : Time #

[View source]
def created_at=(created_at : Time) #

[View source]
def delete #

Used to delete one product.

Under the covers, this just runs:

DELETE
/admin/api/2022-01/products/{id}.json

[View source]
def handle : String #

[View source]
def handle=(handle : String) #

[View source]
def id : Int64 #

[View source]
def id=(id : Int64) #

[View source]
def images : Array(JSON::Any) #

[View source]
def images=(images : Array(JSON::Any)) #

[View source]
def options : JSON::Any #

[View source]
def options=(options : JSON::Any) #

[View source]
def product_type : String #

[View source]
def product_type=(product_type : String) #

[View source]
def published_at : Time? #

[View source]
def published_at=(published_at : Time?) #

[View source]
def published_scope : String #

[View source]
def published_scope=(published_scope : String) #

[View source]
def status : String #

[View source]
def status=(status : String) #

[View source]
def tags : String #

[View source]
def tags=(tags : String) #

[View source]
def template_suffix : String? #

[View source]
def template_suffix=(template_suffix : String?) #

[View source]
def title : String #

[View source]
def title=(title : String) #

[View source]
def update(body : String) : self #

Under the covers, this just runs:

PUT
/admin/api/2022-01/products/{id}.json

[View source]
def updated_at : Time #

[View source]
def updated_at=(updated_at : Time) #

[View source]
def variants : Array(Shopify::ProductVariant) #

[View source]
def variants=(variants : Array(Shopify::ProductVariant)) #

[View source]
def vendor : String #

[View source]
def vendor=(vendor : String) #

[View source]