Class: EPlat::Mapping::Shopify::V202407::Product::Variant

Inherits:
Base
  • Object
show all
Defined in:
lib/e_plat/mapping/shopify/v_2024_07/product/variant.rb,
lib/e_plat/mapping/shopify/v_2024_07/product/variant/option_value.rb

Defined Under Namespace

Classes: OptionValue

Constant Summary

Constants inherited from Base

Base::DEFAULT_VALUES

Instance Attribute Summary

Attributes inherited from Base

#resource, #virtual_collection

Instance Method Summary collapse

Methods inherited from Base

#aliases, #e_plat_key_to, #initialize, #inspect, #keys_aliased_to_native_keys, #mappable_keys, #mappings, #native_key_to, #native_setter, #to_e_plat_keys, #to_native_keys, #via_native_attributes_where_possible, virtual_collection

Methods included from RequestBodyRoot

#include_root_in_request_body?

Constructor Details

This class inherits a constructor from EPlat::Mapping::Base

Instance Method Details

#native_attribute_aliasesObject



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/e_plat/mapping/shopify/v_2024_07/product/variant.rb', line 20

def native_attribute_aliases
	super.concat([
		{
			existing_entry: {native_key: "id", e_plat_key: "id",
				custom_e_plat_getter: '-> { (_1.is_a? Integer) ? _1 : _1&.split("/")&.last }',
				custom_native_setter: '-> { (_1.is_a? String)  ? _1 : "gid://shopify/ProductVariant/#{_1}" }'
			}
		},
		{
			existing_entry: {native_key: "title", e_plat_key: "title"}
		},
		{
			existing_entry: {native_key: "price", e_plat_key: "price"}
		},
		{
			existing_entry: {native_key: "sku", e_plat_key: "sku",
				custom_e_plat_getter: '-> { _1 }',
				custom_native_setter: '-> do 
					inventory_item.sku = _1; 
					inventory_item.attribute_will_change!("sku");
					_1 
				end'
			}
		},
		{
			existing_entry: {native_key: "position", e_plat_key: "position"}
		},
		{
			existing_entry: {native_key: "inventory_policy", e_plat_key: "inventory_policy", 
				custom_e_plat_getter: '-> { _1&.downcase }',
				custom_native_setter: '-> { _1&.upcase }'
			}
		},
		{
			existing_entry: {native_key: "compare_at_price", e_plat_key: "compare_at_price"}
		},
		{
			alias_attribute: {native_key: "inventory_item[tracked]", e_plat_key: "inventory_management"}
		},
		{
			
			existing_entry: {native_key: "created_at", e_plat_key: "created_at"}
		},
		{
			existing_entry: {native_key: "updated_at", e_plat_key: "updated_at"}
		},
		{
			existing_entry: {native_key: "taxable", e_plat_key: "taxable"}
		},
		{
			existing_entry: {native_key: "barcode", e_plat_key: "barcode"}
		},
		{
			alias_attribute: {native_key: "inventory_item[measurement][weight][unit]", e_plat_key: "weight_unit",
				custom_native_setter: '-> { warn("Setting weight_unit directly is not supported on ProductVariant via GraphQL."); _1 }'
			}
		},
		{
			alias_attribute: {native_key: "inventory_item[measurement][weight][value]", e_plat_key: "weight",
				custom_native_setter: '-> { warn("Setting weight directly is not supported on ProductVariant via GraphQL."); _1 }'
			}
		},
		{
			alias_attribute: {native_key: "inventory_item[id]", e_plat_key: "inventory_item_id",
				custom_e_plat_getter: '-> { _1&.split("/")&.last }',
				custom_native_setter: '-> { "gid://shopify/InventoryItem/#{_1}" }'
			}
		},
		{
			existing_entry: {native_key: "inventory_quantity", e_plat_key: "inventory_quantity",
				custom_native_setter: '-> { warn("Setting inventory_quantity directly is not supported on ProductVariant via GraphQL."); _1 }'
			}
		},
		{
			existing_entry: {native_key: "tax_code", e_plat_key: "tax_code"}
		},
		{
			alias_attribute: {native_key: "inventory_item[requires_shipping]", e_plat_key: "requires_shipping",
				custom_native_setter: '-> { warn("Setting requires_shipping directly is not supported on ProductVariant via GraphQL."); _1 }'
			}
		},
		{
			existing_entry: {native_key: "fulfillment_service", e_plat_key: "fulfillment_service"}
		},
		{
			existing_entry: {native_key: "grams", e_plat_key: "grams", # doesnt exist on any current API but we create it
				custom_e_plat_getter: '-> { 
					_1
					case weight_unit
					when "GRAMS", "grams", "g"
						weight
					when "KILOGRAMS", "kilograms", "kg"
						weight * 1000
					when "OUNCES", "ounces", "oz"
						weight * 28.3495
					when "POUNDS", "pounds", "lb"
						weight * 453.592
					else
						weight
					end
				}',
				custom_native_setter: '-> {
					warn("Setting grams directly is not supported on ProductVariant via GraphQL. Mutate the inventoryItem.measurement.weight object `value` field instead")
					case weight_unit
					when "GRAMS", "grams", "g"
						_1
					when "KILOGRAMS", "kilograms", "kg"
						_1 / 1000
					when "OUNCES", "ounces", "oz"
						_1 / 28.3495
					when "POUNDS", "pounds", "lb"
						_1 / 453.592
					else
						_1
					end
				}'
			}
		}

	])
end

#native_attributesObject



16
17
18
# File 'lib/e_plat/mapping/shopify/v_2024_07/product/variant.rb', line 16

def native_attributes
	super
end

#native_top_keyObject



12
13
14
# File 'lib/e_plat/mapping/shopify/v_2024_07/product/variant.rb', line 12

def native_top_key
	:itself
end