shopify_product_taxonomy 1.0.0 → 1.1.0
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 +4 -4
- data/lib/product_taxonomy/loader.rb +9 -2
- data/lib/product_taxonomy/models/category.rb +26 -2
- data/lib/product_taxonomy/models/mixins/localized.rb +1 -1
- data/lib/product_taxonomy/models/return_reason.rb +88 -0
- data/lib/product_taxonomy/models/serializers/category/data/data_serializer.rb +9 -0
- data/lib/product_taxonomy/models/serializers/category/dist/json_serializer.rb +8 -0
- data/lib/product_taxonomy/models/serializers/category/docs/search_serializer.rb +1 -1
- data/lib/product_taxonomy/models/serializers/category/docs/siblings_serializer.rb +1 -0
- data/lib/product_taxonomy/models/serializers/return_reason/data/data_serializer.rb +34 -0
- data/lib/product_taxonomy/models/serializers/return_reason/data/localizations_serializer.rb +39 -0
- data/lib/product_taxonomy/models/serializers/return_reason/dist/json_serializer.rb +35 -0
- data/lib/product_taxonomy/models/serializers/return_reason/dist/txt_serializer.rb +46 -0
- data/lib/product_taxonomy/models/serializers/return_reason/docs/base_serializer.rb +29 -0
- data/lib/product_taxonomy/models/serializers/return_reason/docs/reversed_serializer.rb +49 -0
- data/lib/product_taxonomy/models/serializers/return_reason/docs/search_serializer.rb +32 -0
- data/lib/product_taxonomy/version.rb +1 -1
- data/lib/product_taxonomy.rb +25 -0
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 68f41afc40ad1e0c0d16d45e41f105c984d6e5159621f4417ab16270ccb56af7
|
|
4
|
+
data.tar.gz: 776eb4172eef466640e468c485aa07bd6cd18bd012bc91f1dfbdca767e1ef98e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 06a00c7523ff2d8c6d5cae5f5d1d7624cebee3021e684c56852d03cd041d622a7f0af759737559a70c4d4e68885c221770f807e356ced05f6d61ac105d77c40a
|
|
7
|
+
data.tar.gz: 2f2e4747e3cfeead16b45478c5bf858869ffe3a213bca7ea22bd7b385d08f0aa3b02ca0c8a72c0199d96e3172e78164e1b93c5df2546db30f49c77eb9ae3f144
|
|
@@ -5,12 +5,20 @@ require "yaml"
|
|
|
5
5
|
module ProductTaxonomy
|
|
6
6
|
class Loader
|
|
7
7
|
class << self
|
|
8
|
-
def load(
|
|
8
|
+
def load(data_path:)
|
|
9
|
+
ProductTaxonomy.data_path = data_path
|
|
10
|
+
|
|
9
11
|
return if ProductTaxonomy::Category.all.any?
|
|
10
12
|
|
|
13
|
+
values_path = File.join(data_path, "values.yml")
|
|
14
|
+
attributes_path = File.join(data_path, "attributes.yml")
|
|
15
|
+
return_reasons_path = File.join(data_path, "return_reasons.yml")
|
|
16
|
+
categories_glob = Dir.glob(File.join(data_path, "categories", "*.yml"))
|
|
17
|
+
|
|
11
18
|
begin
|
|
12
19
|
ProductTaxonomy::Value.load_from_source(YAML.load_file(values_path))
|
|
13
20
|
ProductTaxonomy::Attribute.load_from_source(YAML.load_file(attributes_path))
|
|
21
|
+
ProductTaxonomy::ReturnReason.load_from_source(YAML.load_file(return_reasons_path))
|
|
14
22
|
|
|
15
23
|
categories_source_data = categories_glob.each_with_object([]) do |file, array|
|
|
16
24
|
array.concat(YAML.safe_load_file(file))
|
|
@@ -28,4 +36,3 @@ module ProductTaxonomy
|
|
|
28
36
|
end
|
|
29
37
|
end
|
|
30
38
|
end
|
|
31
|
-
|
|
@@ -22,6 +22,7 @@ module ProductTaxonomy
|
|
|
22
22
|
id: item["id"],
|
|
23
23
|
name: item["name"],
|
|
24
24
|
attributes: Array(item["attributes"]).map { Attribute.find_by(friendly_id: _1) || _1 },
|
|
25
|
+
return_reasons: Array(item["return_reasons"]).map { ReturnReason.find_by(friendly_id: _1) || _1 },
|
|
25
26
|
)
|
|
26
27
|
end
|
|
27
28
|
|
|
@@ -37,6 +38,7 @@ module ProductTaxonomy
|
|
|
37
38
|
node.validate!(:category_tree_loaded)
|
|
38
39
|
node.children.sort_by!(&:name)
|
|
39
40
|
node.attributes.sort_by!(&:name)
|
|
41
|
+
# `return_reasons` order is intentionally preserved from `data/categories/*.yml`.
|
|
40
42
|
root_nodes << node if node.root?
|
|
41
43
|
end
|
|
42
44
|
@verticals.sort_by!(&:name)
|
|
@@ -74,6 +76,7 @@ module ProductTaxonomy
|
|
|
74
76
|
validates :id, format: { with: /\A[a-z]{2}(-\d+)*\z/ }, on: :create
|
|
75
77
|
validates :name, presence: true, on: :create
|
|
76
78
|
validate :attributes_found?, on: :create
|
|
79
|
+
validate :return_reasons_found?, on: :create
|
|
77
80
|
validates_with ProductTaxonomy::Indexed::UniquenessValidator, attributes: [:id], on: :create
|
|
78
81
|
|
|
79
82
|
# Validations that can only be performed after the category tree has been loaded.
|
|
@@ -84,19 +87,21 @@ module ProductTaxonomy
|
|
|
84
87
|
|
|
85
88
|
localized_attr_reader :name, keyed_by: :id
|
|
86
89
|
|
|
87
|
-
attr_reader :id, :children, :secondary_children, :attributes
|
|
90
|
+
attr_reader :id, :children, :secondary_children, :attributes, :return_reasons
|
|
88
91
|
attr_accessor :parent, :secondary_parents
|
|
89
92
|
|
|
90
93
|
# @param id [String] The ID of the category.
|
|
91
94
|
# @param name [String] The name of the category.
|
|
92
95
|
# @param attributes [Array<Attribute>] The attributes of the category.
|
|
96
|
+
# @param return_reasons [Array<ReturnReason>] The return reasons for the category.
|
|
93
97
|
# @param parent [Category] The parent category of the category.
|
|
94
|
-
def initialize(id:, name:, attributes: [], parent: nil)
|
|
98
|
+
def initialize(id:, name:, attributes: [], return_reasons: [], parent: nil)
|
|
95
99
|
@id = id
|
|
96
100
|
@name = name
|
|
97
101
|
@children = []
|
|
98
102
|
@secondary_children = []
|
|
99
103
|
@attributes = attributes
|
|
104
|
+
@return_reasons = return_reasons
|
|
100
105
|
@parent = parent
|
|
101
106
|
@secondary_parents = []
|
|
102
107
|
end
|
|
@@ -134,6 +139,13 @@ module ProductTaxonomy
|
|
|
134
139
|
@attributes << attribute
|
|
135
140
|
end
|
|
136
141
|
|
|
142
|
+
# Add a return reason to the category
|
|
143
|
+
#
|
|
144
|
+
# @param [ReturnReason] return_reason
|
|
145
|
+
def add_return_reason(return_reason)
|
|
146
|
+
@return_reasons << return_reason
|
|
147
|
+
end
|
|
148
|
+
|
|
137
149
|
#
|
|
138
150
|
# Information
|
|
139
151
|
#
|
|
@@ -286,6 +298,18 @@ module ProductTaxonomy
|
|
|
286
298
|
end
|
|
287
299
|
end
|
|
288
300
|
|
|
301
|
+
def return_reasons_found?
|
|
302
|
+
return_reasons&.each do |return_reason|
|
|
303
|
+
next if return_reason.is_a?(ReturnReason)
|
|
304
|
+
|
|
305
|
+
errors.add(
|
|
306
|
+
:return_reasons,
|
|
307
|
+
:not_found,
|
|
308
|
+
message: "not found for friendly ID \"#{return_reason}\"",
|
|
309
|
+
)
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
289
313
|
def children_found?
|
|
290
314
|
children&.each do |child|
|
|
291
315
|
next if child.is_a?(Category)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProductTaxonomy
|
|
4
|
+
class ReturnReason
|
|
5
|
+
include ActiveModel::Validations
|
|
6
|
+
include FormattedValidationErrors
|
|
7
|
+
extend Localized
|
|
8
|
+
extend Indexed
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
# Override to match folder name convention (return_reasons vs returnreasons)
|
|
12
|
+
def localizations_humanized_model_name
|
|
13
|
+
"return_reasons"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Load return reasons from source data. By default, this data is deserialized from a YAML file in the `data` directory.
|
|
17
|
+
#
|
|
18
|
+
# @param source_data [Array<Hash>] The source data to load return reasons from.
|
|
19
|
+
# @return [void]
|
|
20
|
+
def load_from_source(source_data)
|
|
21
|
+
raise ArgumentError, "source_data must be an array" unless source_data.is_a?(Array)
|
|
22
|
+
|
|
23
|
+
source_data.each do |return_reason_data|
|
|
24
|
+
raise ArgumentError, "source_data must contain hashes" unless return_reason_data.is_a?(Hash)
|
|
25
|
+
|
|
26
|
+
return_reason = return_reason_from(return_reason_data)
|
|
27
|
+
ReturnReason.add(return_reason)
|
|
28
|
+
return_reason.validate!(:create)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Reset all class-level state
|
|
33
|
+
def reset
|
|
34
|
+
@localizations = nil
|
|
35
|
+
@hashed_models = nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Get the next ID for a newly created return reason.
|
|
39
|
+
#
|
|
40
|
+
# @return [Integer] The next ID.
|
|
41
|
+
def next_id = (all.max_by(&:id)&.id || 0) + 1
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def return_reason_from(return_reason_data)
|
|
46
|
+
ReturnReason.new(
|
|
47
|
+
id: return_reason_data["id"],
|
|
48
|
+
name: return_reason_data["name"],
|
|
49
|
+
description: return_reason_data["description"],
|
|
50
|
+
friendly_id: return_reason_data["friendly_id"],
|
|
51
|
+
handle: return_reason_data["handle"],
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
validates :id, presence: true, numericality: { only_integer: true }, on: :create
|
|
57
|
+
validates :name, presence: true, on: :create
|
|
58
|
+
validates :friendly_id, presence: true, on: :create
|
|
59
|
+
validates :handle, presence: true, on: :create
|
|
60
|
+
validates :description, presence: true, on: :create
|
|
61
|
+
validates_with ProductTaxonomy::Indexed::UniquenessValidator, attributes: [:friendly_id], on: :create
|
|
62
|
+
|
|
63
|
+
localized_attr_reader :name, :description
|
|
64
|
+
|
|
65
|
+
attr_reader :id, :friendly_id, :handle
|
|
66
|
+
|
|
67
|
+
# @param id [Integer] The ID of the return reason.
|
|
68
|
+
# @param name [String] The name of the return reason.
|
|
69
|
+
# @param description [String] The description of the return reason.
|
|
70
|
+
# @param friendly_id [String] The friendly ID of the return reason.
|
|
71
|
+
# @param handle [String] The handle of the return reason.
|
|
72
|
+
def initialize(id:, name:, description:, friendly_id:, handle:)
|
|
73
|
+
@id = id
|
|
74
|
+
@name = name
|
|
75
|
+
@description = description
|
|
76
|
+
@friendly_id = friendly_id
|
|
77
|
+
@handle = handle
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# The global ID of the return reason
|
|
81
|
+
#
|
|
82
|
+
# @return [String]
|
|
83
|
+
def gid
|
|
84
|
+
"gid://shopify/ReturnReasonDefinition/#{id}"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
@@ -14,11 +14,20 @@ module ProductTaxonomy
|
|
|
14
14
|
# @param [Category] category
|
|
15
15
|
# @return [Hash]
|
|
16
16
|
def serialize(category)
|
|
17
|
+
return_reason_ids = category.return_reasons.map(&:friendly_id)
|
|
18
|
+
has_unknown = return_reason_ids.delete('unknown')
|
|
19
|
+
has_other = return_reason_ids.delete('other')
|
|
20
|
+
|
|
21
|
+
sorted_return_reasons = AlphanumericSorter.sort(return_reason_ids)
|
|
22
|
+
sorted_return_reasons += ['unknown'] if has_unknown
|
|
23
|
+
sorted_return_reasons += ['other'] if has_other
|
|
24
|
+
|
|
17
25
|
{
|
|
18
26
|
"id" => category.id,
|
|
19
27
|
"name" => category.name,
|
|
20
28
|
"children" => category.children.sort_by(&:id_parts).map(&:id),
|
|
21
29
|
"attributes" => AlphanumericSorter.sort(category.attributes.map(&:friendly_id), other_last: true),
|
|
30
|
+
"return_reasons" => sorted_return_reasons,
|
|
22
31
|
}
|
|
23
32
|
end
|
|
24
33
|
end
|
|
@@ -38,6 +38,14 @@ module ProductTaxonomy
|
|
|
38
38
|
"extended" => attr.is_a?(ExtendedAttribute),
|
|
39
39
|
}
|
|
40
40
|
end,
|
|
41
|
+
"return_reasons" => category.return_reasons.map do |return_reason|
|
|
42
|
+
{
|
|
43
|
+
"id" => return_reason.gid,
|
|
44
|
+
"name" => return_reason.name(locale:),
|
|
45
|
+
"handle" => return_reason.handle,
|
|
46
|
+
"description" => return_reason.description(locale:),
|
|
47
|
+
}
|
|
48
|
+
end,
|
|
41
49
|
"children" => category.children.map do |child|
|
|
42
50
|
{
|
|
43
51
|
"id" => child.gid,
|
|
@@ -7,7 +7,7 @@ module ProductTaxonomy
|
|
|
7
7
|
module SearchSerializer
|
|
8
8
|
class << self
|
|
9
9
|
def serialize_all
|
|
10
|
-
ProductTaxonomy::Category.all_depth_first.
|
|
10
|
+
ProductTaxonomy::Category.all_depth_first.map { serialize(_1) }
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
# @param [Category] category
|
|
@@ -29,6 +29,7 @@ module ProductTaxonomy
|
|
|
29
29
|
"node_type" => category.root? ? "root" : "leaf",
|
|
30
30
|
"ancestor_ids" => category.ancestors.map(&:gid).join(","),
|
|
31
31
|
"attribute_handles" => category.attributes.map(&:handle).join(","),
|
|
32
|
+
"return_reason_handles" => category.return_reasons.map(&:handle).join(","),
|
|
32
33
|
}
|
|
33
34
|
end
|
|
34
35
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProductTaxonomy
|
|
4
|
+
module Serializers
|
|
5
|
+
module ReturnReason
|
|
6
|
+
module Data
|
|
7
|
+
module DataSerializer
|
|
8
|
+
class << self
|
|
9
|
+
# @return [Array<Hash>] Array of serialized return data
|
|
10
|
+
def serialize_all
|
|
11
|
+
ProductTaxonomy::ReturnReason.all.sort_by(&:id).map { serialize(_1) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @param return_reason [ReturnReason] The return reason to serialize
|
|
15
|
+
# @return [Hash] Hash containing the return reason data
|
|
16
|
+
def serialize(return_reason)
|
|
17
|
+
{
|
|
18
|
+
"id" => return_reason.id,
|
|
19
|
+
"name" => return_reason.name,
|
|
20
|
+
"description" => return_reason.description,
|
|
21
|
+
"friendly_id" => return_reason.friendly_id,
|
|
22
|
+
"handle" => return_reason.handle,
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProductTaxonomy
|
|
4
|
+
module Serializers
|
|
5
|
+
module ReturnReason
|
|
6
|
+
module Data
|
|
7
|
+
class LocalizationsSerializer
|
|
8
|
+
class << self
|
|
9
|
+
# @param locale [String] The locale to use for serialization
|
|
10
|
+
# @return [Hash] Hash containing localized return reason data
|
|
11
|
+
def serialize_all(locale: "en")
|
|
12
|
+
{
|
|
13
|
+
locale => {
|
|
14
|
+
"return_reasons" => ProductTaxonomy::ReturnReason.all.sort_by(&:friendly_id).each_with_object({}) do |return_reason, hash|
|
|
15
|
+
hash[return_reason.friendly_id] = serialize(return_reason, locale:)
|
|
16
|
+
end,
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @param return_reason [ReturnReason] The return reason to serialize
|
|
22
|
+
# @param locale [String] The locale to use for serialization
|
|
23
|
+
# @return [Hash] Hash containing name and description
|
|
24
|
+
def serialize(return_reason, locale: "en")
|
|
25
|
+
{
|
|
26
|
+
"name" => return_reason.name(locale:),
|
|
27
|
+
"description" => return_reason.description(locale:),
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProductTaxonomy
|
|
4
|
+
module Serializers
|
|
5
|
+
module ReturnReason
|
|
6
|
+
module Dist
|
|
7
|
+
class JsonSerializer
|
|
8
|
+
class << self
|
|
9
|
+
# @param return_reason [ReturnReason] The return reason to serialize
|
|
10
|
+
# @param locale [String] The locale to use for localized return reasons
|
|
11
|
+
# @return [Hash] A hash containing the serialized return reason data
|
|
12
|
+
def serialize_all(version:, locale: "en")
|
|
13
|
+
{
|
|
14
|
+
"version" => version,
|
|
15
|
+
"return_reasons" => ProductTaxonomy::ReturnReason.all.map { serialize(_1, locale:) },
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @param return_reason [ReturnReason]
|
|
20
|
+
# @param locale [String] The locale to use for localized return reasons.
|
|
21
|
+
# @return [Hash]
|
|
22
|
+
def serialize(return_reason, locale: "en")
|
|
23
|
+
{
|
|
24
|
+
"id" => return_reason.gid,
|
|
25
|
+
"name" => return_reason.name(locale:),
|
|
26
|
+
"handle" => return_reason.handle,
|
|
27
|
+
"description" => return_reason.description(locale:),
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProductTaxonomy
|
|
4
|
+
module Serializers
|
|
5
|
+
module ReturnReason
|
|
6
|
+
module Dist
|
|
7
|
+
class TxtSerializer
|
|
8
|
+
class << self
|
|
9
|
+
# @param version [String] The version to include in the output
|
|
10
|
+
# @param locale [String] The locale to use for localized return reasons
|
|
11
|
+
# @param padding [Integer] The padding to use for the GID
|
|
12
|
+
# @return [String] The formatted text output with header and return reasons
|
|
13
|
+
def serialize_all(version:, locale: "en", padding: longest_gid_length)
|
|
14
|
+
header = <<~HEADER
|
|
15
|
+
# Shopify Product Taxonomy - Return Reasons: #{version}
|
|
16
|
+
# Format: {GID} : {Return reason name}
|
|
17
|
+
|
|
18
|
+
HEADER
|
|
19
|
+
|
|
20
|
+
return_reasons_txt = ProductTaxonomy::ReturnReason
|
|
21
|
+
.all
|
|
22
|
+
.map { serialize(_1, padding:, locale:) }
|
|
23
|
+
.join("\n")
|
|
24
|
+
|
|
25
|
+
header + return_reasons_txt
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @param return_reason [ReturnReason]
|
|
29
|
+
# @param padding [Integer] The padding to use for the GID.
|
|
30
|
+
# @param locale [String] The locale to use for localized return reasons.
|
|
31
|
+
# @return [String]
|
|
32
|
+
def serialize(return_reason, padding: 0, locale: "en")
|
|
33
|
+
"#{return_reason.gid.ljust(padding)} : #{return_reason.name(locale:)}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def longest_gid_length
|
|
39
|
+
ProductTaxonomy::ReturnReason.all.map { _1.gid.length }.max || 0
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProductTaxonomy
|
|
4
|
+
module Serializers
|
|
5
|
+
module ReturnReason
|
|
6
|
+
module Docs
|
|
7
|
+
module BaseSerializer
|
|
8
|
+
class << self
|
|
9
|
+
def serialize_all
|
|
10
|
+
ProductTaxonomy::ReturnReason.all.map { serialize(_1) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @param [ReturnReason] return_reason
|
|
14
|
+
# @return [Hash]
|
|
15
|
+
def serialize(return_reason)
|
|
16
|
+
{
|
|
17
|
+
"id" => return_reason.gid,
|
|
18
|
+
"name" => return_reason.name,
|
|
19
|
+
"handle" => return_reason.handle,
|
|
20
|
+
"description" => return_reason.description,
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProductTaxonomy
|
|
4
|
+
module Serializers
|
|
5
|
+
module ReturnReason
|
|
6
|
+
module Docs
|
|
7
|
+
module ReversedSerializer
|
|
8
|
+
class << self
|
|
9
|
+
def serialize_all
|
|
10
|
+
return_reasons_to_categories = ProductTaxonomy::Category.all.each_with_object({}) do |category, hash|
|
|
11
|
+
category.return_reasons.each do |return_reason|
|
|
12
|
+
hash[return_reason] ||= []
|
|
13
|
+
hash[return_reason] << category
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
serialized_return_reasons = ProductTaxonomy::ReturnReason.all.map do |return_reason|
|
|
18
|
+
serialize(return_reason, return_reasons_to_categories[return_reason])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
{
|
|
22
|
+
"return_reasons" => serialized_return_reasons,
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @param [ReturnReason] return_reason The return reason to serialize.
|
|
27
|
+
# @param [Array<Category>] return_reason_categories The categories that the return reason belongs to.
|
|
28
|
+
# @return [Hash] The serialized return reason.
|
|
29
|
+
def serialize(return_reason, return_reason_categories)
|
|
30
|
+
return_reason_categories ||= []
|
|
31
|
+
{
|
|
32
|
+
"id" => return_reason.gid,
|
|
33
|
+
"handle" => return_reason.handle,
|
|
34
|
+
"name" => return_reason.name,
|
|
35
|
+
"description" => return_reason.description,
|
|
36
|
+
"categories" => return_reason_categories.sort_by(&:full_name).map do |category|
|
|
37
|
+
{
|
|
38
|
+
"id" => category.gid,
|
|
39
|
+
"full_name" => category.full_name,
|
|
40
|
+
}
|
|
41
|
+
end,
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProductTaxonomy
|
|
4
|
+
module Serializers
|
|
5
|
+
module ReturnReason
|
|
6
|
+
module Docs
|
|
7
|
+
module SearchSerializer
|
|
8
|
+
class << self
|
|
9
|
+
def serialize_all
|
|
10
|
+
ProductTaxonomy::ReturnReason.all.map { serialize(_1) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @param [ReturnReason] return_reason
|
|
14
|
+
# @return [Hash]
|
|
15
|
+
def serialize(return_reason)
|
|
16
|
+
{
|
|
17
|
+
"searchIdentifier" => return_reason.handle,
|
|
18
|
+
"title" => return_reason.name,
|
|
19
|
+
"url" => "?returnReasonHandle=#{CGI.escapeURIComponent(return_reason.handle)}",
|
|
20
|
+
"return_reason" => {
|
|
21
|
+
"handle" => return_reason.handle,
|
|
22
|
+
"name" => return_reason.name,
|
|
23
|
+
"description" => return_reason.description,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/product_taxonomy.rb
CHANGED
|
@@ -26,6 +26,7 @@ require_relative "product_taxonomy/models/mixins/formatted_validation_errors"
|
|
|
26
26
|
require_relative "product_taxonomy/models/attribute"
|
|
27
27
|
require_relative "product_taxonomy/models/extended_attribute"
|
|
28
28
|
require_relative "product_taxonomy/models/value"
|
|
29
|
+
require_relative "product_taxonomy/models/return_reason"
|
|
29
30
|
require_relative "product_taxonomy/models/category"
|
|
30
31
|
require_relative "product_taxonomy/models/taxonomy"
|
|
31
32
|
require_relative "product_taxonomy/models/mapping_rule"
|
|
@@ -48,3 +49,27 @@ require_relative "product_taxonomy/models/serializers/value/data/data_serializer
|
|
|
48
49
|
require_relative "product_taxonomy/models/serializers/value/data/localizations_serializer"
|
|
49
50
|
require_relative "product_taxonomy/models/serializers/value/dist/json_serializer"
|
|
50
51
|
require_relative "product_taxonomy/models/serializers/value/dist/txt_serializer"
|
|
52
|
+
require_relative "product_taxonomy/models/serializers/return_reason/data/data_serializer"
|
|
53
|
+
require_relative "product_taxonomy/models/serializers/return_reason/data/localizations_serializer"
|
|
54
|
+
require_relative "product_taxonomy/models/serializers/return_reason/docs/base_serializer"
|
|
55
|
+
require_relative "product_taxonomy/models/serializers/return_reason/docs/reversed_serializer"
|
|
56
|
+
require_relative "product_taxonomy/models/serializers/return_reason/docs/search_serializer"
|
|
57
|
+
require_relative "product_taxonomy/models/serializers/return_reason/dist/json_serializer"
|
|
58
|
+
require_relative "product_taxonomy/models/serializers/return_reason/dist/txt_serializer"
|
|
59
|
+
require_relative "product_taxonomy/commands/command"
|
|
60
|
+
require_relative "product_taxonomy/commands/generate_dist_command"
|
|
61
|
+
require_relative "product_taxonomy/commands/find_unmapped_external_categories_command"
|
|
62
|
+
require_relative "product_taxonomy/commands/generate_docs_command"
|
|
63
|
+
require_relative "product_taxonomy/commands/generate_release_command"
|
|
64
|
+
require_relative "product_taxonomy/commands/dump_categories_command"
|
|
65
|
+
require_relative "product_taxonomy/commands/dump_attributes_command"
|
|
66
|
+
require_relative "product_taxonomy/commands/dump_values_command"
|
|
67
|
+
require_relative "product_taxonomy/commands/dump_return_reasons_command"
|
|
68
|
+
require_relative "product_taxonomy/commands/dump_integration_full_names_command"
|
|
69
|
+
require_relative "product_taxonomy/commands/sync_en_localizations_command"
|
|
70
|
+
require_relative "product_taxonomy/commands/add_category_command"
|
|
71
|
+
require_relative "product_taxonomy/commands/add_attribute_command"
|
|
72
|
+
require_relative "product_taxonomy/commands/add_attributes_to_categories_command"
|
|
73
|
+
require_relative "product_taxonomy/commands/add_value_command"
|
|
74
|
+
require_relative "product_taxonomy/commands/add_return_reason_command"
|
|
75
|
+
require_relative "product_taxonomy/commands/add_return_reasons_to_categories_command"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shopify_product_taxonomy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shopify
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-02-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -74,6 +74,7 @@ files:
|
|
|
74
74
|
- lib/product_taxonomy/models/mixins/formatted_validation_errors.rb
|
|
75
75
|
- lib/product_taxonomy/models/mixins/indexed.rb
|
|
76
76
|
- lib/product_taxonomy/models/mixins/localized.rb
|
|
77
|
+
- lib/product_taxonomy/models/return_reason.rb
|
|
77
78
|
- lib/product_taxonomy/models/serializers/attribute/data/data_serializer.rb
|
|
78
79
|
- lib/product_taxonomy/models/serializers/attribute/data/localizations_serializer.rb
|
|
79
80
|
- lib/product_taxonomy/models/serializers/attribute/dist/json_serializer.rb
|
|
@@ -88,6 +89,13 @@ files:
|
|
|
88
89
|
- lib/product_taxonomy/models/serializers/category/dist/txt_serializer.rb
|
|
89
90
|
- lib/product_taxonomy/models/serializers/category/docs/search_serializer.rb
|
|
90
91
|
- lib/product_taxonomy/models/serializers/category/docs/siblings_serializer.rb
|
|
92
|
+
- lib/product_taxonomy/models/serializers/return_reason/data/data_serializer.rb
|
|
93
|
+
- lib/product_taxonomy/models/serializers/return_reason/data/localizations_serializer.rb
|
|
94
|
+
- lib/product_taxonomy/models/serializers/return_reason/dist/json_serializer.rb
|
|
95
|
+
- lib/product_taxonomy/models/serializers/return_reason/dist/txt_serializer.rb
|
|
96
|
+
- lib/product_taxonomy/models/serializers/return_reason/docs/base_serializer.rb
|
|
97
|
+
- lib/product_taxonomy/models/serializers/return_reason/docs/reversed_serializer.rb
|
|
98
|
+
- lib/product_taxonomy/models/serializers/return_reason/docs/search_serializer.rb
|
|
91
99
|
- lib/product_taxonomy/models/serializers/value/data/data_serializer.rb
|
|
92
100
|
- lib/product_taxonomy/models/serializers/value/data/localizations_serializer.rb
|
|
93
101
|
- lib/product_taxonomy/models/serializers/value/dist/json_serializer.rb
|