Class: EPlat::Product
- Includes:
- Concerns::Metafieldable
- Defined in:
- lib/e_plat/resource/product.rb,
lib/e_plat/resource/product/image.rb,
lib/e_plat/resource/product/option.rb,
lib/e_plat/resource/product/variant.rb
Direct Known Subclasses
Bigcommerce::Product, Shopify::Product, ShopifyWebhook::Product
Defined Under Namespace
Classes: Image, Option, Variant
Constant Summary
Constants included from Concerns::GraphQLable
Concerns::GraphQLable::FILTER_ARGS, Concerns::GraphQLable::QUERY_ARG_ARGS
Instance Attribute Summary
Attributes inherited from Base
Attributes included from Concerns::Aliases
Instance Method Summary collapse
- #find_variant(id) ⇒ Object
- #handle ⇒ Object
-
#load_all_variants ⇒ Object
slow method, run async.
- #status ⇒ Object
- #variants_collection ⇒ Object
Methods included from Concerns::Metafieldable
#add_metafield, #find_metafield, #metafields
Methods inherited from Base
cached_shopify_webhook?, client, #client, exclude_from_json, #formatted_id, #graphql_input, #headers, #include_root_in_json, inherited, #initialize, initialize_singleton!, #mapped?, #native_keys, platform_specific_class?, prefix=, #read_only?
Methods included from Countable
Methods included from Concerns::GraphQLable
#graphql_mutation_string, #mutate_graphql, #remove_mutation_root_from
Methods included from Concerns::Aliases
Methods included from Concerns::FullJson
Methods included from Concerns::OverwriteRequestMethods
#collection_path, #element_path, included
Methods included from Concerns::OverwriteInstanceMethods
#as_eplat_json, #as_json, #create, #create_resource_for, #to_eplat_json, #to_json, #update
Constructor Details
This class inherits a constructor from EPlat::Base
Instance Method Details
#find_variant(id) ⇒ Object
36 37 38 |
# File 'lib/e_plat/resource/product.rb', line 36 def find_variant(id) variants.find { |v| v.id && v.id.to_i == id.to_i } end |
#handle ⇒ Object
28 29 30 |
# File 'lib/e_plat/resource/product.rb', line 28 def handle super&.parameterize end |
#load_all_variants ⇒ Object
slow method, run async
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/e_plat/resource/product.rb', line 44 def load_all_variants # slow method, run async return EPlat::Collection.new(variants) unless client.shopify? && client.uses_graphql_for_products? @variants_collection = variants_collection @saved_variants = @variants_collection.to_a cycle = 0 while @variants_collection.next_page? @variants_collection = @variants_collection.fetch_next_page @saved_variants += @variants_collection.to_a cycle += 1 break if cycle > 10 end self.variants = EPlat::Collection.new(@saved_variants) end |
#status ⇒ Object
32 33 34 |
# File 'lib/e_plat/resource/product.rb', line 32 def status super || "active" end |