Skip to content

Commit bf585ce

Browse files
authored
Count negative inventory values as out of stock (#307)
Signed-off-by: Philipp Daun <post@philippdaun.net>
1 parent 866d992 commit bf585ce

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Tags/Shopify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ protected function isInStock($variants): bool
284284
}
285285
}
286286

287-
if ($stock === 0 and $deny) {
287+
if ($stock <= 0 and $deny) {
288288
return false;
289289
}
290290

tests/Unit/TagsTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ public function outputs_in_stock()
156156
])->save();
157157

158158
$this->assertEquals('', $this->tag('{{ if {shopify:in_stock} }}Yes{{ /if }}', ['slug' => 'obi-wan']));
159+
160+
$variant->merge([
161+
'inventory_quantity' => -1,
162+
])->save();
163+
164+
$this->assertEquals('', $this->tag('{{ if {shopify:in_stock} }}Yes{{ /if }}', ['slug' => 'obi-wan']));
165+
166+
$variant->merge([
167+
'inventory_quantity' => null,
168+
])->save();
169+
170+
$this->assertEquals('', $this->tag('{{ if {shopify:in_stock} }}Yes{{ /if }}', ['slug' => 'obi-wan']));
159171
}
160172

161173
#[Test]

0 commit comments

Comments
 (0)