item_models 0.0.13 → 0.0.16

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: fa90ceaa3413fb8f1eff246593217cb54a380e8e6fb5b06ee31b1bdd2cf07ac1
4
- data.tar.gz: f5e889db45c50e4a2a640f23998d12b615e31f1619bec7618ff92ff002fea366
3
+ metadata.gz: 2bb9091dc58e62a90422baf821b798b08387d1b13e4c9bfbf3d519e26dda5cae
4
+ data.tar.gz: 3675c282105208b2d61e91c187479232110fe9278c076684517c768faf161c4e
5
5
  SHA512:
6
- metadata.gz: f0446a42158a50ae996d0b3d9a551c711c320e485a43e3696ee5ba442b9d8aba8108e6917086707c0bd699b0f6b088f29d9e3e9795af510102a6b89d7acc1273
7
- data.tar.gz: 0f83a1f14e3083d918a062fcb8220161815e7e1a6dd2de336f7fc5e47f71a8ecae1c1e5c8860aadb398641f735c4e03211ea1d11d7bc4ae055e1f9c7f17c68f7
6
+ metadata.gz: a02f15bfc3f2f3cbac0b036acad9fac5a30c85c365b4b047ca937b5bb54338de3166b6ab07469779ca1eb55acd07ec58acc31b825654d8aa1620b41f49442321
7
+ data.tar.gz: 63e1a4e82230dec57a8f3090f34cac08a45bf71021f71ad9ef8ca9217f2d782138554d0cb0d891310e0956f50044d8191981d5ac424bb39f4afc8ca396287b7d
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ItemModels
4
- VERSION = '0.0.13'
4
+ VERSION = '0.0.16'
5
5
  end
data/lib/models/bundle.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class Bundle < ItemApplicationRecord
4
5
  self.table_name = 'item_bundles'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :variant
7
9
  belongs_to :item
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class BundleVariant < ItemApplicationRecord
4
5
  self.table_name = 'item_bundle_variants'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :bundle
7
9
  belongs_to :variant
@@ -0,0 +1,28 @@
1
+ module Restorable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ acts_as_paranoid column: :removed, sentinel_value: false
6
+ acts_as_paranoid column: :removed_at, sentinel_value: false
7
+
8
+ # It seems paranoia bug: method_missing `deleted_at`
9
+ # when restore with `recovery_window`
10
+ alias_attribute :deleted_at, :removed_at
11
+
12
+ private
13
+
14
+ def paranoia_restore_attributes
15
+ {
16
+ removed_at: nil,
17
+ removed: false
18
+ }
19
+ end
20
+
21
+ def paranoia_destroy_attributes
22
+ {
23
+ removed_at: current_time_from_proper_timezone,
24
+ removed: nil
25
+ }
26
+ end
27
+ end
28
+ end
data/lib/models/image.rb CHANGED
@@ -1,11 +1,103 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class Image < ItemApplicationRecord
4
5
  self.table_name = 'item_images'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :item
7
9
  has_many :item_listing_images
8
10
  has_many :variant_images, foreign_key: :item_image_id
9
11
  has_many :master_catalog_images
10
12
  has_many :item_listing_variant_custom_fields
