add inventory to frontend
This commit is contained in:
@@ -78,7 +78,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
if ( $insert ){
|
||||
|
||||
$query = Product::find();
|
||||
if ( isset($this->id_account) && !is_numeric($this->id_account)){
|
||||
if ( isset($this->id_account) && is_numeric($this->id_account)){
|
||||
$query->andWhere(['id_account' => $this->id_account]);
|
||||
|
||||
}
|
||||
@@ -102,6 +102,18 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
$form->save();
|
||||
}
|
||||
|
||||
foreach ($inventoryGroups as $group){
|
||||
$form = new InventoryItemForm(
|
||||
[
|
||||
'inventory' => $this,
|
||||
'id_product' => $group->id_inventory_group,
|
||||
'inventoryGroup' => $group,
|
||||
'type' => 'group'
|
||||
]
|
||||
);
|
||||
$form->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -142,9 +142,14 @@ class InventoryItem extends BaseFitnessActiveRecord
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
if ( !$insert ){
|
||||
$product = $this->product;
|
||||
$product->stock = $this->count;
|
||||
$product->save(false);
|
||||
if ( $this->type == 'product'){
|
||||
$product = $this->product;
|
||||
$product->stock = $this->count;
|
||||
if ( !$product->save(false) ){
|
||||
\Yii::error("Failed to save product stock");
|
||||
throw new \Exception("A leltár elem mentése nem sikerült");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user