item_builder 0.1.10 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/item_builder.rb +46 -1
- data/lib/item_builder/get_quantity_service.rb +13 -12
- data/lib/item_builder/modes.rb +4 -0
- data/lib/item_builder/modes/quantity_service.rb +2 -2
- data/lib/item_builder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78374ce9b35b89257c71b2c25a0ec5ae52490eaa79ca64c777acc1fd65bcb2e5
|
4
|
+
data.tar.gz: b839aa926980f7479349658c67ed6e870e2c7960944d0f9abcc2839dec21f984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35913352045ce6d2d1df6d641ed49e2a4fcd7e6aca2b8ec7e016315fe8923dad12037db32f3eeb52077f514685673071b3aa548c36460e715e4e4784ead4306c
|
7
|
+
data.tar.gz: 53928e6cc0be8ad63fb1a42644d4195c031a8a6afc3aece2ff8ae57c3e85a8f49c001288e632d34dfe9c7eae38c6c71175e305823fa73abe65262b61d037ac8d
|
data/lib/item_builder.rb
CHANGED
@@ -10,13 +10,58 @@ require 'item_models'
|
|
10
10
|
|
11
11
|
module ItemBuilder
|
12
12
|
class << self
|
13
|
+
attr_reader :listing_ids
|
14
|
+
attr_reader :listings
|
15
|
+
attr_reader :mode
|
16
|
+
attr_reader :wh_spaces
|
17
|
+
attr_reader :variants
|
18
|
+
attr_reader :variant_ids
|
13
19
|
def build(listing_ids, mode)
|
20
|
+
@listing_ids = listing_ids
|
14
21
|
@mode = mode
|
15
|
-
|
22
|
+
mode_check
|
23
|
+
end
|
24
|
+
|
25
|
+
def mode_check
|
26
|
+
if mode == :quantity
|
27
|
+
quantity_mode
|
28
|
+
else
|
29
|
+
default
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def quantity_mode
|
34
|
+
listings.map do |listing|
|
35
|
+
modes[mode].new(
|
36
|
+
listing: listing,
|
37
|
+
wh_spaces: wh_spaces,
|
38
|
+
variants: variants
|
39
|
+
).perform
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def default
|
44
|
+
listings.map do |listing|
|
16
45
|
modes[mode].new(listing: listing).perform
|
17
46
|
end
|
18
47
|
end
|
19
48
|
|
49
|
+
def wh_spaces
|
50
|
+
@wh_spaces ||= WarehouseSpace.where(item_variant_id: variant_ids)
|
51
|
+
end
|
52
|
+
|
53
|
+
def variants
|
54
|
+
@variants ||= Variant.where(id: variant_ids)
|
55
|
+
end
|
56
|
+
|
57
|
+
def variant_ids
|
58
|
+
@variant_ids ||= listings.map(&:variant_id).uniq
|
59
|
+
end
|
60
|
+
|
61
|
+
def listings
|
62
|
+
@listings ||= VariantListing.where(id: listing_ids)
|
63
|
+
end
|
64
|
+
|
20
65
|
def modes
|
21
66
|
{
|
22
67
|
price: ItemBuilder::Modes::PriceService,
|
@@ -76,23 +76,24 @@ module ItemBuilder
|
|
76
76
|
|
77
77
|
def qty_bundle
|
78
78
|
# Quantity for bundle config
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
qty
|
79
|
+
if bundle_variants.present?
|
80
|
+
qty_list = []
|
81
|
+
bundle_variants.each do |bvr|
|
82
|
+
qty = WarehouseSpace.find_by(item_variant_id: bvr.variant_id)&.quantity
|
83
|
+
qty ||= 0
|
84
|
+
qty = qty / bvr.unit
|
85
|
+
qty_list.push(qty)
|
84
86
|
end
|
85
|
-
qty_list.
|
87
|
+
[qty_list.min, 0].sort[1]
|
88
|
+
else
|
89
|
+
qty_default
|
86
90
|
end
|
87
|
-
[qty_list.min, 0].sort[1]
|
88
|
-
end
|
89
|
-
|
90
|
-
def bundle_condition(bvr)
|
91
|
-
bvr.variant.present? && bvr.variant.warehouse_spaces.present?
|
92
91
|
end
|
93
92
|
|
94
93
|
def bundle_variants
|
95
|
-
Bundle.where(
|
94
|
+
Bundle.where(
|
95
|
+
'variant_id = ?', variant.id
|
96
|
+
).first.bundle_variants.where(channel_id: listing.channel_id)
|
96
97
|
end
|
97
98
|
|
98
99
|
def listing_wh_sp_quantity
|
data/lib/item_builder/modes.rb
CHANGED
@@ -9,8 +9,12 @@ require 'item_builder/modes/update_service'
|
|
9
9
|
module ItemBuilder
|
10
10
|
module Modes
|
11
11
|
attr_reader :listing
|
12
|
+
attr_reader :wh_spaces
|
13
|
+
attr_reader :variants
|
12
14
|
def initialize(args)
|
13
15
|
@listing = args.fetch(:listing)
|
16
|
+
@wh_spaces = args.fetch(:wh_spaces) || []
|
17
|
+
@variants = args.fetch(:variants) || []
|
14
18
|
end
|
15
19
|
|
16
20
|
def base
|
@@ -55,11 +55,11 @@ module ItemBuilder
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def warehouse
|
58
|
-
|
58
|
+
wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
|
59
59
|
end
|
60
60
|
|
61
61
|
def variant
|
62
|
-
|
62
|
+
variants.select {|v| v.id == listing.variant_id }.first
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
data/lib/item_builder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: item_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okaaryanata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|