13
+
14
+ has_attached_file :image,
15
+ path: '/system/item/:class/:attachment/:id_partition/:style/:fingerprint.:extension',
16
+ default_url: lambda { |attach|
17
+ attach.instance.url || '/public/missing/missing-item.jpg'
18
+ },
19
+ styles: lambda { |attachment|
20
+ object = attachment.instance.image.queued_for_write[:original]
21
+ width, height =
22
+ if object
23
+ FastImage.size(object) || [0,0]
24
+ else
25
+ [(attachment.instance.width || 500), (attachment.instance.height || 500)]
26
+ end
27
+
28
+ dim = [width, height]
29
+ clamped_dim = dim.max && [600, dim.max, 2000].sort[1]
30
+ big_clamped_dim = dim.max && [1100, dim.max, 2000].sort[1]
31
+
32
+ # max hxw and ratio (1100 x 762)
33
+ ratio_381_550 = 1100/762.to_f
34
+ real_ratio = height/width.to_f
35
+
36
+ # If real ratio is smaller, then width is thicker than desired width, therefor
37
+ # adjust height to fit desired ratio.
38
+ if real_ratio < ratio_381_550
39
+ w_381_550 = width
40
+ h_381_550 = width * ratio_381_550
41
+ else
42
+ w_381_550 = height / ratio_381_550
43
+ h_381_550 = height
44
+ end
45
+
46
+ {
47
+ xlarge: {
48
+ geometry: '1600x1600>',
49
+ format: :jpg,
50
+ convert_options: '-strip -interlace Plane -background white -alpha remove -flatten -alpha off'
51
+ },
52
+ large: {
53
+ geometry: '1000x1000>',
54
+ format: :jpg,
55
+ convert_options: '-strip -interlace Plane -background white -alpha remove -flatten -alpha off'
56
+ },
57
+ medium: {
58
+ geometry: '800x800>',
59
+ format: :jpg,
60
+ convert_options: '-strip -interlace Plane -background white -alpha remove -flatten -alpha off'
61
+ },
62
+ small: {
63
+ geometry: '500x500>',
64
+ format: :jpg,
65
+ convert_options: '-strip -interlace Plane -background white -alpha remove -flatten -alpha off'
66
+ },
67
+ thumb: {
68
+ geometry: '100x100>',
69
+ format: :jpg,
70
+ convert_options: '-strip -interlace Plane -background white -alpha remove -flatten -alpha off'
71
+ },
72
+ marketplace: {
73
+ geometry: '500x500<',
74
+ format: :jpg,
75
+ convert_options: '-strip -interlace Plane -background white -alpha remove -flatten -alpha off'
76
+ },
77
+ # Lazada needs colorspace to be sRGB. CMYK colorspace will produce error
78
+ square: {
79
+ geometry: dim.max && dim.max < 600 ? '600x600<' : '2000x2000>',
80
+ format: :jpg,
81
+ convert_options: "-strip -colorspace sRGB -interlace Plane -background white -alpha remove -flatten -alpha off -gravity center -extent #{clamped_dim}x#{clamped_dim}"
82
+ },
83
+ # Zalora
84
+ big_square: {
85
+ geometry: dim.max && dim.max < 1100 ? '1100x1100<' : '2000x2000>',
86
+ format: :jpg,
87
+ convert_options: "-strip -colorspace sRGB -interlace Plane -background white -alpha remove -flatten -alpha off -gravity center -extent #{big_clamped_dim}x#{big_clamped_dim}"
88
+ },
89
+ # lyke
90
+ ratio_381_550: {
91
+ geometry: w_381_550 <= 762 ? '762x1100<' : '762x1100>',
92
+ format: :jpeg,
93
+ convert_options: "-strip -colorspace sRGB -interlace Plane -background white -alpha remove -flatten -alpha off -gravity center -extent 762x1100"
94
+ },
95
+ # elevenia
96
+ width_780_or_less: {
97
+ geometry: '780x>',
98
+ format: :jpg,
99
+ convert_options: '-strip -interlace Plane -background white -alpha remove -flatten -alpha off'
100
+ }
101
+ }
102
+ }
11
103
  end
data/lib/models/item.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class Item < ItemApplicationRecord
5
+ include ::Restorable
6
+
4
7
  has_many :variants
5
8
  has_many :item_listings
6
9
  has_many :bundles
@@ -1,15 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class ItemListing < ItemApplicationRecord
4
5
  self.table_name = 'item_channel_associations'
6
+ include ::Restorable
7
+
5
8
  belongs_to :item
6
9
  has_many :variant_listings, foreign_key: :channel_association_id
7
10
  has_many :item_listing_images, foreign_key: :channel_association_id
8
- has_many :item_listing_categories, foreign_key: :channel_association_id
9
- has_many :item_listing_brands, foreign_key: :channel_association_id
11
+ has_one :item_listing_category, foreign_key: :channel_association_id
12
+ has_one :item_listing_brand, foreign_key: :channel_association_id
10
13
  has_many :item_listing_variant_custom_fields, foreign_key: :channel_association_id
11
14
  has_many :item_listing_custom_fields, foreign_key: :channel_association_id
12
15
  has_many :item_listing_variant_images, foreign_key: :channel_association_id
16
+ has_many :images,
17
+ class_name: 'ItemListingImage',
18
+ dependent: :destroy,
19
+ autosave: true,
20
+ foreign_key: :channel_association_id
13
21
  has_one :category,
14
22
  dependent: :destroy,
15
23
  autosave: true
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class ItemListingBrand < ItemApplicationRecord
4
5
  self.table_name = 'item_channel_association_brands'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :item_listing, foreign_key: :channel_association_id
