item_builder 0.1.23 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6780bd1811cc5b5a70e34a875fbecc9f492d82c0755b80465fe06565f7f58ee
4
- data.tar.gz: 0b45360d1a8651670204a8fa8638ea5454978b90122837d8447f0284ea39fa9a
3
+ metadata.gz: 637545e1e40b3f319760f991d19621b9a0e68b48a16c9219ce4103995070727f
4
+ data.tar.gz: 9128cf0c849fc64ac5f60393c173a7c95d68dc169a75acae8c08b22bad451428
5
5
  SHA512:
6
- metadata.gz: cc7850d78db626648be0b915bf8a8f72d928268892d5360a83b071f65b2e6ba645505fbafae82548da165b0d7ed99f83f1ecdf195cff03c575fa7e4b60d3d7a7
7
- data.tar.gz: 7cba37504ce2c06fec5d2bc5d9be2e80844629a214c1df12c9996147c4b779947867451d24575a30aea1d4455d7be26c5c118786d4491435f45d9ec544a01530
6
+ metadata.gz: 1b854582f9f8bd9f31eee880d643dc1f4884529740fcbf147c892ab5e08cecc07fe969c7f8f0926d712a8934c8390a1a15ee05681ad211be3873ddd7b1a0ca30
7
+ data.tar.gz: 7bf2f7c0711a76a18ca01bb6321a0f7d82d5a81d37cf6f633aed36af3728da47de0e8093e4f1571e66ba99e4d3deb47ac6b57045cc8251e686e9a6226e6afdd3
data/lib/item_builder.rb CHANGED
@@ -26,25 +26,26 @@ class ItemBuilder
26
26
  end
27
27
 
28
28
  def mode_check
29
- if mode == :quantity
30
- quantity_mode
29
+ if mode == :quantity || mode == :simple
30
+ quantity_simple_mode
31
31
  else
32
32
  default
33
33
  end
34
34
  end
35
35
 
36
- def quantity_mode
36
+ def quantity_simple_mode
37
37
  listings.map do |listing|
38
- modes[mode].new(qty_params(listing)).perform
38
+ modes[mode].new(qty_simple_params(listing)).perform
39
39
  end
40
40
  end
41
41
 
42
- def qty_params(listing)
42
+ def qty_simple_params(listing)
43
43
  {
44
44
  listing: listing, wh_spaces: wh_spaces, variants: variants,
45
45
  stock_allocs: stock_allocs, variant_listings: variant_listings,
46
46
  bundles: bundles, item_bundle_variants: item_bundle_variants,
47
- existing_alloc_stocks: existing_alloc_stocks
47
+ existing_alloc_stocks: existing_alloc_stocks,
48
+ reserved_stocks: reserved_stocks
48
49
  }
49
50
  end
50
51
 
@@ -70,8 +71,7 @@ class ItemBuilder
70
71
 
71
72
  def item_bundle_variants
72
73
  @item_bundle_variants ||= BundleVariant.where(
73
- bundle_id: bundle_ids,
74
- channel_id: listings[0].channel_id
74
+ bundle_id: bundle_ids
75
75
  )
76
76
  end
77
77
 
@@ -114,4 +114,20 @@ class ItemBuilder
114
114
  update: ItemBuilder::Modes::UpdateService
115
115
  }
116
116
  end
117
+
118
+ def order_host
119
+ url = ENV['ORDERS_URL'] || 'orders.forstok.com'
120
+ url + '/api/v3/item_line/reserved_stock'
121
+ end
122
+
123
+ def reserved_params
124
+ "account_id=#{listings[0].profile_channel_association_id}
125
+ &item_variant_ids=#{variant_ids.join(',')}"
126
+ end
127
+
128
+ def reserved_stocks
129
+ @reserved_stocks ||= JSON.parse(RestClient.get(
130
+ "#{order_host}?#{reserved_params}"
131
+ ).body) if [3,13].include?(listings[0].channel_id)
132
+ end
117
133
  end
@@ -16,6 +16,7 @@ class ItemBuilder
16
16
  attr_reader :item_bundle_variants
17
17
  attr_reader :existing_alloc_stocks
18
18
  attr_reader :variant_listings
19
+ attr_reader :reserved_stocks
19
20
  def initialize(args)
20
21
  @listing = args.fetch(:listing)
21
22
  @wh_spaces = args.fetch(:wh_spaces, [])
@@ -25,6 +26,7 @@ class ItemBuilder
25
26
  @item_bundle_variants = args.fetch(:item_bundle_variants, [])
26
27
  @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
27
28
  @variant_listings = args.fetch(:variant_listings, [])
29
+ @reserved_stocks = args.fetch(:reserved_stocks, [])
28
30
  end
29
31
 
30
32
  def base
