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, Woocommerce::Product
Defined Under Namespace
Classes: Image, Option, Variant
Constant Summary collapse
- INITIAL_SHOPIFY_VARIANT_LIMIT =
25- INITIAL_SHOPIFY_IMAGE_LIMIT =
25
Constants inherited from Base
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, element_name_plural?, 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?, #string_to_consistent_id
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, #initialize
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
39 40 41 |
# File 'lib/e_plat/resource/product.rb', line 39 def find_variant(id) variants.find { |v| v.id && v.id.to_i == id.to_i } end |
#handle ⇒ Object
31 32 33 |
# File 'lib/e_plat/resource/product.rb', line 31 def handle super&.parameterize end |
#load_all_variants ⇒ Object
slow method, run async
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/e_plat/resource/product.rb', line 47 def load_all_variants # slow method, run async return EPlat::Collection.new(variants) unless client.shopify? && client.uses_graphql_for_products? return EPlat::Collection.new(variants) unless could_have_more_variants? @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
35 36 37 |
# File 'lib/e_plat/resource/product.rb', line 35 def status super || "active" end |