tiny_builder 0.0.6 → 0.0.8

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: 0e74aed48d7a6bde96ec9e6dbaf479044bd2d551b59f47992e72e4169ce58da3
4
- data.tar.gz: 94ec01f9675a3d3b54dceb4ec3ebc749c1b2485a425156b6c5017b5eefb0a798
3
+ metadata.gz: 22641ae917f24c88375d9d8f5b1f0d58d85fc6096115c0ffa2cbdbbe87fa061e
4
+ data.tar.gz: 61b18b9375629dbc99a64670283247fa743e06378b9d24283f636ded0e1483c0
5
5
  SHA512:
6
- metadata.gz: 6ca8521dac8c51243a9372cb63fa67b934a675af3127dcc01aa79494c9e2ac3ff9507cde3207bf579b5d006769fee0b44c2f2a5827a89aa696f749223dcd073d
7
- data.tar.gz: c04d6de7140861ed1ab84e752d03595d0eafa7b0f184f6c269b5fe326591b3f6f8036c30ab5cd8b35e0d77726e647d1406852146295ee83e624ece9b3d63c4bd
6
+ metadata.gz: 485efb6ca5c4a783a1ef02ba7b8f929bd14a77df9112d1943ab7201c3154e2eebca034476d21f9f77a69635e9735512fdca795742a7d9a249bb3209b7b248f06
7
+ data.tar.gz: 01a0431d9ed7de8116d9676bf8f9d260da31129fad935c0c6d85a00fbfedfe1ff801de4a076a52581520a30d7dd47128a25591b622149924354d4005b0967c8e
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MongoWarehouseSpace
4
+ include Mongoid::Document
5
+
6
+ store_in collection: 'warehouse_spaces', client: 'inventory'
7
+
8
+ field :old_warehouse_id, as: :warehouse_id, type: Integer
9
+ field :quantity, type: Integer
10
+ field :item_variant_id, type: Integer
11
+ field :old_id, type: Integer
12
+ end
@@ -55,5 +55,16 @@ class TinyBuilder
55
55
  def shopify_location_url
56
56
  apigateway_url + '/shopify/data_location'
57
57
  end
58
+
59
+ def woocommerce_product_url
60
+ apigateway_url + '/woocommerce/item'
61
+ end
62
+
63
+ def woocommerce_item_payload(listing)
64
+ {
65
+ "credential": credential,
66
+ "data": { "local_item_id": listing.local_item_id, local_id: listing[:local_id] }
67
+ }.to_json
68
+ end
58
69
  end
59
70
  end
@@ -12,11 +12,13 @@ class TinyBuilder
12
12
  attr_reader :listings
13
13
  attr_reader :mwh
14
14
  attr_reader :channel_id
15
+ attr_reader :inventory_v2
15
16
 
16
17
  def initialize(args)
17
18
  @listings = args[:listings]
18
19
  @mwh = args[:mwh]
19
20
  @channel_id = args[:channel_id]
21
+ @inventory_v2 = args[:inventory_v2]
20
22
  end
21
23
 
22
24
  def perform
@@ -64,7 +64,15 @@ class TinyBuilder
64
64
  end
65
65
 
66
66
  def warehouse_spaces
67
- @warehouse_spaces ||= WarehouseSpace.where(item_variant_id: variant_ids).where.not(warehouse_id: nil)
67
+ @warehouse_spaces ||= get_warehouse_spaces
68
+ end
69
+
70
+ def get_warehouse_spaces
71
+ if inventory_v2
72
+ MongoWarehouseSpace.where(item_variant_id: variant_ids, :warehouse_id.exists => true).map{ |ws| ws }
73
+ else
74
+ WarehouseSpace.where(item_variant_id: variant_ids).where.not(warehouse_id: nil)
75
+ end
68
76
  end
69
77
 
70
78
  def listing_warehouse_spaces(listing)
