item_builder 0.1.8 → 0.1.9

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: c64fdf8fcf5b5a10d2d347e642cbc388acb98d5c7f4a9e2ec485a15291b06c43
4
- data.tar.gz: 6abbe3d99475537e7a9cd347b23db0ad14298bd9608b3d17997e0dfc8fbc4ac3
3
+ metadata.gz: bce91d8493302cb16b40cb46855412d7b1cf9378ac39791c7806379c00419602
4
+ data.tar.gz: 0ba73ba00283255f10b25541ae4d3c8a998135fe7d6059341a187fc164ebfe73
5
5
  SHA512:
6
- metadata.gz: 913765098ea5e4f64d71010eb0587ee164899683fcc05e0c30129c1d939dfbda73d11a8d53563fd0a4f2ce98bbdd4344b7f1c44ab87e65bfafc96dc963a86223
7
- data.tar.gz: 1cef844215ba56c6297494bb441109b969322dcae52edb983295c9d9b01d6e7e75b6dfc2f80cf448989412ee555ee4bc097763a101d6408c1fff76c4e180b6cd
6
+ metadata.gz: 8145858b7f105fb0dfb0ab7fc58e982e4efa0e4f095b03b33112800d3d8bd8a09f25e223121ca307f399a737dd855a0e3b75ab50c6dbc2ebfd2d9a21721f2adb
7
+ data.tar.gz: 97088a338d35d90b3cf2b8ccd80acaf7039beea0db0c13dbaf2e4cd32de14b9d5faca7aed082d2e4ff50ba01c7d35c71aec2bfe7ddedeb297a4106c8eab9b503
@@ -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
@@ -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
@@ -23,7 +23,7 @@ module ItemBuilder
23
23
  if item['reservedStockLevel2'] > available_quantity
24
24
  0
25
25
  else
26
- item['availableStockLevel2'] + item['reservedStockLevel2']
26
+ available_quantity
27
27
  end
28
28
  end
29
29
 
@@ -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.8'
4
+ VERSION = '0.1.9'
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-16 00:00:00.000000000 Z
11
+ date: 2020-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,6 +135,15 @@ files:
135
135
  - lib/item_builder/modes/quantity/zalora_service.rb
136
136
  - lib/item_builder/modes/quantity_service.rb
137
137
  - lib/item_builder/modes/simple_service.rb
138
+ - lib/item_builder/modes/update/base.rb
139
+ - lib/item_builder/modes/update/blibli_service.rb
140
+ - lib/item_builder/modes/update/bukalapak_service.rb
141
+ - lib/item_builder/modes/update/jd_service.rb
142
+ - lib/item_builder/modes/update/lazada_service.rb
143
+ - lib/item_builder/modes/update/shopify_service.rb
144
+ - lib/item_builder/modes/update/tokopedia_service.rb
145
+ - lib/item_builder/modes/update/zalora_service.rb
146
+ - lib/item_builder/modes/update_service.rb
138
147
  - lib/item_builder/version.rb
139
148
  homepage:
140
149
  licenses: []