/**
  * Creates a new ProductRelation model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ProductRelation();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'main' => $model->main, 'sub' => $model->sub]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #2
0
 /**
  * create a batch product base on one main product
  */
 public function actionAddBatchProduct($mainID)
 {
     $model = new Product();
     $model->scenario = Product::SCENARIO_BATCH;
     $mainProduct = $this->findModel($mainID);
     $model->attributes = $mainProduct->getAttributes();
     $model->stock_qty = null;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $relation = new ProductRelation();
         $relation->main = $mainID;
         $relation->sub = $model->id;
         if ($relation->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             throw new NotFoundHttpException('Error Saving Product');
         }
     } else {
         $model->qty_per_order = 2;
         return $this->render('add_batch', ['model' => $model, 'mainID' => $mainID]);
     }
 }