item_builder 0.1.2 → 0.1.3

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: d6ca67cd6f66fc6bb86a68f1140bd07c301b75c5d153a06525739f66792f4100
4
- data.tar.gz: bf50c6b8d2572126a1408da97e1ed89a8a91bed566e1541616c4a02b780d911a
3
+ metadata.gz: c92a9679076c8b127303bb9fc809ba3567424193373552d5675aa1db4f582595
4
+ data.tar.gz: 2701fcce867981222ce0abc80194043c8a7ec05ba126709d90d4879cebfa7484
5
5
  SHA512:
6
- metadata.gz: 29951b9ebe8d09e224c5923f2e985bf3f5376663e48db5f479b05752d60ec411e338cdc0beab6c1a4f8214026529678ae420e4aaac3ecda9439e1e558b12eefd
7
- data.tar.gz: 2fb3d8d0a3820cc291579d0e4bb9992fe4d6bb38229e8e291a63698032d5f2c00934712b04161c5f60b62b6007a6e0af18571c69d8300f07832c1edd76456606
6
+ metadata.gz: b42422beea0ceae242ab2f80d8f8777967eaae82153be8feda2941a8bd7fe1e5819bfcd0a4d105bd2c44fd45d303e4ad722555d128b765ba1661fbc50651a550
7
+ data.tar.gz: 324aa9b16a344e7b9adb67454767bafb43b8a4253057681446d68bb5d54194a02dde8183117d1ae201dc860af6bacf349c2b3bff66db91cdebeae8f2c52e3fca
@@ -10,6 +10,7 @@ module ItemBuilder
10
10
  attr_reader :listing
11
11
  def initialize(args)
12
12
  @listing = args.fetch(:listing)
13
+ warehouse
13
14
  end
14
15
 
15
16
  def base
@@ -20,5 +21,33 @@ module ItemBuilder
20
21
  sku: listing.sku
21
22
  }
22
23
  end
24
+
25
+ def warehouse
26
+ warehouse_spaces.each do |warehouse_space|
27
+ warehouses << to_h(warehouse_space)
28
+ end
29
+ end
30
+
31
+ def warehouse_spaces
32
+ WarehouseSpace.where(item_variant_id: listing.variant_id)
33
+ end
34
+
35
+ def warehouse_mapping(warehouse_id)
36
+ WarehouseMapping
37
+ .where(profile_channel_association_id:
38
+ listing.profile_channel_association_id,
39
+ warehouse_id: warehouse_id)
40
+ end
41
+
42
+ def wh_mapping(warehouse_id)
43
+ data = warehouse_mapping(warehouse_id)
44
+ return nil if data.empty?
45
+
46
+ warehouse_mapping(warehouse_id)[0].channel_warehouse_id
47
+ end
48
+
49
+ def warehouses
50
+ @warehouses ||= []
51
+ end
23
52
  end
24
53
  end
@@ -7,12 +7,17 @@ module ItemBuilder
7
7
  include Modes
8
8
 
9
9
  def perform
10
- to_h.merge(base)
10
+ base.merge!(
11
+ warehouse: warehouses
12
+ )
11
13
  end
12
14
 
13
- def to_h
15
+ def to_h(warehouse_space)
14
16
  {
15
- active: listing.active
17
+ active: listing.active,
18
+ warehouse_id: wh_mapping(
19
+ warehouse_space.warehouse_id
20
+ )
16
21
  }
17
22
  end
18
23
  end
@@ -7,15 +7,20 @@ module ItemBuilder
7
7
  include Modes
8
8
 
9
9
  def perform
10
- to_h.merge(base)
10
+ base.merge!(
11
+ warehouse: warehouses
12
+ )
11
13
  end
12
14
 
13
- def to_h
15
+ def to_h(warehouse_space)
14
16
  {
15
17
  price: listing.price,
16
18
  sale_price: listing.sale_price,
17
19
  sale_start_at: listing.sale_start_at,
18
- sale_end_at: listing.sale_end_at
20
+ sale_end_at: listing.sale_end_at,
21
+ warehouse_id: wh_mapping(
22
+ warehouse_space.warehouse_id
23
+ )
19
24
  }
20
25
  end
21
26
  end
@@ -8,18 +8,19 @@ module ItemBuilder
8
8
  include Modes
9
9
 
10
10
  def perform
11
- to_h.merge(base)
11
+ base.merge!(
12
+ warehouse: warehouses
13
+ )
12
14
  end
13
15
 
14
- def to_h
16
+ def to_h(warehouse_space)
15
17
  {
16
- quantity: warehouse.quantity
18
+ quantity: warehouse_space.quantity,
19
+ warehouse_id: wh_mapping(
20
+ warehouse_space.warehouse_id
21
+ )
17
22
  }
18
23
  end
19
-
20
- def warehouse
21
- WarehouseSpace.find_by(item_variant_id: listing.variant_id)
22
- end
23
24
  end
24
25
  end
25
26
  end
@@ -9,19 +9,22 @@ module ItemBuilder
9
9
  include Modes
10
10
 
11
11
  def perform
12
- to_h.merge(base)
12
+ base.merge!(
13
+ warehouse: warehouses
14
+ )
13
15
  end
14
16
 
15
- def to_h
16
- quantity.merge(price)
17
- end
18
-
19
- def quantity
20
- QuantityService.new(listing: listing).to_h
21
- end
22
-
23
- def price
24
- PriceService.new(listing: listing).to_h
17
+ def to_h(warehouse_space)
18
+ {
19
+ quantity: warehouse_space.quantity,
20
+ price: listing.price,
21
+ sale_price: listing.sale_price,
22
+ sale_start_at: listing.sale_start_at,
23
+ sale_end_at: listing.sale_end_at,
24
+ warehouse_id: wh_mapping(
25
+ warehouse_space.warehouse_id
26
+ )
27
+ }
25
28
  end
26
29
  end
27
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ItemBuilder
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-01 00:00:00.000000000 Z
11
+ date: 2020-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler