item_builder 0.1.5 → 0.1.10

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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/lib/item_builder.rb +2 -1
  3. data/lib/item_builder/get_quantity_service.rb +141 -0
  4. data/lib/item_builder/modes.rb +1 -0
  5. data/lib/item_builder/modes/price/base.rb +26 -0
  6. data/lib/item_builder/modes/price/blibli_service.rb +26 -0
  7. data/lib/item_builder/modes/price/bukalapak_service.rb +60 -0
  8. data/lib/item_builder/modes/price/jd_service.rb +30 -0
  9. data/lib/item_builder/modes/price/sale_price_policy.rb +40 -0
  10. data/lib/item_builder/modes/price/shopify_service.rb +26 -0
  11. data/lib/item_builder/modes/price/zalora_service.rb +26 -0
  12. data/lib/item_builder/modes/price_service.rb +37 -6
  13. data/lib/item_builder/modes/quantity/base.rb +75 -0
  14. data/lib/item_builder/modes/quantity/blibli_service.rb +51 -0
  15. data/lib/item_builder/modes/quantity/lazada_service.rb +14 -0
  16. data/lib/item_builder/modes/quantity/zalora_service.rb +14 -0
  17. data/lib/item_builder/modes/quantity_service.rb +42 -1
  18. data/lib/item_builder/modes/update/base.rb +30 -0
  19. data/lib/item_builder/modes/update/blibli_service.rb +11 -0
  20. data/lib/item_builder/modes/update/bukalapak_service.rb +11 -0
  21. data/lib/item_builder/modes/update/jd_service.rb +11 -0
  22. data/lib/item_builder/modes/update/lazada_service.rb +11 -0
  23. data/lib/item_builder/modes/update/shopify_service.rb +11 -0
  24. data/lib/item_builder/modes/update/tokopedia_service.rb +62 -0
  25. data/lib/item_builder/modes/update/zalora_service.rb +11 -0
  26. data/lib/item_builder/modes/update_service.rb +56 -0
  27. data/lib/item_builder/version.rb +1 -1
  28. metadata +29 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce2ebd51f97f3d37ae9a8028f885108f544b0f970431bf47f762e0c0a80a7911
4
- data.tar.gz: 7f472d800918402e3b1fbe86a055e446e1a0a6fe6ebe7d268779c6aea203adaa
3
+ metadata.gz: 333ca323d654a17bc52a958c3f0b0eb1a4ae1badfebbaf3f8c1e2a22dcaa7c4b
4
+ data.tar.gz: d79d0f4a17f5a33f3a5cf8c798466db4d4bc5e055bc93375fbb89e164f8d9615
5
5
  SHA512:
6
- metadata.gz: dc967441831e0adb69cb77d9fcaa4be7a13faf6f1058f89f443004676aba085a32e8e8fe0d263ae5da11768cd78dff2671fad093d93345a592a6cfd9e8e67b22
7
- data.tar.gz: 70366f1bb87d059e34537a1723b5a6bfd04b6bfac9d964920c66a4beb1c31af404e195860e83eba93d9a2a30740f670b8bb12a107ed5f8e644fa31baf3c58d06
6
+ metadata.gz: f5e28dd8604e33b90f3179166b314a8d1df21e60d66f32ba4b9da12c1c9f432404ee0378069eaeb97a6441758866787a5cf2218e18e61f2ea951e93ce3c8efae
7
+ data.tar.gz: b27ee3727c10e172ffdf2fa0295a641f58c53c5c8c695fb17bbe8aa5c0b33511356764cd8d46a5f536e3256a98c4ed8eddea06521beee5e7a3c44e8a05173e42
@@ -22,7 +22,8 @@ module ItemBuilder
22
22
  price: ItemBuilder::Modes::PriceService,
23
23
  quantity: ItemBuilder::Modes::QuantityService,
24
24
  simple: ItemBuilder::Modes::SimpleService,
25
- active: ItemBuilder::Modes::ActiveService
25
+ active: ItemBuilder::Modes::ActiveService,
26
+ update: ItemBuilder::Modes::UpdateService
26
27
  }
27
28
  end
28
29
  end
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'warehouse_models'
4
+ require 'item_builder/modes.rb'
5
+ module ItemBuilder
6
+ class GetQuantityService
7
+ attr_reader :listing, :wh_sp, :variant
8
+ def initialize(args)
9
+ @listing = args.fetch(:listing)
10
+ @wh_sp = args.fetch(:wh_sp)
11
+ @variant = args.fetch(:variant)
12
+ end
13
+
14
+ def perform
15
+ return 0 if check_consignment_variant?
16
+
17
+ if allocated_stock_active?
18
+ # yang masuk di kondisi ini,
19
+ # artinya akun tersebut ada allocated stock yang aktif
20
+ allocated_stock
21
+ elsif existing_allocated_stock.present?
22
+ # yang masuk di kondisi ini,
23
+ # artinya akun tersebut tidak ada allocated stock yang aktif,
24
+ # namun ada allocated stock yg aktif dari channel lain
25
+ warehouse_stock - count_existing_alloc_stock + count_alloc_rsvd_stock
26
+ else
27
+ # yang masuk di kondisi ini,
28
+ # artinya tidak ada allocated stock di item tersebut
29
+ warehouse_stock
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def check_consignment_variant?
36
+ listing.consignment? ||
37
+ (
38
+ !listing.active? && listing.channel_id == 12
39
+ )
40
+ end
41
+
42
+ def allocated_stock_active?
43
+ listing.present? && stock_alloc.present? && allocated_start_end?
44
+ end
45
+
46
+ def allocated_start_end?
47
+ stock_alloc.start_at.beginning_of_day <= Time.now &&
48
+ stock_alloc.end_at.end_of_day >= Time.now
49
+ end
50
+
51
+ def allocated_stock
52
+ stock_alloc.quantity.to_i - one_alloc_rsvd_stock(stock_alloc).to_i
53
+ end
54
+
55
+ def stock_alloc
56
+ @stock_alloc ||= listing.variant_listing_stock_allocation
57
+ end
58
+
59
+ # warehouse_stock fungsi untuk mendapatkan available quantity
60
+ # baik itu bundle atau default
61
+ def warehouse_stock
62
+ case variant.config.downcase
63
+ when 'default'
64
+ qty_default
65
+ when 'free gift', 'combo'
66
+ qty_bundle
67
+ else
68
+ raise "config not recognize => #{variant.config}"
69
+ end
70
+ end
71
+
72
+ def qty_default
73
+ # set lower limit for quantity
74
+ [listing_wh_sp_quantity, 0].sort[1]
75
+ end
76
+
77
+ def qty_bundle
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
84
+ end
85
+ qty_list.push(qty)
86
+ 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
+ end
93
+
94
+ def bundle_variants
95
+ Bundle.where('variant_id = ?', variant.id).first.bundle_variant
96
+ end
97
+
98
+ def listing_wh_sp_quantity
99
+ @listing_wh_sp_quantity ||= wh_sp&.quantity || 0
100
+ end
101
+
102
+ def existing_allocated_stock
103
+ VariantListingStockAllocation.where(
104
+ variant_association_id: variant.variant_listings.pluck(:id)
105
+ ).where('ADDTIME(end_at, "07:00") >= NOW()')
106
+ end
107
+
108
+ def count_existing_alloc_stock
109
+ return 0 if existing_allocated_stock.blank?
110
+
111
+ existing_allocated_stock.sum(:quantity)
112
+ end
113
+
114
+ def count_alloc_rsvd_stock
115
+ stock = 0
116
+ existing_allocated_stock.each do |allocated_stock|
117
+ stock += one_alloc_rsvd_stock(allocated_stock).to_i
118
+ end
119
+ stock
120
+ end
121
+
122
+ def host
123
+ url = ENV['ORDERS_URL'] || 'orders.forstok.com'
124
+ url + '/api/v2/item_line/count_one_allocated_reserved_stock'
125
+ end
126
+
127
+ def params(allocated_stock)
128
+ "channel_id=#{listing.channel_id}&item_variant_id=#{listing.variant_id}
129
+ &start_at=#{allocated_stock.start_at.to_date.beginning_of_day}
130
+ &end_at=#{allocated_stock.end_at.to_date.end_of_day}"
131
+ end
132
+
133
+ # one_alloc_rsvd_stock fungsi untuk mendapatkan satu
134
+ # allocated reserved stock
135
+ def one_alloc_rsvd_stock(allocated_stock)
136
+ RestClient.get("#{host}?#{params(allocated_stock)}")
137
+ rescue RestClient::ExceptionWithResponse => e
138
+ e.response
139
+ end
140
+ end
141
+ end
@@ -5,6 +5,7 @@ require 'item_builder/modes/price_service'
5
5
  require 'item_builder/modes/quantity_service'