9
+ belongs_to :shopee,
10
+ class_name: 'ShopeeBrand',
11
+ foreign_key: :shopee_brand_id,
12
+ optional: true
7
13
  end
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class ItemListingCategory < ItemApplicationRecord
4
5
  self.table_name = 'item_channel_association_categories'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :item_listing, foreign_key: :channel_association_id
9
+ belongs_to :shopee,
10
+ class_name: 'ShopeeCategory',
11
+ foreign_key: :shopee_category_id,
12
+ optional: true
7
13
  end
@@ -1,8 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class ItemListingCustomField < ItemApplicationRecord
4
5
  self.table_name = 'item_channel_association_custom_fields'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :item_listing, foreign_key: :channel_association_id
7
9
  belongs_to :variant
10
+ belongs_to :shopee,
11
+ class_name: 'ShopeeItemCustomField',
12
+ foreign_key: :shopee_item_custom_field_id,
13
+ optional: true
14
+
15
+ serialize :value
8
16
  end
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class ItemListingImage < ItemApplicationRecord
4
5
  self.table_name = 'item_channel_association_images'
6
+ include ::Restorable
7
+
5
8
  belongs_to :image
6
9
  belongs_to :item_listing, foreign_key: :channel_association_id
7
10
  end
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemListingVariantCustomField < ItemApplicationRecord
4
- self.table_name = 'item_channel_association_variant_images'
4
+ self.table_name = 'item_channel_association_variant_custom_fields'
5
5
 
6
6
  belongs_to :item_listing, foreign_key: :channel_association_id
7
7
  belongs_to :variant
8
8
  belongs_to :image
9
+ belongs_to :shopee,
10
+ class_name: 'ShopeeItemVariantCustomField',
11
+ foreign_key: :shopee_item_variant_custom_field_id,
12
+ optional: true
9
13
  end
@@ -2,4 +2,8 @@
2
2
 
3
3
  class ItemListingVariantImage < ItemApplicationRecord
4
4
  self.table_name = 'item_channel_association_variant_images'
5
+
6
+ belongs_to :image,
7
+ class_name: 'Image',
8
+ optional: true
5
9
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ShopeeBrand < ItemApplicationRecord
4
+ self.table_name = 'channel_shopee_brands'
5
+
6
+ has_many :item_listing_brands,
7
+ class_name: 'ItemListingBrand',
8
+ foreign_key: :shopee_brand_id
9
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ShopeeCategory < ItemApplicationRecord
4
+ self.table_name = 'channel_shopee_categories'
5
+
6
+ belongs_to :parent_category,
7
+ class_name: 'ShopeeCategory',
8
+ foreign_key: :parent_category_id,
9
+ optional: true
10
+ belongs_to :primary_category,
11
+ class_name: 'ShopeeCategory',
12
+ foreign_key: :primary_category_id,
13
+ optional: true
14
+ has_many :child_categories,
15
+ class_name: 'ShopeeCategory',
16
+ foreign_key: :parent_category_id,
17
+ dependent: :destroy
18
+
19
+ has_many :item_channel_association_categories,
20
+ class_name: '::ItemListingCategory',
21
+ foreign_key: :shopee_category_id
22
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ShopeeItemCustomField < ItemApplicationRecord
4
+ self.table_name = 'channel_shopee_item_custom_fields'
5
+
6
+ has_many :associated_custom_fields, class_name: 'ItemListingCustomField'
7
+ has_many :options, foreign_key: :custom_field_id, class_name: 'ShopeeItemCustomFieldOption'
8
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ShopeeItemCustomFieldOption < ItemApplicationRecord
4
+ self.table_name = 'channel_shopee_item_custom_field_options'
5
+
6
+ belongs_to :custom_field,
7
+ class_name: 'ShopeeItemCustomField',
8
+ foreign_key: :custom_field_id,
9
+ optional: true
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ShopeeItemVariantCustomField < ItemApplicationRecord
4
+ self.table_name = 'channel_shopee_variant_custom_fields'
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ShopeeLogisticAddress < ItemApplicationRecord
4
+ self.table_name = 'channel_shopee_logistic_addresses'
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ShopeeShippingProvider < ItemApplicationRecord
4
+ self.table_name = 'channel_shopee_shipping_providers'
5
+ end
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class Variant < ItemApplicationRecord
4
5
  self.table_name = 'item_variants'
6
+ include ::Restorable
7
+
5
8
  belongs_to :item
