Class: ItemBuilder::Modes::CreateService

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

Constant Summary collapse

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, #stock_alloc, #variant, #warehouse

Instance Method Details

#channel_nameObject



35
36
37
# File 'lib/item_builder/modes/create_service.rb', line 35

def channel_name
  CREATE_CHANNEL[listing.channel_id].to_s
end

#create_channelObject



29
30
31
32
33
# File 'lib/item_builder/modes/create_service.rb', line 29

def create_channel
  class_name = "ItemBuilder::Modes::Create::#{channel_name}Service"
  create_channel_service = class_name.constantize
  create_channel_service.new(item_listing, shipping_providers).perform
end

#item_listingObject



39
40
41
# File 'lib/item_builder/modes/create_service.rb', line 39

def item_listing
  @item_listing ||= listing.item_listing
end

#listingsObject



43
44
45
46
47
# File 'lib/item_builder/modes/create_service.rb', line 43

def listings
  @listings ||= item_listing.variant_listings.where(
    profile_channel_association_id: listing.profile_channel_association_id
  )
end

#performObject



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

def perform
  to_h.merge(create_channel)
end

#to_hObject



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

def to_h
  {
    item: {
      id: item_listing.id,
      variations: ::ItemBuilder.build(listings.map(&:id), :map_create)
    }
  }
end