Class: EPlat::Mapping::Woocommerce::V3::Shop

Inherits:
Base
  • Object
show all
Defined in:
lib/e_plat/mapping/woocommerce/v_3/shop.rb

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, #platform, #protected_attributes_rename_on_initialize, #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



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
# File 'lib/e_plat/mapping/woocommerce/v_3/shop.rb', line 27

def native_attribute_aliases
  super.concat([
    {
      alias_attribute: {
        native_key: "woocommerce_store_address", 
        e_plat_key: "address1",
        custom_e_plat_getter: "-> (value) { 
          value&.value
        }"
      }
    },
    {
      alias_attribute: {
        native_key: "woocommerce_store_address_2", 
        e_plat_key: "address2",
        custom_e_plat_getter: "-> (value) { 
          value&.value
        }"
      }
    },
    {
      alias_attribute: {
        native_key: "woocommerce_store_city", 
        e_plat_key: "city",
        custom_e_plat_getter: "-> (value) { 
          value&.value
        }"
      }
    },
    {
      alias_attribute: {
        native_key: "woocommerce_store_postcode", 
        e_plat_key: "zip",
        custom_e_plat_getter: "-> (value) { 
          value&.value
        }"
      }
    },
    {
      alias_attribute: {
        native_key: "woocommerce_default_country", 
        e_plat_key: "country",
        custom_e_plat_getter: "-> (value) { 
          if value.is_a?(Hash) && value['value']
            # Extract just the country code part, safely handling any format
            country_code = value['value'].to_s.split(':').first.to_s.gsub(/[^A-Za-z0-9]/, '')
            country_code
          else
            value.to_s.split(':').first.to_s.gsub(/[^A-Za-z0-9]/, '')
          end
        }"
      }
    },
    {
      alias_attribute: {
        native_key: "woocommerce_default_country", 
        e_plat_key: "country_code",
        custom_e_plat_getter: "-> (value) { 
          # e.g. US:CA => US
          value.default.split(':').first
        }"
      }
    },
    {
      alias_attribute: {
        native_key: "woocommerce_default_country", 
        e_plat_key: "province",
        custom_e_plat_getter: "-> (value) { 
          # e.g. US:CA => CA
          value.default.split(':').last
        }"
      }
    },
    {
      alias_attribute: {
        native_key: "woocommerce_currency", 
        e_plat_key: "currency",
        custom_e_plat_getter: "-> (value) { 
          value&.default
        }"
      }
    },
    {
      alias_attribute: {
        native_key: "woocommerce_weight_unit", 
        e_plat_key: "weight_unit",
        custom_e_plat_getter: "-> (value) { 
          lazy_load_weight_unit
        }"
      }
    },
    # Client store_url as domain
    {
      existing_entry: {
        native_key: "domain", 
        e_plat_key: "domain",
        custom_e_plat_getter: "-> (value) { 
          client&.store_url
        }"
      }
    },
    # Set has_storefront to true for WooCommerce
    {
      existing_entry: {
        native_key: "has_storefront", 
        e_plat_key: "has_storefront",
        custom_e_plat_getter: "-> (value) { true }"
      }
    }
  ])
end

#native_attributesObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/e_plat/mapping/woocommerce/v_3/shop.rb', line 14

def native_attributes
  super.concat([
    "domain", #fake, as we use client.store_url. This whole class is read_only really
    "woocommerce_store_address",
    "woocommerce_store_address_2",
    "woocommerce_store_city",
    "woocommerce_store_postcode",
    "woocommerce_default_country",
    "woocommerce_currency",
    "woocommerce_weight_unit" # lazy loaded from settings/products instead of settings/general
  ])
end

#native_top_keyObject

WooCommerce uses the ‘/settings/general` endpoint to get the shop details we lazy load the weight unit from `/settings/products/woocommerce_weight_unit` when needed



10
11
12
# File 'lib/e_plat/mapping/woocommerce/v_3/shop.rb', line 10

def native_top_key
  :itself # The response is an array, not a nested object with a specific top key
end