6
9
  has_many :variant_images, foreign_key: :item_variant_id
7
10
  has_many :bundles
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class VariantImage < ItemApplicationRecord
4
5
  self.table_name = 'item_variant_images'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :image
7
9
  belongs_to :variant
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class VariantListing < ItemApplicationRecord
4
5
  self.table_name = 'item_channel_association_variant_associations'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :variant
7
9
  belongs_to :item_listing, foreign_key: :channel_association_id
@@ -9,4 +11,28 @@ class VariantListing < ItemApplicationRecord
9
11
  class_name: 'VariantListingStockAllocation',
10
12
  foreign_key: :variant_association_id
11
13
  has_many :variant_listing_price_histories, foreign_key: :variant_association_id
14
+
15
+ serialize :option2_value
16
+ serialize :option_value
17
+ serialize :name_option
18
+ serialize :qc_reason
19
+ serialize :last_log
20
+ serialize :bukalapak_free_shipping
21
+ serialize :shopee_shipping_providers
22
+ serialize :description
23
+ serialize :description_unique_selling_point
24
+
25
+ def item_listing_custom_fields
26
+ ItemListingCustomField.where("channel_association_id = ? AND variant_id = ?", self.channel_association_id, self.variant_id)
27
+ end
28
+
29
+ def item_listing_variant_custom_fields
30
+ ItemListingVariantCustomField.where("channel_association_id = ? AND variant_id = ?", self.channel_association_id, self.variant_id)
31
+ end
32
+
33
+ def item_listing_variant_images
34
+ ItemListingVariantImage.where(
35
+ "channel_association_id = ? AND variant_id = ? AND account_id = ?", self.channel_association_id, self.variant_id, self.profile_channel_association_id
36
+ )
37
+ end
12
38
  end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class VariantOption < ItemApplicationRecord
4
5
  self.table_name = 'item_variant_options'
6
+ include ::Restorable
5
7
 
6
8
  has_many :variant_option_associations, foreign_key: :option_id
7
9
  end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'concerns/restorable'
3
4
  class VariantOptionAssociation < ItemApplicationRecord
4
5
  self.table_name = 'item_variant_option_associations'
6
+ include ::Restorable
5
7
 
6
8
  belongs_to :variant_option, foreign_key: :option_id
7
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: item_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - alexander
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-13 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
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description:
55
+ description:
56
56
  email:
57
57
  - alxibra@gmail.com
58
58
  executables: []
@@ -65,6 +65,7 @@ files:
65
65
  - lib/models/availability_option.rb
66
66
  - lib/models/bundle.rb
67
67
  - lib/models/bundle_variant.rb
68
+ - lib/models/concerns/restorable.rb
68
69
  - lib/models/image.rb
69
70
  - lib/models/item.rb
70
71
  - lib/models/item_application_record.rb
@@ -77,6 +78,13 @@ files:
77
78
  - lib/models/item_listing_variant_image.rb
78
79
  - lib/models/master_catalog.rb
79
80
  - lib/models/master_catalog_image.rb
81
+ - lib/models/shopee_brand.rb
82
+ - lib/models/shopee_category.rb
83
+ - lib/models/shopee_item_custom_field.rb
84
+ - lib/models/shopee_item_custom_field_option.rb
85
+ - lib/models/shopee_item_variant_custom_field.rb
86
+ - lib/models/shopee_logistic_address.rb
87
+ - lib/models/shopee_shipping_provider.rb
80
88
  - lib/models/variant.rb
81
89
  - lib/models/variant_image.rb
82
90
  - lib/models/variant_listing.rb
@@ -84,11 +92,11 @@ files:
84
92
  - lib/models/variant_listing_stock_allocation.rb
85
93
  - lib/models/variant_option.rb
86
94
  - lib/models/variant_option_association.rb
87
- homepage:
95
+ homepage:
88
96
  licenses:
89
97
  - MIT
90
98
  metadata: {}
91
- post_install_message:
99
+ post_install_message:
92
100
  rdoc_options: []
93
101
  require_paths:
94
102
  - lib
@@ -104,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
112
  - !ruby/object:Gem::Version
105
113
  version: '0'
106
114
  requirements: []
107
- rubygems_version: 3.0.3
108
- signing_key:
115
+ rubygems_version: 3.3.7
116
+ signing_key:
109
117
  specification_version: 4
110
118
  summary: gem for active record item models
111
119
  test_files: []