6
6
  require 'item_builder/modes/simple_service'
7
7
  require 'item_builder/modes/active_service'
8
+ require 'item_builder/modes/update_service'
8
9
  module ItemBuilder
9
10
  module Modes
10
11
  attr_reader :listing
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'item_builder/modes.rb'
5
+ require 'item_builder/modes/price_service'
6
+ require 'item_builder/modes/price/sale_price_policy'
7
+ module ItemBuilder
8
+ module Modes
9
+ module Price
10
+ class Base
11
+ attr_reader :listing
12
+
13
+ def initialize(listing)
14
+ raise 'listing is not set' if listing.nil?
15
+
16
+ @listing = listing
17
+ end
18
+
19
+ def sale_price_policy
20
+ @sale_price_policy ||=
21
+ ItemBuilder::Modes::Price::SalePricePolicy.new(listing: listing)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'item_builder/modes/price/base'
5
+ module ItemBuilder
6
+ module Modes
7
+ module Price
8
+ class BlibliService < Base
9
+ def perform
10
+ {
11
+ price: listing.price,
12
+ sale_price: sale_price,
13
+ sale_start_at: listing.sale_start_at,
14
+ sale_end_at: listing.sale_end_at
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ def sale_price
21
+ sale_price_policy.on_sale? ? listing.sale_price : listing.price
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'item_builder/modes/price/base'
5
+ module ItemBuilder
6
+ module Modes
7
+ module Price
8
+ class BukalapakService < Base
9
+ def perform
10
+ if listing.sale_price.nil?
11
+ bukalapak_price
12
+ else
13
+ deal
14
+ end
15
+ end
16
+
17
+ def bukalapak_price
18
+ {
19
+ price: listing.price,
20
+ sale_price: listing.sale_price,
21
+ sale_start_at: listing.sale_start_at,
22
+ sale_end_at: listing.sale_end_at
23
+ }
24
+ end
25
+
26
+ def deal
27
+ {
28
+ percentage: deal_percentage,
29
+ sale_start_at: sale_start_at,
30
+ sale_end_at: sale_end_at,
31
+ price: listing.price,
32
+ sale_price: listing.sale_price
33
+ }
34
+ end
35
+
36
+ def deal_percentage
37
+ price = listing.price.to_f
38
+ sale_price = listing.sale_price.to_f
39
+ 100 - (sale_price / price * 100)
40
+ end
41
+
42
+ def sale_start_at
43
+ return DateTime.now if listing.sale_start_at.nil?
44
+ return DateTime.now if listing.sale_start_at < DateTime.now
45
+
46
+ listing.sale_start_at
47
+ end
48
+
49
+ def sale_end_at
50
+ month_later = DateTime.now + 1.month
51
+ return month_later if listing.sale_end_at.nil?
52
+ return month_later if listing.sale_end_at > month_later
53
+ return month_later if listing.sale_end_at < DateTime.now
54
+
55
+ listing.sale_end_at
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'item_builder/modes/price/base'
5
+ module ItemBuilder
6
+ module Modes
7
+ module Price
8
+ class JdService < Base
9
+ def perform
10
+ {
11
+ price: listing.price,
12
+ sale_price: jd_price,
13
+ sale_start_at: listing.sale_start_at,
14
+ sale_end_at: listing.sale_end_at
15
+ }
16
+ end
17
+
18
+ def jd_price
19
+ increment_price =
20
+ if (listing.price % 1000).positive?
21
+ 1000
22
+ else
23
+ 0
24
+ end
25
+ (listing.price.to_i / 1000) * 1000 + increment_price
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'item_builder/modes.rb'
5
+ require 'item_builder/modes/price_service'
6
+ module ItemBuilder
7
+ module Modes
8
+ module Price
9
+ class SalePricePolicy
10
+ include Modes
11
+ def sale_price
12
+ # has sale price but no sale date defined
13
+ # then push sale price immediately
14
+ # assuming it starts today and no end date specified
15
+ return listing.sale_price if sale_price? && !sale_date?
16
+
17
+ # has sale price and today is on sale then push sale price immediately
18
+ listing.sale_price if sale_price? && on_sale?
19
+ # don't push / don't return anything if 2 rules above unfulfilled
20
+ end
21
+
22
+ def sale_price?
23
+ listing.sale_price
24
+ end
25
+
26
+ def sale_date?
27
+ listing.sale_start_at && listing.sale_end_at
28
+ end
29
+
30
+ def on_sale?
31
+ return false unless sale_price?
32
+
33
+ sale_start_at = listing.sale_start_at || DateTime.now
34
+ sale_end_at = listing.sale_end_at || DateTime.now + 1_000_000.years
35
+ sale_start_at <= DateTime.now && sale_end_at >= DateTime.now
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'item_builder/modes/price/base'
5
+ module ItemBuilder
6
+ module Modes
7
+ module Price
8
+ class ShopifyService < Base
9
+ def perform
10
+ {
11
+ price: listing.price,
12
+ sale_price: sale_price,
13
+ sale_start_at: listing.sale_start_at,
14
+ sale_end_at: listing.sale_end_at
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ def sale_price
21
+ sale_price_policy.on_sale? ? listing.sale_price : listing.price
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'item_builder/modes/price/base'
5
+ module ItemBuilder
6
+ module Modes
7
+ module Price
8
+ class ZaloraService < Base
9
+ def perform
10
+ {
11
+ price: listing.price,
12
+ sale_price: sale_price,
13
+ sale_start_at: listing.sale_start_at,
14
+ sale_end_at: listing.sale_end_at
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ def sale_price
21
+ sale_price_policy.on_sale? ? listing.sale_price : listing.price
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,22 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes.rb'
4
+ require 'item_builder/modes/price/blibli_service'
5
+ require 'item_builder/modes/price/bukalapak_service'
6
+ require 'item_builder/modes/price/zalora_service'
7
+ require 'item_builder/modes/price/shopify_service'
8
+ require 'item_builder/modes/price/jd_service'
4
9
  module ItemBuilder
5
10
  module Modes
6
11
  class PriceService
7
12
  include Modes
8
13
 
14
+ PRICE_CHANNEL = {}.tap do |hash|
15
+ hash[2] = :Shopify
16
+ hash[9] = :Blibli
17
+ hash[11] = :Bukalapak
18
+ hash[13] = :Zalora
19
+ hash[16] = :Jd
20
+ end.freeze
21
+
9
22
  def perform
10
23
  to_h.merge(base)
11
24
  end
12
25
 
13
26
  def to_h
14
- {
15
- price: listing.price,
16
- sale_price: listing.sale_price,
17
- sale_start_at: listing.sale_start_at,
18
- sale_end_at: listing.sale_end_at
19
- }
27
+ price
28
+ end
29
+
30
+ def price
31
+ if channel_name.empty?
32
+ {
33
+ price: listing.price,
34
+ sale_price: listing.sale_price,
35
+ sale_start_at: listing.sale_start_at,
36
+ sale_end_at: listing.sale_end_at
37
+ }
38
+ else
39
+ price_channel
40
+ end
41
+ end
42
+
43
+ def price_channel
44
+ class_name = "ItemBuilder::Modes::Price::#{channel_name}Service"
45
+ price_channel_service = class_name.constantize
46
+ price_channel_service.new(listing).perform
47
+ end
48
+
49
+ def channel_name
50
+ PRICE_CHANNEL[listing.channel_id].to_s
20
51
  end
21
52
  end
22
53
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ItemBuilder
4
+ module Modes
5
+ module Quantity
6
+ class Base
7
+ attr_reader :listing
8
+ attr_reader :available_quantity
9
+
10
+ def initialize(listing, available_quantity)
11
+ raise 'listing is not set' if listing.nil?
12
+
13
+ @listing = listing
14
+ @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
+ rescue RestClient::ExceptionWithResponse => e
30
+ e.response
31
+ end
32
+
33
+ def apigateway_get
34
+ RestClient.get("#{host}?#{params}")
35
+ rescue RestClient::ExceptionWithResponse => e
36
+ e.response
37
+ end
38
+
39
+ def headers
40
+ {
41
+ content_type: :json,
42
+ accept: :json
43
+ }
44
+ end
45
+
46
+ def credential
47
+ account_id = listing.profile_channel_association_id
48
+ host = ENV['CREDENTIAL_URL'] || 'user.forstok.com'
49
+ begin
50
+ RestClient.get("#{host}/credential?account_id=#{account_id}")
51
+ rescue RestClient::ExceptionWithResponse => e
52
+ e.response
53
+ end
54
+ end
55
+
56
+ def data
57
+ {
58
+ "credential": JSON.parse(credential)['credential'],
59
+ "data": request
60
+ }
61
+ end
62
+
63
+ def api_data
64
+ data.to_json
65
+ end
66
+
67
+ def apigateway_post
68
+ RestClient.post(url, api_data, headers)
69
+ rescue RestClient::ExceptionWithResponse => e
70
+ e.response
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/quantity/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Quantity
7
+ class BlibliService < Base
8
+ def perform
9
+ local_variant
10
+ end
11
+
12
+ def local_variant
13
+ qty = 0
14
+ local_product['value']['items'].each do |item|
15
+ qty = total_quantity(item) if item['itemSku'] == listing.local_id
16
+ end
17
+ qty
18
+ end
19
+
20
+ def total_quantity(item)
21
+ # Make stock 0
22
+ # if local reserved quantity is bigger than available quantity
23
+ if item['reservedStockLevel2'] > available_quantity
24
+ 0
25
+ else
26
+ available_quantity
27
+ end
28
+ end
29
+
30
+ # Find local product based on id
31
+ # @return [Hash] Local Blibli product
32
+ def local_product
33
+ @local_product ||= JSON.parse(apigateway_post)
34
+ end
35
+
36
+ private
37
+
38
+ def request
39
+ {
40
+ "gdnSku": listing.local_id
41
+ }
42
+ end
43
+
44
+ def url
45
+ url = ENV['API_GATEWAY_URL'] || 'apigateway.forstok.com'
46
+ url + '/blibli/item'
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/quantity/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Quantity
7
+ class LazadaService < Base
8
+ def perform
9
+ available_quantity + reserved_stock.to_i
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/quantity/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Quantity
7
+ class ZaloraService < Base
8
+ def perform
9
+ available_quantity + reserved_stock.to_i
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,24 +2,65 @@
2
2
 
3
3
  require 'warehouse_models'
4
4
  require 'item_builder/modes.rb'
5
+ require 'item_builder/get_quantity_service'
6
+ require 'item_builder/modes/quantity/base'
7
+ require 'item_builder/modes/quantity/lazada_service'
8
+ require 'item_builder/modes/quantity/blibli_service'
9
+ require 'item_builder/modes/quantity/zalora_service'
5
10
  module ItemBuilder
6
11
  module Modes
7
12
  class QuantityService
8
13
  include Modes
9
14
 
15
+ QUANTITY_CHANNEL = {}.tap do |hash|
16
+ hash[3] = :Lazada
17
+ hash[9] = :Blibli
18
+ hash[13] = :Zalora
19
+ end.freeze
20
+
10
21
  def perform
11
22
  to_h.merge(base)
12
23
  end
13
24
 
14
25
  def to_h
15
26
  {
16
- quantity: warehouse.quantity
27
+ quantity: qty
17
28
  }
18
29
  end
19
30
 
31
+ def qty
32
+ if channel_name.empty?
33
+ available_quantity
34
+ else
35
+ qty_channel
36
+ end
37
+ end
38
+
39
+ def qty_channel
40
+ class_name = "ItemBuilder::Modes::Quantity::#{channel_name}Service"
41
+ qty_channel_service = class_name.constantize
42
+ qty_channel_service.new(listing, available_quantity).perform
43
+ end
44
+
45
+ def channel_name
46
+ QUANTITY_CHANNEL[listing.channel_id].to_s
47
+ end
48
+
49
+ def available_quantity
50
+ ItemBuilder::GetQuantityService.new(
51
+ listing: listing,
52
+ variant: variant,
53
+ wh_sp: warehouse
54
+ ).perform
55
+ end
56
+
20
57
  def warehouse
21
58
  WarehouseSpace.find_by(item_variant_id: listing.variant_id)
22
59
  end
60
+
61
+ def variant
62
+ @variant ||= Variant.find(listing.variant_id)
63
+ end
23
64
  end
24
65
  end
25
66
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes.rb'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Update
7
+ class Base
8
+ attr_reader :listing
9
+ attr_reader :item_listing
10
+
11
+ def initialize(listing, item_listing)
12
+ raise 'listing is not set' if listing.nil?
13
+
14
+ raise 'item listing is not set' if item_listing.nil?
15
+
16
+ @listing = listing
17
+ @item_listing = item_listing
18
+ end
19
+
20
+ def base
21
+ {
22
+ name: listing.name,
23
+ minimum_order: listing.minimum_order,
24
+ package_weight: listing.package_weight
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/update/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Update
7
+ class BlibliService < Base
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/update/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Update
7
+ class BukalapakService < Base
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/update/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Update
7
+ class JdService < Base
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/update/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Update
7
+ class LazadaService < Base
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/update/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Update
7
+ class ShopifyService < Base
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/update/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Update
7
+ class TokopediaService < Base
8
+ def perform
9
+ tokopedia_attr.merge(base)
10
+ end
11
+
12
+ def tokopedia_attr
13
+ {
14
+ condition: (listing.new_condition ? 'NEW' : 'USED')
15
+ }
16
+ end
17
+
18
+ def possible_variant_options
19
+ item_listing.item_listing_custom_fields
20
+ .where.not(value: '') # prevent unselected/empty options
21
+ .group_by(&:tokopedia_custom_field_id)
22
+ .each_with_index.map {|variant_custom_fields, index1|
23
+ variant_custom_field_sample = variant_custom_fields.first
24
+ selected_tokopedia_custom_field = tokopedia_variant(variant_custom_field_sample)
25
+ {
26
+ v: variant_custom_field_sample.tokopedia.local_id.to_i,
27
+ vu: selected_tokopedia_custom_field['unit_id'],
28
+ pos: index1 + 1,
29
+ opt: variant_custom_fields.pluck(:value).uniq.map {|custom_field_value|
30
+ # handle variant with manual value (without options)
31
+ if variant_custom_field_sample.tokopedia.input_type == 'text'
32
+ {
33
+ value: custom_field_value,
34
+ t_id: custom_field_value.bytes.sum, # set value act as option id
35
+ cstm: ''
36
+ }
37
+ else
38
+ custom_field_option = variant_custom_field_sample.tokopedia.options
39
+ .find_by(name: custom_field_value)
40
+ option_value =
41
+ if selected_tokopedia_custom_field['unit_id'] == 0
42
+ custom_field_option.name
43
+ else
44
+ custom_field_option.name
45
+ .split(" #{selected_tokopedia_custom_field['unit']}")
46
+ .first
47
+ end
48
+ {
49
+ vuv: custom_field_option.local_id, # variant unit value id
50
+ value: option_value, # original option value
51
+ t_id: custom_field_option.id,
52
+ cstm: ''
53
+ }
54
+ end
55
+ }
56
+ }
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/update/base'
4
+ module ItemBuilder
5
+ module Modes
6
+ module Update
7
+ class ZaloraService < Base
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes.rb'
4
+ require 'item_builder/modes/update/blibli_service'
5
+ require 'item_builder/modes/update/bukalapak_service'
6
+ require 'item_builder/modes/update/lazada_service'
7
+ require 'item_builder/modes/update/zalora_service'
8
+ require 'item_builder/modes/update/shopify_service'
9
+ require 'item_builder/modes/update/jd_service'
10
+ require 'item_builder/modes/update/tokopedia_service'
11
+ module ItemBuilder
12
+ module Modes
13
+ class UpdateService
14
+ include Modes
15
+
16
+ UPDATE_CHANNEL = {}.tap do |hash|
17
+ hash[2] = :Shopify
18
+ hash[3] = :Lazada
19
+ hash[4] = :Bhinneka
20
+ hash[5] = :Blanja
21
+ hash[9] = :Blibli
22
+ hash[11] = :Bukalapak
23
+ hash[12] = :Shopee
24
+ hash[13] = :Zalora
25
+ hash[15] = :Tokopedia
26
+ hash[16] = :Jd
27
+ end.freeze
28
+
29
+ def perform
30
+ to_h.merge(base)
31
+ end
32
+
33
+ def to_h
34
+ simple.merge(update)
35
+ end
36
+
37
+ def update
38
+ class_name = "ItemBuilder::Modes::Update::#{channel_name}Service"
39
+ update_channel_service = class_name.constantize
40
+ update_channel_service.new(listing, item_listing).perform
41
+ end
42
+
43
+ def channel_name
44
+ UPDATE_CHANNEL[listing.channel_id].to_s
45
+ end
46
+
47
+ def simple
48
+ SimpleService.new(listing: listing).to_h
49
+ end
50
+
51
+ def item_listing
52
+ @item_listing ||= ItemListing.find(listing.channel_association_id)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ItemBuilder
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.10'
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.5
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.0.7
89
+ version: 0.0.11
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.0.7
96
+ version: 0.0.11
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: warehouse_models
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -116,17 +116,38 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - lib/item_builder.rb
119
+ - lib/item_builder/get_quantity_service.rb
119
120
  - lib/item_builder/modes.rb
120
121
  - lib/item_builder/modes/active_service.rb
121
122
  - lib/item_builder/modes/base_service.rb
123
+ - lib/item_builder/modes/price/base.rb
124
+ - lib/item_builder/modes/price/blibli_service.rb
125
+ - lib/item_builder/modes/price/bukalapak_service.rb
126
+ - lib/item_builder/modes/price/jd_service.rb
127
+ - lib/item_builder/modes/price/sale_price_policy.rb
128
+ - lib/item_builder/modes/price/shopify_service.rb
129
+ - lib/item_builder/modes/price/zalora_service.rb
122
130
  - lib/item_builder/modes/price_service.rb
131
+ - lib/item_builder/modes/quantity/base.rb
132
+ - lib/item_builder/modes/quantity/blibli_service.rb
133
+ - lib/item_builder/modes/quantity/lazada_service.rb
134
+ - lib/item_builder/modes/quantity/zalora_service.rb
123
135
  - lib/item_builder/modes/quantity_service.rb
124
136
  - lib/item_builder/modes/simple_service.rb
137
+ - lib/item_builder/modes/update/base.rb
138
+ - lib/item_builder/modes/update/blibli_service.rb
139
+ - lib/item_builder/modes/update/bukalapak_service.rb
140
+ - lib/item_builder/modes/update/jd_service.rb
141
+ - lib/item_builder/modes/update/lazada_service.rb
142
+ - lib/item_builder/modes/update/shopify_service.rb
143
+ - lib/item_builder/modes/update/tokopedia_service.rb
144
+ - lib/item_builder/modes/update/zalora_service.rb
145
+ - lib/item_builder/modes/update_service.rb
125
146
  - lib/item_builder/version.rb
126
- homepage:
147
+ homepage:
127
148
  licenses: []
128
149
  metadata: {}
129
- post_install_message:
150
+ post_install_message:
130
151
  rdoc_options: []
131
152
  require_paths:
132
153
  - lib
@@ -142,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
163
  version: '0'
143
164
  requirements: []
144
165
  rubygems_version: 3.0.6
145
- signing_key:
166
+ signing_key:
146
167
  specification_version: 4
147
168
  summary: Item builder
148
169
  test_files: []