Module: ItemBuilderMwh::Modes
- Included in:
- ActiveService, CreateService, MapCreateService, PreconditionCreateService, PriceService, QuantityService, Simple::SalePricePolicy, SimpleService
- Defined in:
- lib/item_builder_mwh/modes.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/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/modes/simple/jd_service.rb,
lib/item_builder_mwh/modes/map_create_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: Create, MapCreate, PreconditionCreate, Price, Quantity, Simple
Classes: ActiveService, BaseService, CreateService, MapCreateService, PreconditionCreateService, PriceService, QuantityService, SimpleService
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#bundles ⇒ Object
Returns the value of attribute bundles.
14
15
16
|
# File 'lib/item_builder_mwh/modes.rb', line 14
def bundles
@bundles
end
|
#existing_alloc_stocks ⇒ Object
Returns the value of attribute existing_alloc_stocks.
16
17
18
|
# File 'lib/item_builder_mwh/modes.rb', line 16
def existing_alloc_stocks
@existing_alloc_stocks
end
|
#item_bundle_variants ⇒ Object
Returns the value of attribute item_bundle_variants.
15
16
17
|
# File 'lib/item_builder_mwh/modes.rb', line 15
def item_bundle_variants
@item_bundle_variants
end
|
#lazada_quantity ⇒ Object
Returns the value of attribute lazada_quantity.
20
21
22
|
# File 'lib/item_builder_mwh/modes.rb', line 20
def lazada_quantity
@lazada_quantity
end
|
#listing ⇒ Object
Returns the value of attribute listing.
10
11
12
|
# File 'lib/item_builder_mwh/modes.rb', line 10
def listing
@listing
end
|
#reserved_stocks ⇒ Object
Returns the value of attribute reserved_stocks.
18
19
20
|
# File 'lib/item_builder_mwh/modes.rb', line 18
def reserved_stocks
@reserved_stocks
end
|
#shipping_providers ⇒ Object
Returns the value of attribute shipping_providers.
23
24
25
|
# File 'lib/item_builder_mwh/modes.rb', line 23
def shipping_providers
@shipping_providers
end
|
#shopify_inventory_location ⇒ Object
Returns the value of attribute shopify_inventory_location.
22
23
24
|
# File 'lib/item_builder_mwh/modes.rb', line 22
def shopify_inventory_location
@shopify_inventory_location
end
|
#stock_allocs ⇒ Object
Returns the value of attribute stock_allocs.
13
14
15
|
# File 'lib/item_builder_mwh/modes.rb', line 13
def stock_allocs
@stock_allocs
end
|
#variant_listings ⇒ Object
Returns the value of attribute variant_listings.
17
18
19
|
# File 'lib/item_builder_mwh/modes.rb', line 17
def variant_listings
@variant_listings
end
|
#variants ⇒ Object
Returns the value of attribute variants.
12
13
14
|
# File 'lib/item_builder_mwh/modes.rb', line 12
def variants
@variants
end
|
#wh_spaces ⇒ Object
Returns the value of attribute wh_spaces.
11
12
13
|
# File 'lib/item_builder_mwh/modes.rb', line 11
def wh_spaces
@wh_spaces
end
|
#zalora_reserved_stock ⇒ Object
Returns the value of attribute zalora_reserved_stock.
21
22
23
|
# File 'lib/item_builder_mwh/modes.rb', line 21
def zalora_reserved_stock
@zalora_reserved_stock
end
|
#zilingo_quantity ⇒ Object
Returns the value of attribute zilingo_quantity.
19
20
21
|
# File 'lib/item_builder_mwh/modes.rb', line 19
def zilingo_quantity
@zilingo_quantity
end
|
Instance Method Details
#base ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/item_builder_mwh/modes.rb', line 43
def base
{
id: listing.id,
local_id: listing.local_id,
local_item_id: listing.local_item_id,
sku: listing.sku,
variant_id: listing.variant_id
}
end
|
#bundle ⇒ Object
71
72
73
|
# File 'lib/item_builder_mwh/modes.rb', line 71
def bundle
bundles.select {|b| b.variant_id == listing.variant_id }.first
end
|
#bundle_variants ⇒ Object
65
66
67
68
69
|
# File 'lib/item_builder_mwh/modes.rb', line 65
def bundle_variants
if bundle.present?
item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
end
end
|
#credential ⇒ Object
135
136
137
138
139
|
# File 'lib/item_builder_mwh/modes.rb', line 135
def credential
return @shopify_inventory_location['credential'] if @shopify_inventory_location['credential'].present?
nil
end
|
#existing_allocated_stock ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/item_builder_mwh/modes.rb', line 53
def existing_allocated_stock
existing_alloc_stocks.map do |els|
if listings.pluck(:id).include?(els.variant_association_id)
els
end
end.compact
end
|
#initialize(args) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/item_builder_mwh/modes.rb', line 24
def initialize(args)
@listing = args.fetch(:listing)
@wh_spaces = args.fetch(:wh_spaces, [])
@variants = args.fetch(:variants, [])
@stock_allocs = args.fetch(:stock_allocs, [])
@bundles = args.fetch(:bundles, [])
@item_bundle_variants = args.fetch(:item_bundle_variants, [])
@existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
@variant_listings = args.fetch(:variant_listings, [])
@reserved_stocks = args.fetch(:reserved_stocks, [])
@zilingo_quantity = args.fetch(:zilingo_quantity, [])
@lazada_quantity = args.fetch(:lazada_quantity, [])
@zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
@shopify_inventory_location = args.fetch(:shopify_inventory_location, {})
mode = args.fetch(:mode, '')
@shipping_providers = args.fetch(:shipping_providers, [])
warehouse unless mode == :create || mode == :item_create || mode == :precondition_create || mode == :precondition_update || mode == :update
end
|
#listings ⇒ Object
61
62
63
|
# File 'lib/item_builder_mwh/modes.rb', line 61
def listings
variant_listings.select {|vl| vl.variant_id == listing.variant_id}
end
|
#multiwarehouse ⇒ Object
141
142
143
144
145
|
# File 'lib/item_builder_mwh/modes.rb', line 141
def multiwarehouse
return credential['multiwarehouse'] if credential.present?
false
end
|
#pca ⇒ Object
113
114
115
|
# File 'lib/item_builder_mwh/modes.rb', line 113
def pca
listing.profile_channel_association_id.to_s
end
|
#stock_alloc ⇒ Object
75
76
77
|
# File 'lib/item_builder_mwh/modes.rb', line 75
def stock_alloc
stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
end
|
#variant ⇒ Object
79
80
81
|
# File 'lib/item_builder_mwh/modes.rb', line 79
def variant
variants.select {|v| v.id == listing.variant_id }.first
end
|
#variant_id ⇒ Object
117
118
119
|
# File 'lib/item_builder_mwh/modes.rb', line 117
def variant_id
bundle_variants&.first&.variant_id || listing.variant_id
end
|
#warehouse ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/item_builder_mwh/modes.rb', line 83
def warehouse
if multiwarehouse && wh_routing == 1
warehouses << to_h(warehouse_spaces.first)
else
warehouse_list
end
end
|
#warehouse_list ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/item_builder_mwh/modes.rb', line 91
def warehouse_list
if warehouse_spaces.present?
warehouse_spaces.each do |warehouse_space|
warehouses << to_h(warehouse_space)
end
else
warehouses << to_h(nil)
end
end
|
#warehouse_mapping(warehouse_id) ⇒ Object
121
122
123
124
125
126
|
# File 'lib/item_builder_mwh/modes.rb', line 121
def warehouse_mapping(warehouse_id)
WarehouseMapping
.where(profile_channel_association_id:
listing.profile_channel_association_id,
warehouse_id: warehouse_id)
end
|
#warehouse_spaces ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/item_builder_mwh/modes.rb', line 101
def warehouse_spaces
WarehouseSpace
.joins('JOIN warehouse_mappings ON
warehouse_spaces.warehouse_id = warehouse_mappings.warehouse_id')
.joins('JOIN warehouses ON
warehouse_spaces.warehouse_id = warehouses.id')
.where("warehouse_mappings.profile_channel_association_id=#{pca}")
.where('warehouse_mappings.deleted_at is NULL')
.where("warehouse_spaces.item_variant_id=#{variant_id}")
.where('warehouses.consignment = 0')
end
|
#warehouses ⇒ Object
153
154
155
|
# File 'lib/item_builder_mwh/modes.rb', line 153
def warehouses
@warehouses ||= []
end
|
#wh_mapping(warehouse_id) ⇒ Object
128
129
130
131
132
133
|
# File 'lib/item_builder_mwh/modes.rb', line 128
def wh_mapping(warehouse_id)
data = warehouse_mapping(warehouse_id)
return nil if data.empty?
warehouse_mapping(warehouse_id)[0].channel_warehouse_id
end
|
#wh_routing ⇒ Object
147
148
149
150
151
|
# File 'lib/item_builder_mwh/modes.rb', line 147
def wh_routing
return credential['warehouse_routing'] if credential.present? && credential['warehouse_routing'].present?
0
end
|