/**
  * Creates a new ProductUom model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ProductUom();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'product_id' => $model->product_id, 'uom_id' => $model->uom_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $dPost = Yii::$app->request->post();
     if ($model->load($dPost)) {
         $conn = \Yii::$app->db->beginTransaction();
         try {
             $allSaved = true;
             if (!$model->save()) {
                 $allSaved = false;
             } else {
                 foreach (Yii::$app->request->post('prodUom', []) as $row) {
                     $modelUom = new \backend\models\master\ProductUom();
                     $modelUom->product_id = $model->id;
                     $modelUom->uom_id = $row['id_uom'];
                     $modelUom->isi = $row['isi'];
                     if (!$modelUom->save()) {
                         $allSaved = false;
                     }
                 }
                 foreach (Yii::$app->request->post('prodBcode', []) as $row) {
                     $modelChild = new \backend\models\master\ProductChild();
                     $modelChild->product_id = $model->id;
                     $modelChild->barcode = $row['barcode'];
                     if (!$modelChild->save()) {
                         $allSaved = false;
                     }
                 }
             }
             if ($allSaved) {
                 $conn->commit();
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } catch (Exception $ex) {
             $conn->rollBack();
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }