Class: ItemBuilder::Modes::QuantityService
- Inherits:
-
Object
- Object
- ItemBuilder::Modes::QuantityService
show all
- Includes:
- ItemBuilder::Modes
- Defined in:
- lib/item_builder/modes/quantity_service.rb
Constant Summary
collapse
- QUANTITY_CHANNEL =
{}.tap do |hash|
hash[2] = :Shopify
hash[3] = :Lazada
hash[13] = :Zalora
hash[18] = :Zilingo
end.freeze
Instance Attribute Summary
#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
#base, #bundle, #bundle_variants, #existing_allocated_stock, #initialize, #listings, #stock_alloc, #variant, #warehouse
Instance Method Details
#available_quantity ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/item_builder/modes/quantity_service.rb', line 76
def available_quantity
ItemBuilder::GetQuantityService.new(
listing: listing, variant: variant,
wh_sp: warehouse, stock_alloc: stock_alloc,
bundle_variants: bundle_variants,
existing_allocated_stock: existing_allocated_stock
).perform
end
|
#channel_name ⇒ Object
56
57
58
|
# File 'lib/item_builder/modes/quantity_service.rb', line 56
def channel_name
QUANTITY_CHANNEL[listing.channel_id].to_s
end
|
#local_qty ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/item_builder/modes/quantity_service.rb', line 60
def local_qty
if channel_name == 'Zilingo'
return 0 if zilingo_quantity.blank?
zilingo_quantity[listing.local_id].to_i
elsif channel_name == 'Zalora'
return 0 if zalora_reserved_stock.blank?
zalora_reserved_stock[listing.local_id].to_i
else
return 0 if lazada_quantity.blank?
lazada_quantity[listing.local_id].to_i
end
end
|
22
23
24
25
26
27
28
29
30
|
# File 'lib/item_builder/modes/quantity_service.rb', line 22
def perform
if channel_name == "Shopify"
dataSIL = shopify_inventory_location[listing.local_id]
base.merge(to_h, dataSIL) if dataSIL.present?
else
to_h.merge(base)
end
end
|
#qty ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/item_builder/modes/quantity_service.rb', line 42
def qty
if channel_name.empty? || channel_name == "Shopify"
available_quantity
else
qty_channel
end
end
|
#qty_channel ⇒ Object
50
51
52
53
54
|
# File 'lib/item_builder/modes/quantity_service.rb', line 50
def qty_channel
class_name = "ItemBuilder::Modes::Quantity::#{channel_name}Service"
qty_channel_service = class_name.constantize
qty_channel_service.new(listing, available_quantity, local_qty.to_i).perform
end
|
#to_h ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/item_builder/modes/quantity_service.rb', line 32
def to_h
if channel_name == "Zilingo"
{ quantity: qty }
else
{
quantity: [qty, 0].sort[1]
}
end
end
|