Class: ItemBuilderMwh
- Inherits:
-
Object
show all
- Defined in:
- lib/item_builder_mwh.rb,
lib/item_builder_mwh/modes.rb,
lib/item_builder_mwh/version.rb,
lib/item_builder_mwh/modes/price/base.rb,
lib/item_builder_mwh/modes/simple/base.rb,
lib/item_builder_mwh/modes/base_service.rb,
lib/item_builder_mwh/modes/price_service.rb,
lib/item_builder_mwh/modes/quantity/base.rb,
lib/item_builder_mwh/get_quantity_service.rb,
lib/item_builder_mwh/modes/active_service.rb,
lib/item_builder_mwh/modes/simple_service.rb,
lib/item_builder_mwh/modes/price/jd_service.rb,
lib/item_builder_mwh/modes/quantity_service.rb,
lib/item_builder_mwh/modes/simple/jd_service.rb,
lib/item_builder_mwh/zalora_quantity_service.rb,
lib/item_builder_mwh/zilingo_quantity_service.rb,
lib/item_builder_mwh/modes/price/blibli_service.rb,
lib/item_builder_mwh/modes/price/zalora_service.rb,
lib/item_builder_mwh/modes/price/shopify_service.rb,
lib/item_builder_mwh/modes/simple/blibli_service.rb,
lib/item_builder_mwh/modes/simple/lazada_service.rb,
lib/item_builder_mwh/modes/simple/shopee_service.rb,
lib/item_builder_mwh/modes/simple/zalora_service.rb,
lib/item_builder_mwh/modes/simple/shopify_service.rb,
lib/item_builder_mwh/modes/price/bukalapak_service.rb,
lib/item_builder_mwh/modes/price/sale_price_policy.rb,
lib/item_builder_mwh/modes/quantity/lazada_service.rb,
lib/item_builder_mwh/modes/quantity/zalora_service.rb,
lib/item_builder_mwh/modes/quantity/zilingo_service.rb,
lib/item_builder_mwh/modes/simple/bukalapak_service.rb,
lib/item_builder_mwh/modes/simple/sale_price_policy.rb
Defined Under Namespace
Modules: Modes
Classes: GetQuantityService, ZaloraQuantityService, ZilingoQuantityService
Constant Summary
collapse
- VERSION =
'0.1.16'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(listing_ids, mode) ⇒ ItemBuilderMwh
Returns a new instance of ItemBuilderMwh.
20
21
22
23
|
# File 'lib/item_builder_mwh.rb', line 20
def initialize(listing_ids, mode)
@listing_ids = listing_ids
@mode = mode
end
|
Instance Attribute Details
#listing_ids ⇒ Object
Returns the value of attribute listing_ids.
14
15
16
|
# File 'lib/item_builder_mwh.rb', line 14
def listing_ids
@listing_ids
end
|
#listings ⇒ Object
Returns the value of attribute listings.
15
16
17
|
# File 'lib/item_builder_mwh.rb', line 15
def listings
@listings
end
|
#mode ⇒ Object
Returns the value of attribute mode.
16
17
18
|
# File 'lib/item_builder_mwh.rb', line 16
def mode
@mode
end
|
#variant_ids ⇒ Object
Returns the value of attribute variant_ids.
19
20
21
|
# File 'lib/item_builder_mwh.rb', line 19
def variant_ids
@variant_ids
end
|
#variants ⇒ Object
Returns the value of attribute variants.
18
19
20
|
# File 'lib/item_builder_mwh.rb', line 18
def variants
@variants
end
|
#wh_spaces ⇒ Object
Returns the value of attribute wh_spaces.
17
18
19
|
# File 'lib/item_builder_mwh.rb', line 17
def wh_spaces
@wh_spaces
end
|
Class Method Details
.build(listing_ids, mode) ⇒ Object
25
26
27
|
# File 'lib/item_builder_mwh.rb', line 25
def self.build(listing_ids, mode)
new(listing_ids, mode).mode_check
end
|
Instance Method Details
#bundle_ids ⇒ Object
91
92
93
|
# File 'lib/item_builder_mwh.rb', line 91
def bundle_ids
@bundle_ids ||= bundles.map(&:id).uniq
end
|
#bundles ⇒ Object
95
96
97
|
# File 'lib/item_builder_mwh.rb', line 95
def bundles
@bundles ||= Bundle.where(variant_id: variant_ids).group(:variant_id)
end
|
#default ⇒ Object
55
56
57
58
59
|
# File 'lib/item_builder_mwh.rb', line 55
def default
listings.map do |listing|
modes[mode].new(listing: listing).perform
end
end
|
#existing_alloc_stocks ⇒ Object
71
72
73
74
75
|
# File 'lib/item_builder_mwh.rb', line 71
def existing_alloc_stocks
@existing_alloc_stocks ||= VariantListingStockAllocation.where(
variant_association_id: vl_ids
).where('ADDTIME(end_at, "07:00") >= NOW()')
end
|
#item_bundle_variants ⇒ Object
85
86
87
88
89
|
# File 'lib/item_builder_mwh.rb', line 85
def item_bundle_variants
@item_bundle_variants ||= BundleVariant.where(
bundle_id: bundle_ids
)
end
|
#mode_check ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/item_builder_mwh.rb', line 29
def mode_check
if mode == :quantity || mode == :simple
quantity_simple_mode
else
default
end
end
|
#modes ⇒ Object
149
150
151
152
153
154
155
156
|
# File 'lib/item_builder_mwh.rb', line 149
def modes
{
price: ItemBuilderMwh::Modes::PriceService,
quantity: ItemBuilderMwh::Modes::QuantityService,
simple: ItemBuilderMwh::Modes::SimpleService,
active: ItemBuilderMwh::Modes::ActiveService
}
end
|
#order_host ⇒ Object
133
134
135
136
|
# File 'lib/item_builder_mwh.rb', line 133
def order_host
url = ENV['ORDERS_URL'] || 'orders.forstok.com'
url + '/api/v3/item_line/reserved_stock'
end
|
#qty_simple_params(listing) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/item_builder_mwh.rb', line 61
def qty_simple_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,
reserved_stocks: reserved_stocks
}
end
|
#quantity_simple_mode ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/item_builder_mwh.rb', line 37
def quantity_simple_mode
listings.map do |listing|
if listing.channel_id == 18
new_param = qty_simple_params(listing)
.merge({zilingo_delta_quantity: zilingo_delta_quantity})
modes[mode].new(new_param).perform
elsif listing.channel_id == 13
new_param = qty_simple_params(listing)
.merge({zalora_reserved_stock: zalora_reserved_stock})
modes[mode].new(new_param).perform
else
modes[mode].new(qty_simple_params(listing)).perform
end
end
end
|
#reserved_params ⇒ Object
138
139
140
141
|
# File 'lib/item_builder_mwh.rb', line 138
def reserved_params
"account_id=#{listings[0].profile_channel_association_id}
&item_variant_ids=#{variant_ids.join(',')}"
end
|
#reserved_stocks ⇒ Object
143
144
145
146
147
|
# File 'lib/item_builder_mwh.rb', line 143
def reserved_stocks
@reserved_stocks ||= JSON.parse(RestClient.get(
"#{order_host}?#{reserved_params}"
).body) if [3,13].include?(listings[0].channel_id)
end
|
#skus ⇒ Object
117
118
119
|
# File 'lib/item_builder_mwh.rb', line 117
def skus
@skus ||= listings.map(&:local_id).uniq
end
|
#stock_allocs ⇒ Object
99
100
101
102
103
|
# File 'lib/item_builder_mwh.rb', line 99
def stock_allocs
@stock_allocs ||= VariantListingStockAllocation.where(
variant_association_id: vl_ids
)
end
|
#variant_listings ⇒ Object
81
82
83
|
# File 'lib/item_builder_mwh.rb', line 81
def variant_listings
@variant_listings ||= VariantListing.where(variant_id: variant_ids)
end
|
#vl_ids ⇒ Object
77
78
79
|
# File 'lib/item_builder_mwh.rb', line 77
def vl_ids
@vl_ids ||= variant_listings.map(&:id).uniq
end
|
#zalora_reserved_stock ⇒ Object
127
128
129
130
131
|
# File 'lib/item_builder_mwh.rb', line 127
def zalora_reserved_stock
@zalora_reserved_stock ||= ItemBuilderMwh::ZaloraQuantityService.new(
listings: listings, skus: skus
).perform
end
|
#zilingo_delta_quantity ⇒ Object
121
122
123
124
125
|
# File 'lib/item_builder_mwh.rb', line 121
def zilingo_delta_quantity
@zilingo_delta_quantity ||= ItemBuilderMwh::ZilingoQuantityService.new(
listings: listings, skus: skus
).perform
end
|