Class: ItemBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/item_builder.rb,
lib/item_builder/modes.rb,
lib/item_builder/version.rb,
lib/item_builder/modes/price/base.rb,
lib/item_builder/modes/update/base.rb,
lib/item_builder/modes/base_service.rb,
lib/item_builder/modes/price_service.rb,
lib/item_builder/modes/quantity/base.rb,
lib/item_builder/get_quantity_service.rb,
lib/item_builder/modes/active_service.rb,
lib/item_builder/modes/simple_service.rb,
lib/item_builder/modes/update_service.rb,
lib/item_builder/modes/price/jd_service.rb,
lib/item_builder/modes/quantity_service.rb,
lib/item_builder/modes/update/jd_service.rb,
lib/item_builder/modes/price/blibli_service.rb,
lib/item_builder/modes/price/zalora_service.rb,
lib/item_builder/modes/price/shopify_service.rb,
lib/item_builder/modes/update/blibli_service.rb,
lib/item_builder/modes/update/lazada_service.rb,
lib/item_builder/modes/update/zalora_service.rb,
lib/item_builder/modes/update/shopify_service.rb,
lib/item_builder/modes/price/bukalapak_service.rb,
lib/item_builder/modes/price/sale_price_policy.rb,
lib/item_builder/modes/quantity/lazada_service.rb,
lib/item_builder/modes/quantity/zalora_service.rb,
lib/item_builder/modes/update/bukalapak_service.rb,
lib/item_builder/modes/update/tokopedia_service.rb

Defined Under Namespace

Modules: Modes Classes: GetQuantityService

Constant Summary collapse

VERSION =
'0.1.21'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listing_ids, mode) ⇒ ItemBuilder

Returns a new instance of ItemBuilder.



23
24
25
26
# File 'lib/item_builder.rb', line 23

def initialize(listing_ids, mode)
  @listing_ids = listing_ids
  @mode = mode
end

Instance Attribute Details

#listing_idsObject (readonly)

Returns the value of attribute listing_ids.



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

def listing_ids
  @listing_ids
end

#listingsObject (readonly)

Returns the value of attribute listings.



17
18
19
# File 'lib/item_builder.rb', line 17

def listings
  @listings
end

#modeObject (readonly)

Returns the value of attribute mode.



18
19
20
# File 'lib/item_builder.rb', line 18

def mode
  @mode
end

#variant_idsObject (readonly)

Returns the value of attribute variant_ids.



21
22
23
# File 'lib/item_builder.rb', line 21

def variant_ids
  @variant_ids
end

#variantsObject (readonly)

Returns the value of attribute variants.



20
21
22
# File 'lib/item_builder.rb', line 20

def variants
  @variants
end

#wh_spacesObject (readonly)

Returns the value of attribute wh_spaces.



19
20
21
# File 'lib/item_builder.rb', line 19

def wh_spaces
  @wh_spaces
end

Class Method Details

.build(listing_ids, mode) ⇒ Object



12
13
14
# File 'lib/item_builder.rb', line 12

def self.build(listing_ids, mode)
  new(listing_ids, mode).mode_check
end

Instance Method Details

#bundle_idsObject



78
79
80
# File 'lib/item_builder.rb', line 78

def bundle_ids
  @bundle_ids ||= bundles.map(&:id).uniq
end

#bundlesObject



82
83
84
# File 'lib/item_builder.rb', line 82

def bundles
  @bundles ||= Bundle.where(variant_id: variant_ids).group(:variant_id)
end

#defaultObject



51
52
53
54
55
# File 'lib/item_builder.rb', line 51

def default
  listings.map do |listing|
    modes[mode].new(listing: listing).perform
  end
end

#existing_alloc_stocksObject



57
58
59
60
61
# File 'lib/item_builder.rb', line 57

def existing_alloc_stocks
  @existing_alloc_stocks ||= VariantListingStockAllocation.where(
    variant_association_id: vl_ids
  ).where('ADDTIME(end_at, "07:00") >= NOW()')
end

#item_bundle_variantsObject



71
72
73
74
75
76
# File 'lib/item_builder.rb', line 71

def item_bundle_variants
  @item_bundle_variants ||= BundleVariant.where(
    bundle_id: bundle_ids,
    channel_id: listings[0].channel_id
  )
end

#mode_checkObject



28
29
30
31
32
33
34
# File 'lib/item_builder.rb', line 28

def mode_check
  if mode == :quantity
    quantity_mode
  else
    default
  end
end

#modesObject



108
109
110
111
112
113
114
115
116
# File 'lib/item_builder.rb', line 108

def modes
  {
    price: ItemBuilder::Modes::PriceService,
    quantity: ItemBuilder::Modes::QuantityService,
    simple: ItemBuilder::Modes::SimpleService,
    active: ItemBuilder::Modes::ActiveService,
    update: ItemBuilder::Modes::UpdateService
  }
end

#qty_params(listing) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/item_builder.rb', line 42

def qty_params(listing)
  {
    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
  }
end

#quantity_modeObject



36
37
38
39
40
# File 'lib/item_builder.rb', line 36

def quantity_mode
  listings.map do |listing|
    modes[mode].new(qty_params(listing)).perform
  end
end

#stock_allocsObject



86
87
88
89
90
# File 'lib/item_builder.rb', line 86

def stock_allocs
  @stock_allocs ||= VariantListingStockAllocation.where(
    variant_association_id: vl_ids
  )
end

#variant_listingsObject



67
68
69
# File 'lib/item_builder.rb', line 67

def variant_listings
  @variant_listings ||= VariantListing.where(variant_id: variant_ids)
end

#vl_idsObject



63
64
65
# File 'lib/item_builder.rb', line 63

def vl_ids
  @vl_ids ||= variant_listings.map(&:id).uniq
end