Class: ItemBuilder::Modes::PriceService

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

Constant Summary collapse

PRICE_CHANNEL =
{}.tap do |hash|
  hash[2]       = :Shopify
  hash[9]       = :Blibli
  hash[11]      = :Bukalapak
  hash[13]      = :Zalora
  hash[16]      = :Jd
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



49
50
51
# File 'lib/item_builder/modes/price_service.rb', line 49

def channel_name
  PRICE_CHANNEL[listing.channel_id].to_s
end

#performObject



22
23
24
# File 'lib/item_builder/modes/price_service.rb', line 22

def perform
  to_h.merge(base)
end

#priceObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/item_builder/modes/price_service.rb', line 30

def price
  if channel_name.empty?
    {
      price: listing.price,
      sale_price: listing.sale_price,
      sale_start_at: listing.sale_start_at,
      sale_end_at: listing.sale_end_at
    }
  else
    price_channel
  end
end

#price_channelObject



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

def price_channel
  class_name = "ItemBuilder::Modes::Price::#{channel_name}Service"
  price_channel_service = class_name.constantize
  price_channel_service.new(listing).perform
end

#to_hObject



26
27
28
# File 'lib/item_builder/modes/price_service.rb', line 26

def to_h
  price
end