Class: EPlat::Woocommerce::Shop

Inherits:
Shop
  • Object
show all
Defined in:
lib/e_plat/resource/platform_specific/woocommerce/shop.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_single(scope, options) ⇒ Object

Custom find_single for WooCommerce, since it uses settings/general endpoint



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/e_plat/resource/platform_specific/woocommerce/shop.rb', line 5

def find_single(scope, options)
  prefix_options, query_options = split_options(options[:params])
  path = "#{client.url_prefix}settings/general"
  
  # The response is an array, so we need to wrap it in a hash with a top-level key
  response = connection.get(path, client.headers)
  response_data = format.decode(response.body)
  
  # Process response data to create a hash with expected structure
  response_hash = {}
  if response_data.is_a?(Array)
    response_data.each do |setting|
      key = setting["id"]
      response_hash[key] = setting if key
    end
  end
  
  instantiate_record(response_hash, prefix_options)
end

Instance Method Details

#lazy_load_weight_unitObject



26
27
28
29
30
31
32
33
34
# File 'lib/e_plat/resource/platform_specific/woocommerce/shop.rb', line 26

def lazy_load_weight_unit
  return @lazy_load_weight_unit if @lazy_load_weight_unit
  
  path = "#{client.url_prefix}settings/products/woocommerce_weight_unit"
  response = connection.get(path, client.headers)
  response_data = JSON.parse(response.body)
  
  @lazy_load_weight_unit = response_data["value"] || response_data["default"]
end