Class: ItemBuilder::Modes::MapCreateService

Inherits:
Object
  • Object
show all
Includes:
ItemBuilder::Modes
Defined in:
lib/item_builder/modes/map_create_service.rb

Constant Summary collapse

MAP_CREATE_CHANNEL =
{}.tap do |hash|
  hash[12]      = :Shopee
  hash[15]      = :Tokopedia
end.freeze

Instance Attribute Summary

Attributes included from ItemBuilder::Modes

#bundles, #existing_alloc_stocks, #item_bundle_variants, #lazada_quantity, #listing, #shipping_providers, #shopify_inventory_location, #stock_allocs, #variant_listings, #variants, #wh_id, #wh_spaces, #zalora_reserved_stock, #zilingo_quantity

Instance Method Summary collapse

Methods included from ItemBuilder::Modes

#base, #bundle, #bundle_variants, #existing_allocated_stock, #initialize, #listings, #stock_alloc, #variant, #warehouse

Instance Method Details

#channel_nameObject



66
67
68
# File 'lib/item_builder/modes/map_create_service.rb', line 66

def channel_name
  MAP_CREATE_CHANNEL[listing.channel_id].to_s
end

#imagesObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/item_builder/modes/map_create_service.rb', line 49

def images
  listing.item_listing_variant_images.map do |img|
    {
      id: img.id,
      local_id: img.local_id,
      local_url: img.local_url,
      url: img.image.image.url(:xlarge, timestamp: false)
    }
  end
end

#map_create_channelObject



60
61
62
63
64
# File 'lib/item_builder/modes/map_create_service.rb', line 60

def map_create_channel
  class_name = "ItemBuilder::Modes::MapCreate::#{channel_name}Service"
  create_channel_service = class_name.constantize
  create_channel_service.new(listing).perform
end

#performObject



16
17
18
# File 'lib/item_builder/modes/map_create_service.rb', line 16

def perform
  base.merge(simple(listing)).merge(to_h).merge(map_create_channel)
end

#simple(listing) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/item_builder/modes/map_create_service.rb', line 20

def simple(listing)
  SimpleService.new(
    listing: listing, wh_spaces: wh_spaces, variants: variants,
    stock_allocs: stock_allocs, variant_listings: variant_listings,
    bundles: bundles, item_bundle_variants: item_bundle_variants,
    existing_alloc_stocks: existing_alloc_stocks,
    zilingo_quantity: zilingo_quantity,
    zalora_reserved_stock: zalora_reserved_stock
  ).to_h
end

#to_hObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/item_builder/modes/map_create_service.rb', line 31

def to_h
  {
    name: listing.name,
    description: listing.description,
    weight: listing.package_weight,
    length: listing.package_length,
    width: listing.package_width,
    height: listing.package_height,
    condition: listing.new_condition,
    option_name: listing.option_name,
    option_value: listing.option_value,
    option2_name: listing.option2_name,
    option2_value: listing.option2_value,
    internal_data: listing.internal_data,
    images: images
  }
end