public static function findOrCreateByValueAndManufacturer($value, $manufacturer_id) { if (!$value) { return null; } $model_number = static::findOne(['value' => $value, 'manufacturer_id' => $manufacturer_id]); if ($model_number) { return $model_number; } if ($manufacturer_id) { $manufacturer = Manufacturer::findOne(['id' => $manufacturer_id]); } $model_number = new static(); $model_number->value = $value; $model_number->manufacturer_id = $manufacturer ? $manufacturer->id : null; $model_number->save(); return $model_number; }
public function actionSave() { if (Yii::$app->user->can('updateResource')) { $post = Yii::$app->request->post('Manufacturer'); if ($post['id']) { $model = Manufacturer::findOne(['id' => $post['id']]); $model->attributes = $post; if ($model->validate()) { if ($model->update()) { Yii::$app->getSession()->setFlash('success', 'Manufacturer #' . $post['id'] . ' updated.'); } else { Yii::$app->getSession()->setFlash('error', 'Failed to update manufacturer #' . $post['id'] . '.'); } } } } else { Yii::$app->getSession()->setFlash('error', 'Not allowed.'); } return $this->redirect(['index']); }
public function actionManufacturer($id, $name = '') { $manufacturer = Manufacturer::findOne($id); $query = Product::find(); $query->joinWith(['productManufacturers']); $query->andWhere(['in', 'product_manufacturer.manufacturer_id', $id]); $query->andWhere('status = :s AND is_private = :p', [':s' => 1, ':p' => 0]); $query->orderBy('id DESC'); $pageTile = "Items Available in : {$manufacturer->name}"; $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 12]]); return $this->render('category', ['dataProvider' => $dataProvider, 'pageTile' => $pageTile]); }
/** * Finds the Manufacturer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Manufacturer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Manufacturer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }