Skip to content

Commit

Permalink
Replaced all hard coded table identifiers with the getKey() and `ge…
Browse files Browse the repository at this point in the history
…tKeyName()` methods
  • Loading branch information
stevebauman committed Jun 17, 2015
1 parent 191b1e5 commit 8025608
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/Traits/AssemblyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function getAssemblyItemsList($recursive = true, $depth = 0)

foreach ($items as $item) {
$list[$level] = [
'id' => $item->id,
'id' => $item->getKey(),
'name' => $item->name,
'metric_id' => $item->metric_id,
'category_id' => $item->category_id,
Expand Down Expand Up @@ -238,7 +238,7 @@ public function updateAssemblyItem($part, $quantity = 1, array $extra = [])
$id = $part;

if ($part instanceof Model) {
$id = $part->id;
$id = $part->getKey();
}

$attributes = array_merge(['quantity' => $quantity], $extra);
Expand Down Expand Up @@ -356,7 +356,7 @@ public function scopeAssembly(Builder $query)
*/
private function validatePart(Model $part)
{
if ((int) $part->id === (int) $this->id) {
if ((int) $part->getKey() === (int) $this->getKey()) {
$message = 'An item cannot be an assembly of itself.';

throw new InvalidPartException($message);
Expand All @@ -381,8 +381,8 @@ private function validatePart(Model $part)
*/
private function validatePartAgainstList($value, $key)
{
if ($key === 'id') {
if ((int) $value === (int) $this->id) {
if ($key === $this->getKeyName()) {
if ((int) $value === (int) $this->getKey()) {
$message = 'The inserted part exists inside the assembly tree. An item cannot be an assembly of itself.';

throw new InvalidPartException($message);
Expand All @@ -397,6 +397,6 @@ private function validatePartAgainstList($value, $key)
*/
private function getAssemblyCacheKey()
{
return $this->assemblyCacheKey.$this->id;
return $this->assemblyCacheKey.$this->getKey();
}
}
6 changes: 3 additions & 3 deletions src/Traits/InventoryStockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function newTransaction($name = '')
* Set the transaction attributes so they don't
* need to be set manually
*/
$transaction->stock_id = $this->id;
$transaction->stock_id = $this->getKey();
$transaction->name = $name;

return $transaction;
Expand Down Expand Up @@ -521,7 +521,7 @@ private function processPutOperation($putting, $reason = '', $cost = 0)
*/
private function processMoveOperation(Model $location)
{
$this->location_id = $location->id;
$this->location_id = $location->getKey();

$this->dbStartTransaction();

Expand Down Expand Up @@ -633,7 +633,7 @@ private function processRecursiveRollbackOperation(Model $movement)
private function generateStockMovement($before, $after, $reason = '', $cost = 0)
{
$insert = [
'stock_id' => $this->id,
'stock_id' => $this->getKey(),
'before' => $before,
'after' => $after,
'reason' => $reason,
Expand Down
22 changes: 11 additions & 11 deletions src/Traits/InventoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ public function createStockOnLocation($quantity, $location, $reason = '', $cost
* A stock record wasn't found on this location, we'll create one
*/
$insert = [
'inventory_id' => $this->id,
'location_id' => $location->id,
'inventory_id' => $this->getKey(),
'location_id' => $location->getKey(),
'quantity' => 0,
'aisle' => $aisle,
'row' => $row,
Expand Down Expand Up @@ -315,8 +315,8 @@ public function newStockOnLocation($location)
* Assign the known attributes
* so devs don't have to
*/
$stock->inventory_id = $this->id;
$stock->location_id = $location->id;
$stock->inventory_id = $this->getKey();
$stock->location_id = $location->getKey();

return $stock;
}
Expand Down Expand Up @@ -520,8 +520,8 @@ public function getStockFromLocation($location)
$location = $this->getLocation($location);

$stock = $this->stocks()
->where('inventory_id', $this->id)
->where('location_id', $location->id)
->where('inventory_id', $this->getKey())
->where('location_id', $location->getKey())
->first();

if ($stock) {
Expand Down Expand Up @@ -620,12 +620,12 @@ public function generateSku()
* Create the numerical code by the items ID
* to accompany the prefix and pad left zeros
*/
$code = str_pad($this->id, $codeLength, '0', STR_PAD_LEFT);
$code = str_pad($this->getKey(), $codeLength, '0', STR_PAD_LEFT);

/*
* Process the generation
*/
return $this->processSkuGeneration($this->id, $prefix.$skuSeparator.$code);
return $this->processSkuGeneration($this->getKey(), $prefix.$skuSeparator.$code);
}

/*
Expand Down Expand Up @@ -672,7 +672,7 @@ public function regenerateSku()
/*
* Failed generating a new sku, we'll restore the old one
*/
return $this->processSkuGeneration($this->id, $previousSku->code);
return $this->processSkuGeneration($this->getKey(), $previousSku->code);
}

/*
Expand Down Expand Up @@ -721,7 +721,7 @@ public function createSku($code, $overwrite = false)
/*
* No SKU exists, lets create one
*/
return $this->processSkuGeneration($this->id, $code);
return $this->processSkuGeneration($this->getKey(), $code);
}

/**
Expand All @@ -747,7 +747,7 @@ public function updateSku($code, $sku = null)
* trying to find one, we'll create one
*/
if (!$sku) {
return $this->processSkuGeneration($this->id, $code);
return $this->processSkuGeneration($this->getKey(), $code);
}

return $this->processSkuUpdate($sku, $code);
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/InventoryTransactionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ private function processSave($event = '')
private function generateTransactionHistory($stateBefore, $stateAfter, $quantityBefore = 0, $quantityAfter = 0)
{
$insert = [
'transaction_id' => $this->id,
'transaction_id' => $this->getKey(),
'state_before' => $stateBefore,
'state_after' => $stateAfter,
'quantity_before' => $quantityBefore,
Expand All @@ -1386,7 +1386,7 @@ private function generateTransactionHistory($stateBefore, $stateAfter, $quantity
*/
private function getTransactionReason($key)
{
$reason = Lang::get('inventory::reasons.transactions.'.$key, ['id' => $this->id, 'date' => date('Y-m-d H:i:s')]);
$reason = Lang::get('inventory::reasons.transactions.'.$key, ['id' => $this->getKey(), 'date' => date('Y-m-d H:i:s')]);

/*
* Make sure we set the reason to null if no translation is found
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/InventoryVariantTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function newVariant($name = '')
{
$variant = new $this();

$variant->parent_id = $this->id;
$variant->parent_id = $this->getKey();
$variant->category_id = $this->category_id;
$variant->metric_id = $this->metric_id;

Expand Down Expand Up @@ -209,7 +209,7 @@ public function createVariant($name = '', $description = '', $categoryId = null,
*/
public function makeVariantOf(Model $item)
{
return $this->processMakeVariant($item->id);
return $this->processMakeVariant($item->getKey());
}

/**
Expand Down

0 comments on commit 8025608

Please sign in to comment.