jekyll-spree-client 0.1.20 → 0.1.22
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/jekyll/spree_client.rb +25 -19
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d84e793a7b13924032e636bc9271c34526b50532a0d195fefec3d4ba396e9929
|
|
4
|
+
data.tar.gz: 43f88102b50e08f082e22db89899d51198e27d985dfc8b9aa52703ab53abc883
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e1e9fd39bd5bf077ef25471c283f23cbe988b59a54bb290a41526db79c0b3a7811a39bb45ec1fc051b956a9a35b2ce1bdd8e368aae110f3959c6d3de1c8fb17
|
|
7
|
+
data.tar.gz: a9053c799c246b4c70e43d909fc247642288a20dd1ee73b64e62edb3dd380641c6415faac60666da2ea1d378672327e7fc18eba517bd68a74eed9a3716c3e597
|
data/lib/jekyll/spree_client.rb
CHANGED
|
@@ -151,21 +151,6 @@ module Jekyll
|
|
|
151
151
|
@remote_products ||= spree.products(shipping_category_id: shipping_category_id)
|
|
152
152
|
end
|
|
153
153
|
|
|
154
|
-
# Obtain the default stock location, the first that's active.
|
|
155
|
-
#
|
|
156
|
-
# XXX: API doesn't show which one's the default so we're guessing.
|
|
157
|
-
#
|
|
158
|
-
# @return [Hash]
|
|
159
|
-
def stock_location
|
|
160
|
-
@stock_location ||=
|
|
161
|
-
if spree.stock_locations.index
|
|
162
|
-
spree.stock_locations.response['stock_locations']&.find { |s| s['active'] }
|
|
163
|
-
else
|
|
164
|
-
Jekyll.logger.warn "Couldn't get default stock location"
|
|
165
|
-
nil
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
154
|
# Fetch variants by SKU
|
|
170
155
|
#
|
|
171
156
|
# @param [Array]
|
|
@@ -188,11 +173,14 @@ module Jekyll
|
|
|
188
173
|
remote_product = attributes_from(product, product_fields).tap do |a|
|
|
189
174
|
a[:extra_attributes] ||= {}
|
|
190
175
|
end
|
|
191
|
-
|
|
176
|
+
|
|
177
|
+
variant_comparison = attributes_from(variant, product_fields).tap do |v|
|
|
178
|
+
v[:extra_attributes] = v[:extra_attributes]&.transform_keys(&:to_sym)
|
|
179
|
+
end
|
|
192
180
|
|
|
193
181
|
# Only when they haven't changed, so we don't waste time sending a
|
|
194
182
|
# request.
|
|
195
|
-
unless remote_product
|
|
183
|
+
unless compare_hashes(remote_product, variant_comparison)
|
|
196
184
|
# XXX: We don't have the product ID with the variant but we have
|
|
197
185
|
# the slug.
|
|
198
186
|
remote_variant = { id: variant['id'] }.merge!(attributes_from product, variant_only_fields)
|
|
@@ -244,9 +232,14 @@ module Jekyll
|
|
|
244
232
|
product.data['variant_id'] = variant_id
|
|
245
233
|
product.data['in_stock'] = product.data['stock'].to_i > 0
|
|
246
234
|
|
|
235
|
+
spree.variants.show(id: variant_id)
|
|
236
|
+
variant = spree.variants.response
|
|
237
|
+
|
|
247
238
|
# Add the initial stock
|
|
248
|
-
spree.stock_items(
|
|
249
|
-
|
|
239
|
+
spree.stock_items(
|
|
240
|
+
id: variant.dig('stock_items', 0, 'id'),
|
|
241
|
+
stock_location_id: variant.dig('stock_items', 0, 'stock_location_id')
|
|
242
|
+
).stock_movements.create(quantity: product.data['stock'])
|
|
250
243
|
|
|
251
244
|
true
|
|
252
245
|
end
|
|
@@ -268,5 +261,18 @@ module Jekyll
|
|
|
268
261
|
def attributes_from(document_or_hash, fields)
|
|
269
262
|
(document_or_hash.respond_to?(:data) ? document_or_hash.data : document_or_hash).slice(*fields).transform_keys(&:to_sym)
|
|
270
263
|
end
|
|
264
|
+
|
|
265
|
+
# Compare two hashes by the keys they share. Some fields we send
|
|
266
|
+
# are not available through the APIv1, like meta_description.
|
|
267
|
+
#
|
|
268
|
+
# @link https://stackoverflow.com/a/15503329
|
|
269
|
+
# @param :h1 [Hash]
|
|
270
|
+
# @param :h2 [Hash]
|
|
271
|
+
# @return [Boolean]
|
|
272
|
+
def compare_hashes(h1, h2)
|
|
273
|
+
(h1.keys & h2.keys).all? do |k|
|
|
274
|
+
h1[k] == h2[k]
|
|
275
|
+
end
|
|
276
|
+
end
|
|
271
277
|
end
|
|
272
278
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll-spree-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.22
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- f
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-04-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: spree-api-client
|
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
96
96
|
- !ruby/object:Gem::Version
|
|
97
97
|
version: '0'
|
|
98
98
|
requirements: []
|
|
99
|
-
rubygems_version: 3.3.
|
|
99
|
+
rubygems_version: 3.3.27
|
|
100
100
|
signing_key:
|
|
101
101
|
specification_version: 4
|
|
102
102
|
summary: Spree Ecommerce API client for Jekyll
|