@@ -35,5 +37,39 @@ class ItemBuilder
35
37
  sku: listing.sku
36
38
  }
37
39
  end
40
+
41
+ def existing_allocated_stock
42
+ existing_alloc_stocks.map do |els|
43
+ if listings.pluck(:id).include?(els.variant_association_id)
44
+ els
45
+ end
46
+ end.compact
47
+ end
48
+
49
+ def listings
50
+ variant_listings.select {|vl| vl.variant_id == listing.variant_id}
51
+ end
52
+
53
+ def bundle_variants
54
+ if bundle.present?
55
+ item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
56
+ end
57
+ end
58
+
59
+ def bundle
60
+ bundles.select {|b| b.variant_id == listing.variant_id }.first
61
+ end
62
+
63
+ def stock_alloc
64
+ stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
65
+ end
66
+
67
+ def warehouse
68
+ wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
69
+ end
70
+
71
+ def variant
72
+ variants.select {|v| v.id == listing.variant_id }.first
73
+ end
38
74
  end
39
75
  end
@@ -6,30 +6,14 @@ class ItemBuilder
6
6
  class Base
7
7
  attr_reader :listing
8
8
  attr_reader :available_quantity
9
+ attr_reader :reserved_stock
9
10
 
10
- def initialize(listing, available_quantity)
11
+ def initialize(listing, available_quantity, reserved_stock)
11
12
  raise 'listing is not set' if listing.nil?
12
13
 
13
14
  @listing = listing
14
15
  @available_quantity = available_quantity
15
- end
16
-
17
- def order_host
18
- url = ENV['ORDERS_URL'] || 'orders.forstok.com'
19
- url + '/api/v2/item_line/reserved_stock'
20
- end
21
-
22
- def reserved_params
23
- "account_id=#{listing.profile_channel_association_id}
24
- &item_variant_id=#{listing.variant_id}"
25
- end
26
-
27
- def reserved_stock
28
- RestClient.get("#{order_host}?#{reserved_params}")
29
- end
30
-
31
- def apigateway_get
32
- RestClient.get("#{host}?#{params}")
16
+ @reserved_stock = reserved_stock
33
17
  end
34
18
  end
35
19
  end
@@ -37,13 +37,17 @@ class ItemBuilder
37
37
  def qty_channel
38
38
  class_name = "ItemBuilder::Modes::Quantity::#{channel_name}Service"
39
39
  qty_channel_service = class_name.constantize
40
- qty_channel_service.new(listing, available_quantity).perform
40
+ qty_channel_service.new(listing, available_quantity, reserved_stock).perform
41
41
  end
42
42
 
43
43
  def channel_name
44
44
  QUANTITY_CHANNEL[listing.channel_id].to_s
45
45
  end
46
46
 
47
+ def reserved_stock
48
+ reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
49
+ end
50
+
47
51
  def available_quantity
48
52
  ItemBuilder::GetQuantityService.new(
49
53
  listing: listing, variant: variant,
@@ -52,40 +56,6 @@ class ItemBuilder
52
56
  existing_allocated_stock: existing_allocated_stock
53
57
  ).perform
54
58
  end
55
-
56
- def existing_allocated_stock
57
- existing_alloc_stocks.map do |els|
58
- if listings.pluck(:id).include?(els.variant_association_id)
59
- els
60
- end
61
- end
62
- end
63
-
64
- def listings
65
- variant_listings.select {|vl| vl.variant_id == listing.variant_id}
66
- end
67
-
68
- def bundle_variants
69
- if bundle.present?
70
- item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
71
- end
72
- end
73
-
74
- def bundle
75
- bundles.select {|b| b.variant_id == listing.variant_id }.first
76
- end
77
-
78
- def stock_alloc
79
- stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
80
- end
81
-
82
- def warehouse
83
- wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
84
- end
85
-
86
- def variant
87
- variants.select {|v| v.id == listing.variant_id }.first
88
- end
89
59
  end
90
60
  end
91
61
  end
@@ -17,7 +17,13 @@ class ItemBuilder
17
17
  end
18
18
 
19
19
  def quantity
20
- QuantityService.new(listing: listing).to_h
20
+ QuantityService.new(
21
+ listing: listing, wh_spaces: wh_spaces, variants: variants,
22
+ stock_allocs: stock_allocs, variant_listings: variant_listings,
23
+ bundles: bundles, item_bundle_variants: item_bundle_variants,
24
+ existing_alloc_stocks: existing_alloc_stocks,
25
+ reserved_stocks: reserved_stocks
26
+ ).to_h
21
27
  end
22
28
 
23
29
  def price
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilder
4
- VERSION = '0.1.23'
4
+ VERSION = '0.1.28'
5
5
  end
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.23
4
+ version: 0.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-28 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler