add product

This commit is contained in:
2015-09-24 22:14:09 +02:00
parent fcc18d79f6
commit a2b835225a
15 changed files with 229 additions and 80 deletions

View File

@@ -9,6 +9,7 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Account;
use common\models\ProductCategory;
/**
* ProductController implements the CRUD actions for Product model.
@@ -62,8 +63,10 @@ class ProductController extends Controller
public function actionCreate()
{
$model = new Product();
$model->stock = 0;
$model->status = Product::STATUS_ACTIVE;
$accounts = Account::readAccounts(null);
$categories = ProductCategory::read(null);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_product]);
@@ -71,6 +74,8 @@ class ProductController extends Controller
return $this->render('create', [
'model' => $model,
'accounts' => $accounts,
'categories' => $categories ,
]);
}
}
@@ -85,11 +90,16 @@ class ProductController extends Controller
{
$model = $this->findModel($id);
$accounts = Account::readAccounts($model->id_account);
$categories = ProductCategory::read($model->id_product_category);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_product]);
} else {
return $this->render('update', [
'model' => $model,
'accounts' => $accounts,
'categories' => $categories ,
]);
}
}