showroom 0.3.0 → 0.3.1
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/CHANGELOG.md +14 -0
- data/README.md +4 -3
- data/lib/showroom/core/version.rb +1 -1
- data/lib/showroom/models/product.rb +24 -3
- data/lib/showroom/models/product_variant.rb +15 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a879aafd609e03c490716579f3051e97ca92108252ac53cf63256db2ccb8ae5
|
|
4
|
+
data.tar.gz: fbfea4d3ce7580bfbb131a1643e0000f6d7c4a8a7865289337cfabcf8ee0a7fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c523a5ff93f4931a403c9b59a6104e0c014d17742977a7c3c786f8276f7892f2ff751e96d18643463f9efca5fae3acbb0c36213325675896c7a24a67ea45f7f3
|
|
7
|
+
data.tar.gz: 858be74b2a6d8fa7429cd014e04a332699cf5c99edd7afc2485617d95b5e3e43d897a8809bf7f419297d93b55b41cdd3a150348d8ae1805134a3ceec89836df8
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.1] - 2026-04-25
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- `ProductVariant#available?` now returns `nil` (instead of `false`) when the source payload omits the `available` key — some Shopify storefronts do not expose it on `/products/{handle}.json`, so distinguishing "unknown" from "unavailable" is necessary to avoid silently reporting every variant as out of stock
|
|
15
|
+
- `Product#available?` now returns `true | false | nil`: it honours a top-level `available` key when present, otherwise aggregates variants — any `true` → `true`, all `false` → `false`, otherwise `nil`
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- `ProductVariant#availability_known?` — `true` when the payload included an `available` key
|
|
20
|
+
- `Product#availability_known?` — `true` when product-level availability can be determined from a top-level key or any variant
|
|
21
|
+
|
|
22
|
+
## [0.3.0] - 2026-04-24
|
|
23
|
+
|
|
10
24
|
### Added
|
|
11
25
|
|
|
12
26
|
- `Product#similar` — searches for products similar to the current one via the search suggest endpoint; strips variant SKU fragments from the handle before querying, and falls back to a title search when the stripped-handle query returns no results
|
data/README.md
CHANGED
|
@@ -75,8 +75,9 @@ product = Showroom::Product.find('lorem-road-bike')
|
|
|
75
75
|
product.title # => "Lorem Road Bike"
|
|
76
76
|
product.handle # => "lorem-road-bike"
|
|
77
77
|
product.vendor # => "Lorem Cycles"
|
|
78
|
-
product.available?
|
|
79
|
-
product.
|
|
78
|
+
product.available? # => true | false | nil (nil when no variant exposes availability)
|
|
79
|
+
product.availability_known? # => true when availability can be determined
|
|
80
|
+
product.price # => "749.00" (lowest variant price)
|
|
80
81
|
product.price_range # => "749.00–899.00"
|
|
81
82
|
product.prices # => ["749.00", "899.00"] (unique prices from all variants)
|
|
82
83
|
product.url # => "https://acme.myshopify.com/products/lorem-road-bike"
|
|
@@ -90,7 +91,7 @@ product.similar.first.load # => Showroom::Product (full record)
|
|
|
90
91
|
|
|
91
92
|
# Variants
|
|
92
93
|
product.variants.each do |v|
|
|
93
|
-
puts "#{v.title} #{v.price} #{v.compare_at_price} on_sale=#{v.on_sale?} available=#{v.available?}"
|
|
94
|
+
puts "#{v.title} #{v.price} #{v.compare_at_price} on_sale=#{v.on_sale?} available=#{v.available?} availability_known=#{v.availability_known?}"
|
|
94
95
|
end
|
|
95
96
|
|
|
96
97
|
# All pages — returns an Enumerator
|
|
@@ -125,11 +125,32 @@ module Showroom
|
|
|
125
125
|
prices.length == 1 ? prices.first : "#{prices.min} - #{prices.max}"
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
-
# Returns true when
|
|
128
|
+
# Returns true when the product is available for purchase, false when it
|
|
129
|
+
# is not, or nil when availability cannot be determined from the payload.
|
|
129
130
|
#
|
|
130
|
-
#
|
|
131
|
+
# If the response carries a top-level +available+ key, that value wins.
|
|
132
|
+
# Otherwise the result is aggregated from variants:
|
|
133
|
+
# any variant +true+ → +true+; all variants +false+ → +false+;
|
|
134
|
+
# otherwise (mix of +false+ and unknowns, or all unknown) → +nil+.
|
|
135
|
+
#
|
|
136
|
+
# @return [Boolean, nil]
|
|
131
137
|
def available?
|
|
132
|
-
|
|
138
|
+
return @attrs['available'] == true if @attrs.key?('available')
|
|
139
|
+
|
|
140
|
+
states = variants.map(&:available?)
|
|
141
|
+
return true if states.include?(true)
|
|
142
|
+
return false if states.all? { |s| s == false }
|
|
143
|
+
|
|
144
|
+
nil # rubocop:disable Style/ReturnNilInPredicateMethodDefinition
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Returns true when product-level availability can be determined,
|
|
148
|
+
# either from a top-level +available+ key or from at least one variant
|
|
149
|
+
# whose own availability is known.
|
|
150
|
+
#
|
|
151
|
+
# @return [Boolean]
|
|
152
|
+
def availability_known?
|
|
153
|
+
@attrs.key?('available') || variants.any?(&:availability_known?)
|
|
133
154
|
end
|
|
134
155
|
|
|
135
156
|
# Returns the first image, or nil if there are no images.
|
|
@@ -10,13 +10,26 @@ module Showroom
|
|
|
10
10
|
class ProductVariant < Resource
|
|
11
11
|
main_attrs :id, :title, :price, :compare_at_price, :sku
|
|
12
12
|
|
|
13
|
-
# Returns true when the variant is available for purchase
|
|
13
|
+
# Returns true when the variant is available for purchase, false when
|
|
14
|
+
# explicitly unavailable, or nil when the source payload omits the
|
|
15
|
+
# +available+ key (some Shopify storefronts do not expose it on
|
|
16
|
+
# +/products/{handle}.json+).
|
|
14
17
|
#
|
|
15
|
-
# @return [Boolean]
|
|
18
|
+
# @return [Boolean, nil]
|
|
16
19
|
def available?
|
|
20
|
+
return nil unless availability_known? # rubocop:disable Style/ReturnNilInPredicateMethodDefinition
|
|
21
|
+
|
|
17
22
|
@attrs['available'] == true
|
|
18
23
|
end
|
|
19
24
|
|
|
25
|
+
# Returns true when the source payload included an +available+ key,
|
|
26
|
+
# making {#available?} authoritative.
|
|
27
|
+
#
|
|
28
|
+
# @return [Boolean]
|
|
29
|
+
def availability_known?
|
|
30
|
+
@attrs.key?('available')
|
|
31
|
+
end
|
|
32
|
+
|
|
20
33
|
# Returns true when +compare_at_price+ is present and greater than +price+.
|
|
21
34
|
#
|
|
22
35
|
# @return [Boolean]
|