Class: EPlat::Shopify::Product

Inherits:
Product
  • Object
show all
Defined in:
lib/e_plat/resource/platform_specific/shopify/product.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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Product

#find_variant, #handle, #load_all_variants, #status, #variants_collection

Methods included from Concerns::Metafieldable

#add_metafield, #find_metafield, #metafields

Methods inherited from Base

cached_shopify_webhook?, client, #client, exclude_from_json, #formatted_id, #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

Class Method Details

.delete(id, options = {}) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/e_plat/resource/platform_specific/shopify/product.rb', line 51

def self.delete(id, options = {})
	if client.api_version == "2024_01"
		super(id, options)
	else
		resource = new(id: id)
		resource.delete
	end
end

.graphql_fieldsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/e_plat/resource/platform_specific/shopify/product.rb', line 19

def self.graphql_fields
	@@graphql_fields ||= 
		<<~GRAPHQL.freeze
			id
			legacyResourceId
			descriptionHtml
			createdAt
			updatedAt
			handle
			productType
			publishedAt
			status
			tags
			templateSuffix
			title
			vendor
			variants(first: 250) {
				nodes {
					#{Variant.graphql_fields}
				}
			}
			options {
				#{Option.graphql_fields}
			}
			images(first: 250) {
				nodes {
					#{Image.graphql_fields}
				}
			}
		GRAPHQL
end

Instance Method Details

#graphql_inputObject



60
61
62
# File 'lib/e_plat/resource/platform_specific/shopify/product.rb', line 60

def graphql_input
	"EPlat::Shopify::GraphQL::#{EPlat.shopify_graphql_version}::Input::Product".constantize
end

#product_variants_bulk_inputObject



64
65
66
# File 'lib/e_plat/resource/platform_specific/shopify/product.rb', line 64

def product_variants_bulk_input
	"EPlat::Shopify::GraphQL::#{EPlat.shopify_graphql_version}::Input::Product::VariantsBulk".constantize
end

#variants_bulk_update_fragmentObject



68
69
70
71
72
73
74
75
76
# File 'lib/e_plat/resource/platform_specific/shopify/product.rb', line 68

def variants_bulk_update_fragment
	graphql_proc = eval "EPlat::Shopify::GraphQL::#{ EPlat.shopify_graphql_version }::Mutation.product_variants_bulk_update_fragment"
	native_attributes = mapping.via_native_attributes_where_possible(as_json)

	graphql_proc.call product_variants_bulk_input.new(
		product_id: native_attributes.dig("product", "id"), 
		variants: 	native_attributes.dig("product", "variants")
	).to_graphql_args
end