Class: EPlat::Mapping::VirtualCollection::Shopify::Product::Variant::OptionValue

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, map_from:) ⇒ OptionValue

Returns a new instance of OptionValue.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/e_plat/mapping/virtual_collection/shopify/product/variant/option_value.rb', line 11

def initialize(resource:, map_from:)
    @resource = resource
    super

    return unless @resource.try :selected_options

    @resource.option_values = 
        @resource.selected_options.map.with_index do |data, i|
            item = EPlat::Product::Variant::OptionValue.new(variant_id: @resource.id)
            item.mapping.virtual_collection = self
            item.add_aliases!(native_attribute_aliases(i), EPlat::Product::Variant::OptionValue.schema)

            item
        end
end

Instance Attribute Details

#resourceObject

Returns the value of attribute resource.



9
10
11
# File 'lib/e_plat/mapping/virtual_collection/shopify/product/variant/option_value.rb', line 9

def resource
  @resource
end

Instance Method Details

#native_attribute_aliases(i) ⇒ Object



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
# File 'lib/e_plat/mapping/virtual_collection/shopify/product/variant/option_value.rb', line 27

def native_attribute_aliases(i)
    [                                
        {
            alias_attribute: {
                native_key: "[selected_options][#{i}][option_value][id]",
                e_plat_key: "id",
                virtual_collection: true,
                custom_e_plat_getter: '-> { _1&.split("/")&.last }',
                custom_native_setter: '-> { "gid://shopify/ProductOptionValue/#{_1}" }'
            }
        },
        {
            alias_attribute: {
                native_key: "[selected_options][#{i}][name]",
                e_plat_key: "name",
                virtual_collection: true
            }
        },
        {
            alias_attribute: {
                native_key: "[selected_options][#{i}][value]",
                e_plat_key: "value",
                virtual_collection: true
            }
        }
    ]
end