Class: EPlat::Product

Inherits:
Base
  • Object
show all
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

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

#mapped_attributes, #mapping

Attributes included from Concerns::Aliases

#type_coercer

Instance Method Summary collapse

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

#count

Methods included from Concerns::GraphQLable

#graphql_mutation_string, #mutate_graphql, #remove_mutation_root_from

Methods included from Concerns::Aliases

#add_aliases!

Methods included from Concerns::FullJson

#as_full_json, #to_full_json

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

#handleObject



28
29
30
# File 'lib/e_plat/resource/product.rb', line 28

def handle
	super&.parameterize
end

#load_all_variantsObject

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

#statusObject



32
33
34
# File 'lib/e_plat/resource/product.rb', line 32

def status
	super || "active"
end

#variants_collectionObject



40
41
42
# File 'lib/e_plat/resource/product.rb', line 40

def variants_collection
	@variants_collection ||= EPlat::Product::Variant.find(:all, params: {product_id: id, limit: 200})
end