Skip to content

Commit 3c43f9f

Browse files
authored
Merge pull request #30 from justbetter/feature/fix-double-retrieve
Do not set update to false if it's currently true
2 parents df5c98e + 9046ecf commit 3c43f9f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Actions/Retrieval/SaveStock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function save(StockData $stock, bool $forceUpdate): void
2828
$model->retrieve = false;
2929
$model->last_retrieved = now();
3030

31-
$model->update = $forceUpdate || $model->checksum !== $stock->checksum();
31+
$model->update = $forceUpdate || $model->checksum !== $stock->checksum() || $model->update;
3232
$model->checksum = $stock->checksum();
3333

3434
$model->save();

tests/Actions/Retrieval/SaveStockTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,29 @@ public function it_can_force_update(): void
9292

9393
$this->assertTrue($model->refresh()->update);
9494
}
95+
96+
#[Test]
97+
public function it_does_not_reset_update_boolean(): void
98+
{
99+
$stockData = StockData::of([
100+
'sku' => '::sku::',
101+
'in_stock' => true,
102+
'quantity' => 10,
103+
]);
104+
105+
/** @var SaveStock $action */
106+
$action = app(SaveStock::class);
107+
$action->save($stockData, false);
108+
109+
/** @var Stock $model */
110+
$model = Stock::query()->firstWhere('sku', '=', '::sku::');
111+
112+
$this->assertTrue($model->update);
113+
114+
$model->update(['update' => true]);
115+
116+
$action->save($stockData, false);
117+
118+
$this->assertTrue($model->refresh()->update);
119+
}
95120
}

0 commit comments

Comments
 (0)