item_builder 0.1.58 → 0.1.59

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: 2d0017b50afaf5f88d8edbdc634ee44fc21f783e72de47d24691e997d22a286d
4
- data.tar.gz: d2c1f2136ef89b458b11c4a20d121253e5b1ec755a73de41fba89e95966e18c7
3
+ metadata.gz: a2df99bf90994e6a79cfc8b55173af2460cf22900a41f55348a9e04666b486ed
4
+ data.tar.gz: c6dde5d81f574165083bd911d9b6c5ec50acd28c39a2bcfb77f59681c002b559
5
5
  SHA512:
6
- metadata.gz: 69950b28ef94b8ded4e956d32aa931b84a27eb6bd5693b8d05543b21af83618d8b8665370f501c754550a2f0c56fc52445097a8130d47c0819e0401a8be12b10
7
- data.tar.gz: 9ce30390f43b8c2ec84ec42cd58ba153e8c56ce8289225af017e029853e795aa45bec8e4b3cb99e7fc503a8407de476cdef98c5170e64fbf09a534a2b24b369c
6
+ metadata.gz: 144043eb8b8177c85f79814f87fdd000ea8628edd587e536f8be9c01b2d8e1cf895062bd1fc1ec5042c18136f9ee9710db19f26e2c73114199c75205dee86b9b
7
+ data.tar.gz: d22ea600bdc9475b390d9161248caf5c4ea9b06d281721dd90e609dda3d35677d56eac198fbf9dd99d493030486156dba709b0452ecbb464885ed60b7c5b5d89
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ItemBuilder
4
+ module Modes
5
+ module Create
6
+ class Base
7
+ attr_reader :item_listing
8
+ attr_reader :shipping_providers
9
+
10
+ def initialize(item_listing, shipping_providers)
11
+ raise 'item listing is not set' if item_listing.nil?
12
+
13
+ raise 'shipping providers is not set' if shipping_providers.nil?
14
+
15
+ @item_listing = item_listing
16
+ @shipping_providers = shipping_providers
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/create/base'
4
+ class ItemBuilder
5
+ module Modes
6
+ module Create
7
+ class ShopeeService < Base
8
+ def perform
9
+ {
10
+ category: category,
11
+ brand: brand,
12
+ shipping_providers: map_shipping_providers
13
+ }
14
+ end
15
+
16
+ def category
17
+ {
18
+ id: item_listing&.item_listing_category&.id,
19
+ local_id: item_listing&.item_listing_category&.shopee&.local_id,
20
+ name: item_listing&.item_listing_category&.shopee&.name
21
+ }
22
+ end
23
+
24
+ def brand
25
+ {
26
+ id: item_listing&.item_listing_brand&.id,
27
+ local_id: item_listing&.item_listing_brand&.shopee&.local_id,
28
+ name: item_listing&.item_listing_brand&.shopee&.name
29
+ }
30
+ end
31
+
32
+ def map_shipping_providers
33
+ shipping_providers.map do |shipping_provider|
34
+ {
35
+ local_id: shipping_provider.local_id,
36
+ name: shipping_provider.name,
37
+ enabled: shipping_provider.enabled
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes.rb'
4
+ require 'item_builder/modes/create/shopee_service'
5
+ class ItemBuilder
6
+ module Modes
7
+ class CreateService
8
+ include Modes
9
+
10
+ CREATE_CHANNEL = {}.tap do |hash|
11
+ hash[12] = :Shopee
12
+ end.freeze
13
+
14
+ def perform
15
+ to_h.merge(create_channel)
16
+ end
17
+
18
+ def to_h
19
+ {
20
+ item: {
21
+ id: item_listing.id,
22
+ variations: ::ItemBuilder.build(listings.map(&:id), :map_create)
23
+ }
24
+ }
25
+ end
26
+
27
+ def create_channel
28
+ class_name = "ItemBuilder::Modes::Create::#{channel_name}Service"
29
+ create_channel_service = class_name.constantize
30
+ create_channel_service.new(item_listing, shipping_providers).perform
31
+ end
32
+
33
+ def channel_name
34
+ CREATE_CHANNEL[listing.channel_id].to_s
35
+ end
36
+
37
+ def item_listing
38
+ @item_listing ||= listing.item_listing
39
+ end
40
+
41
+ def listings
42
+ @listings ||= item_listing.variant_listings.where(
43
+ profile_channel_association_id: listing.profile_channel_association_id
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ItemBuilder
4
+ module Modes
5
+ module MapCreate
6
+ class Base
7
+ attr_reader :listing
8
+
9
+ def initialize(listing)
10
+ raise 'listing is not set' if listing.nil?
11
+
12
+ @listing = listing
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/map_create/base'
4
+ class ItemBuilder
5
+ module Modes
6
+ module MapCreate
7
+ class ShopeeService < Base
8
+ def perform
9
+ {
10
+ item_custom_fields: item_custom_fields,
11
+ variant_custom_fields: variant_custom_fields,
12
+ shipping_providers: shipping_providers
13
+ }
14
+ end
15
+
16
+ def item_custom_fields
17
+ listing.item_listing_custom_fields.map do |item|
18
+ {
19
+ value: item.value,
20
+ local_id: item&.shopee&.local_id,
21
+ data_type: item&.shopee&.data_type,
22
+ input_type: item&.shopee&.input_type,
23
+ options: item&.shopee&.options.map do |option|
24
+ {
25
+ id: option.id,
26
+ name: option.name,
27
+ local_id: option.local_id
28
+ }
29
+ end
30
+ }
31
+ end
32
+ end
33
+
34
+ def variant_custom_fields
35
+ listing.item_listing_variant_custom_fields.map do |variant|
36
+ {
37
+ value: variant.value,
38
+ local_id: variant&.shopee&.local_id,
39
+ data_type: variant&.shopee&.data_type,
40
+ input_type: variant&.shopee&.input_type
41
+ }
42
+ end
43
+ end
44
+
45
+ def shipping_providers
46
+ listing.shopee_shipping_providers.map do |shipping_provider|
47
+ {
48
+ logistic_id: shipping_provider['logistic_id']
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes.rb'
4
+ require 'item_builder/modes/map_create/shopee_service'
5
+ class ItemBuilder
6
+ module Modes
7
+ class MapCreateService
8
+ include Modes
9
+
10
+ MAP_CREATE_CHANNEL = {}.tap do |hash|
11
+ hash[12] = :Shopee
12
+ end.freeze
13
+
14
+ def perform
15
+ base.merge(simple(listing)).merge(to_h).merge(map_create_channel)
16
+ end
17
+
18
+ def simple(listing)
19
+ SimpleService.new(
20
+ listing: listing, wh_spaces: wh_spaces, variants: variants,
21
+ stock_allocs: stock_allocs, variant_listings: variant_listings,
22
+ bundles: bundles, item_bundle_variants: item_bundle_variants,
23
+ existing_alloc_stocks: existing_alloc_stocks,
24
+ zilingo_quantity: zilingo_quantity,
25
+ zalora_reserved_stock: zalora_reserved_stock
26
+ ).to_h
27
+ end
28
+
29
+ def to_h
30
+ {
31
+ name: listing.name,
32
+ description: listing.description,
33
+ weight: listing.package_weight,
34
+ length: listing.package_length,
35
+ width: listing.package_width,
36
+ height: listing.package_height,
37
+ condition: listing.new_condition,
38
+ option_name: listing.option_name,
39
+ option_value: listing.option_value,
40
+ option2_name: listing.option2_name,
41
+ option2_value: listing.option2_value,
42
+ internal_data: listing.internal_data,
43
+ images: images
44
+ }
45
+ end
46
+
47
+ def images
48
+ listing.item_listing_variant_images.map do |img|
49
+ {
50
+ id: img.id,
51
+ local_id: img.local_id,
52
+ local_url: img.local_url,
53
+ url: img.image.image.url
54
+ }
55
+ end
56
+ end
57
+
58
+ def map_create_channel
59
+ class_name = "ItemBuilder::Modes::MapCreate::#{channel_name}Service"
60
+ create_channel_service = class_name.constantize
61
+ create_channel_service.new(listing).perform
62
+ end
63
+
64
+ def channel_name
65
+ MAP_CREATE_CHANNEL[listing.channel_id].to_s
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ItemBuilder
4
+ module Modes
5
+ module PreconditionCreate
6
+ class Base
7
+ attr_reader :listing
8
+
9
+ def initialize(listing)
10
+ raise 'listing is not set' if listing.nil?
11
+
12
+ @listing = listing
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/precondition_create/base'
4
+ class ItemBuilder
5
+ module Modes
6
+ module PreconditionCreate
7
+ class ShopeeService < Base
8
+ def perform
9
+ {
10
+ internal_data: listing.internal_data,
11
+ images: images
12
+ }
13
+ end
14
+
15
+ def images
16
+ listing.item_listing_variant_images.map do |img|
17
+ {
18
+ id: img.id,
19
+ local_id: img.local_id,
20
+ local_url: img.local_url,
21
+ url: img.image.image.url
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes.rb'
4
+ require 'item_builder/modes/precondition_create/shopee_service'
5
+ class ItemBuilder
6
+ module Modes
7
+ class PreconditionCreateService
8
+ include Modes
9
+
10
+ MAP_PRECONDITION_CREATE_CHANNEL = {}.tap do |hash|
11
+ hash[12] = :Shopee
12
+ end.freeze
13
+
14
+ def perform
15
+ base.merge(map_precondition_create)
16
+ end
17
+
18
+ def map_precondition_create
19
+ class_name = "ItemBuilder::Modes::PreconditionCreate::#{channel_name}Service"
20
+ create_channel_service = class_name.constantize
21
+ create_channel_service.new(listing).perform
22
+ end
23
+
24
+ def channel_name
25
+ MAP_PRECONDITION_CREATE_CHANNEL[listing.channel_id].to_s
26
+ end
27
+ end
28
+ end
29
+ end
@@ -21,6 +21,7 @@ class ItemBuilder
21
21
  attr_reader :zalora_reserved_stock
22
22
  attr_reader :shopify_inventory_location
23
23
  attr_reader :wh_id
24
+ attr_reader :shipping_providers
24
25
  def initialize(args)
25
26
  @listing = args.fetch(:listing)
26
27
  @wh_spaces = args.fetch(:wh_spaces, [])
@@ -35,6 +36,7 @@ class ItemBuilder
35
36
  @zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
36
37
  @shopify_inventory_location = args.fetch(:shopify_inventory_location, [])
37
38
  @wh_id = args.fetch(:wh_id, [])
39
+ @shipping_providers = args.fetch(:shipping_providers, [])
38
40
  end
39
41
 
40
42
  def base
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilder
4
- VERSION = '0.1.58'
4
+ VERSION = '0.1.59'
5
5
  end
data/lib/item_builder.rb CHANGED
@@ -7,6 +7,10 @@ require 'item_builder/modes/price_service'
7
7
  require 'item_builder/modes/quantity_service'
8
8
  require 'item_builder/modes/simple_service'
9
9
  require 'item_builder/modes/active_service'
10
+ require 'item_builder/modes/create_service'
11
+ require 'item_builder/modes/map_create_service'
12
+ require 'item_builder/modes/precondition_create_service'
13
+ require 'item_builder/modes/update_service'
10
14
  require 'item_models'
11
15
  require 'item_builder/zilingo_quantity_service'
12
16
  require 'item_builder/lazada_quantity_service'
@@ -34,6 +38,10 @@ class ItemBuilder
34
38
  def mode_check
35
39
  if mode == :quantity || mode == :simple
36
40
  quantity_simple_mode
41
+ elsif mode == :create || mode == :create_item
42
+ create_mode
43
+ elsif mode == :map_create
44
+ map_create_mode
37
45
  else
38
46
  default
39
47
  end
@@ -72,10 +80,37 @@ class ItemBuilder
72
80
  }
73
81
  end
74
82
 
75
- def default
83
+ def create_mode
84
+ item_listings.map do |listing|
85
+ param =
86
+ if listing.channel_id == 12
87
+ qty_simple_params(listing)
88
+ .merge(shipping_providers: shipping_providers)
89
+ else
90
+ qty_simple_params(listing)
91
+ end
92
+ modes[mode].new(param).perform
93
+ end
94
+ end
95
+
96
+ def map_create_mode
76
97
  listings.map do |listing|
77
- next unless listing.local_id.present?
98
+ modes[mode].new(qty_simple_params(listing)).perform
99
+ end
100
+ end
101
+
102
+ def default
103
+ datas =
104
+ if mode == :precondition_create
105
+ VariantListing.where(
106
+ channel_association_id: channel_association_ids,
107
+ profile_channel_association_id: account_id
108
+ )
109
+ else
110
+ listings
111
+ end
78
112
 
113
+ datas.map do |listing|
79
114
  if listing.channel_id == 2 && mode == :active
80
115
  modes[mode].new(qty_simple_params(listing)).perform
81
116
  elsif listing.channel_id == 18 && mode == :active
@@ -138,10 +173,26 @@ class ItemBuilder
138
173
  @listings ||= VariantListing.joins(:variant).where(id: listing_ids)
139
174
  end
140
175
 
176
+ def item_listings
177
+ @item_listings ||= VariantListing.joins(:variant).includes(:item_listing).where(
178
+ id: listing_ids
179
+ ).group(:channel_association_id)
180
+ end
181
+
182
+ def shipping_providers
183
+ @shipping_providers ||= ShopeeShippingProvider.where(
184
+ enabled: true, mask_channel_id: 0, account_id: account_id
185
+ )
186
+ end
187
+
141
188
  def skus
142
189
  @skus ||= listings.map(&:local_id).uniq
143
190
  end
144
191
 
192
+ def channel_association_ids
193
+ @listing_item_ids ||= listings.map(&:channel_association_id).uniq
194
+ end
195
+
145
196
  def zilingo_quantity
146
197
  @zilingo_quantity ||= ItemBuilder::ZilingoQuantityService.new(
147
198
  listings: listings, skus: skus
@@ -170,7 +221,12 @@ class ItemBuilder
170
221
  quantity: ItemBuilder::Modes::QuantityService,
171
222
  simple: ItemBuilder::Modes::SimpleService,
172
223
  active: ItemBuilder::Modes::ActiveService,
173
- update: ItemBuilder::Modes::UpdateService
224
+ update: ItemBuilder::Modes::CreateService,
225
+ create: ItemBuilder::Modes::CreateService,
226
+ map_create: ItemBuilder::Modes::MapCreateService,
227
+ precondition_create: ItemBuilder::Modes::CreateService,
228
+ precondition_update: ItemBuilder::Modes::CreateService,
229
+ item_create: ItemBuilder::Modes::CreateService,
174
230
  }
175
231
  end
176
232
 
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.58
4
+ version: 0.1.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-25 00:00:00.000000000 Z
11
+ date: 2022-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -121,6 +121,15 @@ files:
121
121
  - lib/item_builder/modes.rb
122
122
  - lib/item_builder/modes/active_service.rb
123
123
  - lib/item_builder/modes/base_service.rb
124
+ - lib/item_builder/modes/create/base.rb
125
+ - lib/item_builder/modes/create/shopee_service.rb
126
+ - lib/item_builder/modes/create_service.rb
127
+ - lib/item_builder/modes/map_create/base.rb
128
+ - lib/item_builder/modes/map_create/shopee_service.rb
129
+ - lib/item_builder/modes/map_create_service.rb
130
+ - lib/item_builder/modes/precondition_create/base.rb
131
+ - lib/item_builder/modes/precondition_create/shopee_service.rb
132
+ - lib/item_builder/modes/precondition_create_service.rb
124
133
  - lib/item_builder/modes/price/base.rb
125
134
  - lib/item_builder/modes/price/blibli_service.rb
126
135
  - lib/item_builder/modes/price/bukalapak_service.rb
@@ -166,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
175
  - !ruby/object:Gem::Version
167
176
  version: '0'
168
177
  requirements: []
169
- rubygems_version: 3.0.9
178
+ rubygems_version: 3.3.7
170
179
  signing_key:
171
180
  specification_version: 4
172
181
  summary: Item builder