Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = GoodsType::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['like', 'type', $this->type])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'alias', $this->alias]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Lists all offers models.
  * @return mixed
  */
 public function actionIndex($typePrice = null)
 {
     $gt = \app\models\GoodsType::find()->orderBy('name')->all();
     $gp = \app\models\Providers::find()->orderBy('id')->all();
     $goodsType = \yii\helpers\ArrayHelper::map($gt, 'type', 'name');
     $goodsProvider = \yii\helpers\ArrayHelper::map($gp, 'id', 'name');
     $goodsProvider = ['' => ' - Все - '] + $goodsProvider;
     $session = Yii::$app->session;
     $session->open();
     $arrPriceType = \yii\helpers\ArrayHelper::map(\app\models\PriceType::find()->all(), 'id', 'name');
     if ($typePrice) {
         $session['typePrice'] = $typePrice;
         $session['typePriceName'] = $arrPriceType[$typePrice];
         $this->redirect('/' . $this->id);
     } elseif (intval($session['typePrice']) == 0) {
         $arW = array_keys($arrPriceType);
         $session['typePrice'] = array_shift($arW);
         $session['typePriceName'] = $arrPriceType[$session['typePrice']];
         $this->redirect('/' . $this->id);
     }
     return $this->render('index', ['goodsType' => $goodsType, 'goodsProvider' => $goodsProvider, 'arrPriceType' => $arrPriceType, 'typePrice' => $session['typePrice']]);
 }
Exemplo n.º 3
0
 public function validateAlias($attribute, $params)
 {
     $arAlias = [];
     $arGoodTypes = GoodsType::find()->where("NOT type = :type", [':type' => $this->type])->all();
     foreach ($arGoodTypes as $value) {
         $arW = explode(',', $value->alias);
         $arAlias = $arAlias + $arW;
     }
     $alias = mb_strtolower($this->{$attribute}, 'UTF-8');
     $arW = explode(',', $alias);
     $arW1 = [];
     foreach ($arW as $value) {
         if (strlen(trim($value)) > 0) {
             $arW1[] = trim($value);
         }
     }
     $arW1 = array_unique($arW1);
     $this->{$attribute} = implode(',', $arW1);
     $arW = explode(',', $this->{$attribute});
     $arNotUnique = array_intersect($arAlias, $arW);
     if (count($arNotUnique) > 0) {
         $this->addError($attribute, 'Следующие алиасы уже существуют: ' . implode(', ', $arNotUnique));
     }
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create($typeId = 0)
 {
     $type = GoodsType::find($typeId);
     $types = GoodsType::all();
     //获取所有types
     return view('admin.attrs.create')->with('types', $types)->with('type', $type);
 }
Exemplo n.º 5
0
 /**
  * Updates an existing Discounts model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $session = Yii::$app->session;
     $session->open();
     $post = Yii::$app->request->post();
     if (Yii::$app->request->isPost) {
         $res = $model->load($post);
     }
     $types = \app\models\GoodsType::find()->all();
     $arTypes = ['' => ' - Не выбран тип товара -'];
     foreach ($types as $type) {
         $arTypes[$type->type] = $type->name;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'arTypes' => $arTypes, 'providerName' => $session['providerIdFullNameName'], 'typePriceName' => $session['typePriceName']]);
     }
 }
Exemplo n.º 6
0
 private function getGoodType($arRes)
 {
     // Получить список всех алиасов
     if (!isset($this->arAlias)) {
         $this->arAlias = [];
         $arGoodTypes = \app\models\GoodsType::find()->all();
         foreach ($arGoodTypes as $gt) {
             $this->arGoodTypes[$gt->type] = $gt->name;
             $arW = explode(',', $gt->alias);
             foreach ($arW as $value) {
                 $this->arAlias[$value] = $gt->type;
             }
         }
     }
     // Привести к нижнему регистру название
     $name = mb_strtolower($arRes['name'], 'UTF-8');
     // Получить код типа товара исходя из найтенного алиаса
     $arRes['goodType'] = '';
     foreach ($this->arAlias as $alias => $goodType) {
         if (mb_strpos($name, $alias) !== false) {
             $arRes['goodType'] = $goodType;
             break;
         }
     }
     return $arRes;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $type = GoodsType::find($id);
     $type->delete();
     return Redirect::to('admin/goods_types');
 }