Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CarPart::find();
     $query->innerJoinWith('size', 'color', 'damage', 'price');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new Sort(['attributes' => ['size_name' => ['asc' => ['size.name' => SORT_ASC], 'desc' => ['size.name' => SORT_DESC]], 'color_name' => ['asc' => ['color.name' => SORT_ASC], 'desc' => ['color.name' => SORT_DESC]], 'damage_name' => ['asc' => ['damage.name' => SORT_ASC], 'desc' => ['damage.name' => SORT_DESC]], 'price_total' => ['asc' => ['price.total' => SORT_ASC], 'desc' => ['price.total' => SORT_DESC]], 'created_at', 'updated_at']])]);
     $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(['created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'size.name', $this->size_name])->andFilterWhere(['like', 'damage.name', $this->damage_name])->andFilterWhere(['like', 'color.name', $this->color_name])->andFilterWhere(['like', 'price.total', $this->price_total]);
     return $dataProvider;
 }
 /**
  * Finds the CarPart model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return CarPart the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CarPart::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCarParts()
 {
     return $this->hasMany(CarPart::className(), ['size_id' => 'id']);
 }
Example #4
0
 public function actionStoreChanges()
 {
     if (isset($_POST['CarPart'])) {
         $result = [];
         $selectedParts = $_POST['CarPart'];
         $carPart = CarPart::getByParts($selectedParts['size_id'], $selectedParts['color_id'], $selectedParts['damage_id']);
         if (isset($carPart, $carPart->price)) {
             $total = (double) $carPart->price->total;
             if ($_POST['mode'] == 0) {
                 Yii::$app->session['carPartTotal'] += $total;
             } elseif ($_POST['mode'] == 1) {
                 Yii::$app->session['carPartTotal'] -= $total;
             }
             $result['total'] = Yii::$app->formatter->asCurrency(Yii::$app->session['carPartTotal']);
             $result['error'] = false;
         } else {
             $result['message'] = Yii::t('app', 'The requested car part need to be defined. You can do it <a href="{route}">here</a>', ['route' => Url::to(['car-part/create']) . '?' . http_build_query($_POST['CarPart'])]);
             $result['error'] = true;
         }
         echo json_encode($result);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }