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/create/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/create_service.rb,
lib/item_builder_mwh/modes/simple_service.rb,
lib/item_builder_mwh/modes/map_create/base.rb,
lib/item_builder_mwh/modes/price/jd_service.rb,
lib/item_builder_mwh/modes/quantity_service.rb,
lib/item_builder_mwh/lazada_quantity_service.rb,
lib/item_builder_mwh/modes/simple/jd_service.rb,
lib/item_builder_mwh/zalora_quantity_service.rb,
lib/item_builder_mwh/modes/map_create_service.rb,
lib/item_builder_mwh/shopify_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/create/shopee_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/create/tokopedia_service.rb,
lib/item_builder_mwh/modes/precondition_create/base.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,
lib/item_builder_mwh/modes/map_create/shopee_service.rb,
lib/item_builder_mwh/modes/precondition_create_service.rb,
lib/item_builder_mwh/modes/map_create/tokopedia_service.rb,
lib/item_builder_mwh/modes/precondition_create/shopee_service.rb
Defined Under Namespace
Modules: Modes
Classes: GetQuantityService, LazadaQuantityService, ShopifyQuantityService, ZaloraQuantityService, ZilingoQuantityService
Constant Summary
collapse
- VERSION =
'0.1.59'
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.
25
26
27
28
|
# File 'lib/item_builder_mwh.rb', line 25
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.
19
20
21
|
# File 'lib/item_builder_mwh.rb', line 19
def listing_ids
@listing_ids
end
|
#listings ⇒ Object
Returns the value of attribute listings.
20
21
22
|
# File 'lib/item_builder_mwh.rb', line 20
def listings
@listings
end
|
#mode ⇒ Object
Returns the value of attribute mode.
21
22
23
|
# File 'lib/item_builder_mwh.rb', line 21
def mode
@mode
end
|
#variant_ids ⇒ Object
Returns the value of attribute variant_ids.
24
25
26
|
# File 'lib/item_builder_mwh.rb', line 24
def variant_ids
@variant_ids
end
|
#variants ⇒ Object
Returns the value of attribute variants.
23
24
25
|
# File 'lib/item_builder_mwh.rb', line 23
def variants
@variants
end
|
#wh_spaces ⇒ Object
Returns the value of attribute wh_spaces.
22
23
24
|
# File 'lib/item_builder_mwh.rb', line 22
def wh_spaces
@wh_spaces
end
|
Class Method Details
.build(listing_ids, mode) ⇒ Object
30
31
32
|
# File 'lib/item_builder_mwh.rb', line 30
def self.build(listing_ids, mode)
new(listing_ids, mode).mode_check
end
|
Instance Method Details
#account_id ⇒ Object
228
229
230
|
# File 'lib/item_builder_mwh.rb', line 228
def account_id
account_id ||= listings[0].profile_channel_association_id
end
|
#bundle_ids ⇒ Object
137
138
139
|
# File 'lib/item_builder_mwh.rb', line 137
def bundle_ids
@bundle_ids ||= bundles.map(&:id).uniq
end
|
#bundles ⇒ Object
141
142
143
|
# File 'lib/item_builder_mwh.rb', line 141
def bundles
@bundles ||= Bundle.where(variant_id: variant_ids).group(:variant_id)
end
|
#channel_association_ids ⇒ Object
167
168
169
|
# File 'lib/item_builder_mwh.rb', line 167
def channel_association_ids
@listing_item_ids ||= listings.map(&:channel_association_id).uniq
end
|
#create_mode ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/item_builder_mwh.rb', line 98
def create_mode
item_listings.map do |listing|
param =
if listing.channel_id == 12
qty_simple_params(listing)
.merge(shipping_providers: shipping_providers)
else
qty_simple_params(listing)
end
modes[mode].new(param.merge(mode: mode)).perform
end
end
|
#default ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/item_builder_mwh.rb', line 70
def default
datas =
if mode == :precondition_create
VariantListing.where(
channel_association_id: channel_association_ids,
profile_channel_association_id: account_id
)
else
listings
end
datas.map do |listing|
if listing.local_id.present?
modes[mode].new(listing: listing).perform
end
end
end
|
#existing_alloc_stocks ⇒ Object
117
118
119
120
121
|
# File 'lib/item_builder_mwh.rb', line 117
def existing_alloc_stocks
@existing_alloc_stocks ||= VariantListingStockAllocation.where(
variant_association_id: vl_ids
).where('end_at >= NOW()')
end
|
#item_bundle_variants ⇒ Object
131
132
133
134
135
|
# File 'lib/item_builder_mwh.rb', line 131
def item_bundle_variants
@item_bundle_variants ||= BundleVariant.where(
bundle_id: bundle_ids
)
end
|
#item_listings ⇒ Object
232
233
234
235
236
|
# File 'lib/item_builder_mwh.rb', line 232
def item_listings
@item_listings ||= VariantListing.joins(:variant).includes(:item_listing).where(
id: listing_ids
).group(:channel_association_id)
end
|
#lazada_quantity ⇒ Object
189
190
191
|
# File 'lib/item_builder_mwh.rb', line 189
def lazada_quantity
@lazada_quantity ||= nil
end
|
#map_create_mode ⇒ Object
111
112
113
114
115
|
# File 'lib/item_builder_mwh.rb', line 111
def map_create_mode
listings.map do |listing|
modes[mode].new(qty_simple_params(listing)).perform
end
end
|
#mode_check ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/item_builder_mwh.rb', line 34
def mode_check
if mode == :quantity || mode == :simple || mode == :active
quantity_simple_mode
elsif mode == :create || mode == :item_create || mode == :precondition_create || mode == :precondition_update || mode == :update
create_mode
elsif mode == :map_create
map_create_mode
else
default
end
end
|
#modes ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/item_builder_mwh.rb', line 209
def modes
{
price: ItemBuilderMwh::Modes::PriceService,
quantity: ItemBuilderMwh::Modes::QuantityService,
simple: ItemBuilderMwh::Modes::SimpleService,
active: ItemBuilderMwh::Modes::ActiveService,
create: ItemBuilderMwh::Modes::CreateService,
map_create: ItemBuilderMwh::Modes::MapCreateService,
precondition_create: ItemBuilderMwh::Modes::CreateService,
precondition_update: ItemBuilderMwh::Modes::CreateService,
item_create: ItemBuilderMwh::Modes::CreateService,
update: ItemBuilderMwh::Modes::CreateService,
}
end
|
#order_host ⇒ Object
193
194
195
196
|
# File 'lib/item_builder_mwh.rb', line 193
def order_host
url = ENV['ORDERS_URL'] || 'orders.forstok.com'
url + '/api/v3/item_line/reserved_stock'
end
|
#qty_simple_params(listing) ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/item_builder_mwh.rb', line 88
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/item_builder_mwh.rb', line 46
def quantity_simple_mode
listings.map do |listing|
next unless listing.local_id.present?
param =
if listing.channel_id == 18
qty_simple_params(listing)
.merge(zilingo_quantity: zilingo_quantity)
elsif listing.channel_id == 13
qty_simple_params(listing)
.merge(zalora_reserved_stock: zalora_reserved_stock)
elsif listing.channel_id == 2
qty_simple_params(listing)
.merge({shopify_inventory_location: shopify_inventory_location})
elsif listing.channel_id == 3
qty_simple_params(listing)
.merge({lazada_quantity: lazada_quantity})
else
qty_simple_params(listing)
end
modes[mode].new(param).perform
end.compact
end
|
#reserved_params ⇒ Object
198
199
200
201
|
# File 'lib/item_builder_mwh.rb', line 198
def reserved_params
"account_id=#{account_id}
&item_variant_ids=#{variant_ids.join(',')}"
end
|
#reserved_stocks ⇒ Object
203
204
205
206
207
|
# File 'lib/item_builder_mwh.rb', line 203
def reserved_stocks
@reserved_stocks ||= JSON.parse(RestClient.get(
"#{order_host}?#{reserved_params}"
).body) if [3,13].include?(listings[0].channel_id)
end
|
#shipping_providers ⇒ Object
238
239
240
241
242
|
# File 'lib/item_builder_mwh.rb', line 238
def shipping_providers
@shipping_providers ||= ShopeeShippingProvider.where(
enabled: true, mask_channel_id: 0, account_id: account_id
)
end
|
#shopify_inventory_location ⇒ Object
183
184
185
186
187
|
# File 'lib/item_builder_mwh.rb', line 183
def shopify_inventory_location
@shopify_inventory_location ||= ItemBuilderMwh::ShopifyQuantityService.new(
listings: listings, skus: skus
).perform
end
|
#skus ⇒ Object
163
164
165
|
# File 'lib/item_builder_mwh.rb', line 163
def skus
@skus ||= listings.map(&:local_id).uniq
end
|
#stock_allocs ⇒ Object
145
146
147
148
149
|
# File 'lib/item_builder_mwh.rb', line 145
def stock_allocs
@stock_allocs ||= VariantListingStockAllocation.where(
variant_association_id: vl_ids
)
end
|
#variant_listings ⇒ Object
127
128
129
|
# File 'lib/item_builder_mwh.rb', line 127
def variant_listings
@variant_listings ||= VariantListing.where(variant_id: variant_ids)
end
|
#vl_ids ⇒ Object
123
124
125
|
# File 'lib/item_builder_mwh.rb', line 123
def vl_ids
@vl_ids ||= variant_listings.map(&:id).uniq
end
|
#zalora_reserved_stock ⇒ Object
177
178
179
180
181
|
# File 'lib/item_builder_mwh.rb', line 177
def zalora_reserved_stock
@zalora_reserved_stock ||= ItemBuilderMwh::ZaloraQuantityService.new(
listings: listings, skus: skus
).perform
end
|
#zilingo_quantity ⇒ Object
171
172
173
174
175
|
# File 'lib/item_builder_mwh.rb', line 171
def zilingo_quantity
@zilingo_quantity ||= ItemBuilderMwh::ZilingoQuantityService.new(
listings: listings, skus: skus
).perform
end
|