/**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new ProductCategoryToProduct();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = 'Create';
             $log->object_class = 'ProductCategoryToProduct';
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductCategoryToProduct::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'product_category_id' => $this->product_category_id, 'product_id' => $this->product_id]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductCategoryToProducts()
 {
     return $this->hasMany(ProductCategoryToProduct::className(), ['product_id' => 'id']);
 }
Example #4
0
 /**
  * Deletes an existing Product model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if ($model = $this->findModel($id)) {
         foreach (ProductTranslation::findAll(['product_id' => $model->id]) as $item) {
             $item->delete();
         }
         foreach (ProductImage::findAll(['product_id' => $model->id]) as $item) {
             $item->delete();
         }
         foreach (ProductCategoryToProduct::findAll(['product_id' => $model->id]) as $item) {
             $item->delete();
         }
         foreach (ProductCollectionToProduct::findAll(['product_id' => $model->id]) as $item) {
             $item->delete();
         }
         $model->delete();
         return $this->goBack(Url::previous());
     } else {
         throw new NotFoundHttpException();
     }
 }
 /**
  * Finds the ProductCategoryToProduct model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ProductCategoryToProduct the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ProductCategoryToProduct::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }