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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 333ca323d654a17bc52a958c3f0b0eb1a4ae1badfebbaf3f8c1e2a22dcaa7c4b
4
- data.tar.gz: d79d0f4a17f5a33f3a5cf8c798466db4d4bc5e055bc93375fbb89e164f8d9615
3
+ metadata.gz: 78374ce9b35b89257c71b2c25a0ec5ae52490eaa79ca64c777acc1fd65bcb2e5
4
+ data.tar.gz: b839aa926980f7479349658c67ed6e870e2c7960944d0f9abcc2839dec21f984
5
5
  SHA512:
6
- metadata.gz: f5e28dd8604e33b90f3179166b314a8d1df21e60d66f32ba4b9da12c1c9f432404ee0378069eaeb97a6441758866787a5cf2218e18e61f2ea951e93ce3c8efae
7
- data.tar.gz: b27ee3727c10e172ffdf2fa0295a641f58c53c5c8c695fb17bbe8aa5c0b33511356764cd8d46a5f536e3256a98c4ed8eddea06521beee5e7a3c44e8a05173e42
6
+ metadata.gz: 35913352045ce6d2d1df6d641ed49e2a4fcd7e6aca2b8ec7e016315fe8923dad12037db32f3eeb52077f514685673071b3aa548c36460e715e4e4784ead4306c
7
+ data.tar.gz: 53928e6cc0be8ad63fb1a42644d4195c031a8a6afc3aece2ff8ae57c3e85a8f49c001288e632d34dfe9c7eae38c6c71175e305823fa73abe65262b61d037ac8d
@@ -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
- VariantListing.where(id: listing_ids).map do |listing|
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
- qty_list = []
80
- bundle_variants.each do |bvr|
81
- qty = 0
82
- if bundle_condition(bvr)
83
- qty = bvr.variant.warehouse_spaces.first.quantity / bvr.unit
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.push(qty)
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('variant_id = ?', variant.id).first.bundle_variant
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
@@ -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
- WarehouseSpace.find_by(item_variant_id: listing.variant_id)
58
+ wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
59
59
  end
60
60
 
61
61
  def variant
62
- @variant ||= Variant.find(listing.variant_id)
62
+ variants.select {|v| v.id == listing.variant_id }.first
63
63
  end
64
64
  end
65
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ItemBuilder
4
- VERSION = '0.1.10'
4
+ VERSION = '0.1.15'
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.10
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: 2020-10-01 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler