Skip to content

Commit 654e3ca

Browse files
authored
Merge pull request #35 from dvicklund/dev
add ability to get location by id
2 parents 1020067 + bd944a5 commit 654e3ca

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Traits/LocationTrait.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Stevebauman\Inventory\Exceptions\InvalidLocationException;
66
use Illuminate\Support\Facades\Lang;
7+
use Stevebauman\Inventory\Models\Location;
78

89
/**
910
* Trait LocationTrait.
@@ -24,6 +25,18 @@ public function getLocation($location)
2425
{
2526
if ($this->isLocation($location)) {
2627
return $location;
28+
} else if (is_numeric($location)) {
29+
try {
30+
$result = Location::where('id', '=', $location)->first();
31+
32+
return $result;
33+
} catch (\Exception $e) {
34+
$message = Lang::get('inventory::exceptions.InvalidLocationException', [
35+
'location' => $location,
36+
]);
37+
38+
throw new InvalidLocationException($message);
39+
}
2740
} else {
2841
$message = Lang::get('inventory::exceptions.InvalidLocationException', [
2942
'location' => $location,

tests/InventoryStockTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,16 @@ public function testRollbackStockMovement() {
285285

286286
$this->assertEquals($initialQuantity, $stock->quantity);
287287
}
288+
289+
public function testNumericLocation() {
290+
$location = $this->newLocation();
291+
292+
$item = $this->newInventory();
293+
294+
$item->createStockOnLocation(42, $location->id, "New stuff");
295+
296+
$newQuantity = $item->getTotalStock();
297+
298+
$this->assertEquals(42, $newQuantity);
299+
}
288300
}

0 commit comments

Comments
 (0)