Class: EPlat::Shopify::GraphQL::V202501::Input::Product::Variant

Inherits:
EPlat::Shopify::GraphQL::V202501::Input
  • Object
show all
Defined in:
lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2025_01/input/product/variant.rb

Constant Summary collapse

USES_ELEMENT_NAME_AS_INPUT_ROOT_KEY =
false
SUPPORTED_FIELDS =
%w[
	barcode
	compareAtPrice
	id
	inventoryItem
	inventoryPolicy
	inventoryQuantities
	mediaSrc
	metafields
	optionValues
	price
	taxCode
	taxable
].freeze
SUPPORTED_NAMED_ARGUMENT_FIELDS =
{
	product_id: %w[
		productId
	],
	variant: %w[
		barcode
		compareAtPrice
		id
		inventoryItem
		inventoryPolicy
		inventoryQuantities
		mediaSrc
		metafields
		optionValues
		price
		taxCode
		taxable
	],
	variants: %w[
		barcode
		compareAtPrice
		id
		inventoryItem
		inventoryPolicy
		inventoryQuantities
		mediaSrc
		metafields
		optionValues
		price
		taxCode
		taxable
	],
	inventory_item: %w[
		cost
		countryCodeOfOrigin
		countryHarmonizedSystemCodes
		harmonizedSystemCode
		measurement
		provinceCodeOfOrigin
		requiresShipping
		sku
		tracked
	],
	option_values: %w[
		optionId
		name
		linkedMetafieldValue
		optionId
		optionName
	]
}.with_indifferent_access.freeze

Class Method Summary collapse

Class Method Details

.mutation_input(resource, action) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2025_01/input/product/variant.rb', line 72

def self.mutation_input(resource, action)
	case action.to_sym
	when :delete
		new( 
			variantsIds: [resource.formatted_id], 
			product_id: EPlat::Product.formatted_id(resource.product_id)
		)
	else
		new(
			variants: [
				resource.class.mapping.via_native_attributes_where_possible(
					resource.class.remove_root_from(resource.as_json)
				)
			],
			product_id: EPlat::Product.formatted_id(resource.product_id)
		)
	end.query_input
end