@@ -6,7 +6,8 @@ class TinyBuilder
6
6
  builder_classes[mode].new(
7
7
  listings: listings,
8
8
  mwh: mwh,
9
- channel_id: credential['channel_id']
9
+ channel_id: credential['channel_id'],
10
+ inventory_v2: credential['inventory_v2']
10
11
  ).perform
11
12
  end
12
13
 
@@ -35,6 +36,8 @@ class TinyBuilder
35
36
  TinyBuilder::ZaloraQuantity.new(credential, listings).perform
36
37
  elsif credential['channel_id'] == 2
37
38
  TinyBuilder::ShopifyQuantity.new(credential, listings).perform
39
+ elsif credential['channel_id'] == 19
40
+ TinyBuilder::WoocommerceQuantity.new(credential, listings).perform
38
41
  end
39
42
  end
40
43
  end
@@ -9,11 +9,15 @@ class TinyBuilder
9
9
  end
10
10
 
11
11
  def channel_data(listing)
12
- if channel_id = 2
12
+ if channel_id == 2
13
13
  {
14
14
  inventory_item_id: listing[:inventory_item_id],
15
15
  location_id: listing[:location_id]
16
16
  }
17
+ elsif channel_id == 19
18
+ {
19
+ meta_location_id: listing[:meta_location_id]
20
+ }
17
21
  else
18
22
  {}
19
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TinyBuilder
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.8'
5
5
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TinyBuilder
4
+ class WoocommerceQuantity
5
+ include ApigatewayHelper
6
+
7
+ attr_reader :credential
8
+ attr_reader :listings
9
+
10
+ def initialize(credential, listings)
11
+ @credential = credential
12
+ @listings = listings
13
+ end
14
+
15
+ def perform
16
+ listings.each do |listing|
17
+ assign_location_id(listing)
18
+ listing.save
19
+ end
20
+ end
21
+
22
+ def assign_location_id(listing)
23
+ return unless listing[:meta_location_id].blank?
24
+
25
+ begin
26
+ listing[:meta_location_id] = meta_location_id(listing)
27
+ rescue
28
+ listing[:wocommerce_last_log] = "Error when getting woocommerce location_id"
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def meta_location_id(listing)
35
+ args = {
36
+ method: :post,
37
+ url: woocommerce_product_url,
38
+ payload: woocommerce_item_payload(listing),
39
+ headers: headers
40
+ }
41
+
42
+ resp = JSON.parse(rest_client(args, [200, 402]))
43
+ data = Array.wrap(resp['meta_data']).find { |meta_data| meta_data['key'] == 'smifw_location_stocks' }
44
+ data ? data['id'] : nil
45
+ end
46
+ end
47
+ end
data/lib/tiny_builder.rb CHANGED
@@ -12,6 +12,7 @@ require 'tiny_builder/quantity_builder'
12
12
  require 'tiny_builder/apigateway_helper'
13
13
  require 'tiny_builder/zalora_quantity'
14
14
  require 'tiny_builder/shopify_quantity'
15
+ require 'tiny_builder/woocommerce_quantity'
15
16
 
16
17
  class TinyBuilder
17
18
  include ModeExecutor
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - hayakaza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-08 00:00:00.000000000 Z
11
+ date: 2024-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,7 @@ files:
132
132
  - lib/models/master_product.rb
133
133
  - lib/models/mongo_item_listing.rb
134
134
  - lib/models/mongo_variant_listing.rb
135
+ - lib/models/mongo_warehouse_space.rb
135
136
  - lib/tiny_builder.rb
136
137
  - lib/tiny_builder/active_builder.rb
137
138
  - lib/tiny_builder/allocated_stock.rb
@@ -145,6 +146,7 @@ files:
145
146
  - lib/tiny_builder/quantity_helper.rb
146
147
  - lib/tiny_builder/shopify_quantity.rb
147
148
  - lib/tiny_builder/version.rb
149
+ - lib/tiny_builder/woocommerce_quantity.rb
148
150
  - lib/tiny_builder/zalora_quantity.rb
149
151
  homepage:
150
152
  licenses: []