Пример #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;
 }
 public function __construct($id, $module, $config = array())
 {
     if (isset(Yii::$app->request->queryParams['goodType'])) {
         $session = Yii::$app->session;
         $session->open();
         $session['goodType'] = Yii::$app->request->queryParams['goodType'];
         return $this->redirect('/' . $id);
     }
     $session = Yii::$app->session;
     $session->open();
     if (isset($session['goodType']) && strlen($session['goodType']) > 0) {
         $this->goodType = $session['goodType'];
     } else {
         $this->redirect('/goods-type');
     }
     $oGoodType = \app\models\GoodsType::findOne($session['goodType']);
     $this->goodTypeName = $oGoodType->name;
     parent::__construct($id, $module, $config);
 }
Пример #3
0
 public function actionDoFiler($goodsType, $goodsProvider = false)
 {
     header('Content-Type: utf-8');
     $oGoodsType = \app\models\GoodsType::findOne($goodsType);
     if (!$oGoodsType instanceof \app\models\GoodsType) {
         throw new Exception('Не верный тип товара');
     }
     $GoodsParamsName = $oGoodsType->getGoodsParamsNames()->orderBy('sort')->all();
     $arParamsType = \yii\helpers\ArrayHelper::map($GoodsParamsName, 'id', 'name');
     //                $arParamsType = [['id'=>'providers_id', 'name'=>'Поставщик']] + $arParamsType;
     $sql = 'select * from offers as O INNER JOIN goods as G INNER JOIN goods_t_' . $goodsType . ' as GT ' . 'where O.goods_id = G.id and G.id = GT.goods_id ';
     $arAnd = ['G.goods_type_type = :GT'];
     $arParams = [':GT' => $goodsType];
     if ($goodsProvider) {
         $arAnd[] = 'O.providers_id = :providers_id';
         $arParams[':providers_id'] = $goodsProvider;
     }
     foreach ($_GET as $k => $v) {
         if (strlen($v) > 0 && isset($arParamsType[$k])) {
             $arAnd[] = "GT.{$k} = :{$k}";
             $arParams[":{$k}"] = $v;
         }
     }
     $sql .= ' and ' . implode(' and ', $arAnd);
     $connection = \Yii::$app->db;
     $command = $connection->createCommand($sql);
     $command->bindValues($arParams);
     $items = $command->queryAll();
     $goodsValues = \app\models\GoodsParams::find()->all();
     //                $arrGoodsValues = \yii\helpers\ArrayHelper::toArray($goodsValues, ['app\models\GoodsParams'=>['id', 'value', 'public_value']]);
     $arrGoodsValues = \yii\helpers\ArrayHelper::map($goodsValues, 'id', 'value');
     //                print ('<pre>');print_r($arrGoodsValues);print('</pre>');exit('100');
     $providers = \app\models\Providers::find()->all();
     $arProviders = \yii\helpers\ArrayHelper::map($providers, 'id', 'name');
     $session = Yii::$app->session;
     $session->open();
     print $this->renderPartial('list', ['arParamsType' => $arParamsType, 'items' => $items, 'arrGoodsValues' => $arrGoodsValues, 'arProviders' => $arProviders, 'typePrice' => $session['typePrice']]);
 }
Пример #4
0
 function __construct($id, $module, $config = array())
 {
     $session = Yii::$app->session;
     $session->open();
     if (isset(Yii::$app->request->queryParams['goodTypeParam'])) {
         $session['goodTypeParam'] = Yii::$app->request->queryParams['goodTypeParam'];
         return $this->redirect('/' . $id);
     }
     if (isset($session['goodTypeParam']) && strlen($session['goodTypeParam']) > 0) {
         //            $this->goodTypeParam = $session['goodTypeParam'];
     } else {
         $this->redirect('/goods-type');
     }
     $this->oGoodsParamsName = \app\models\GoodsParamsName::findOne($session['goodTypeParam']);
     if (!$this->oGoodsParamsName instanceof \app\models\GoodsParamsName) {
         throw new Exception('Не существует такой тип параметра.');
     }
     $oGoodType = \app\models\GoodsType::findOne($session['goodType']);
     if (!$oGoodType instanceof \app\models\GoodsType) {
         throw new Exception('Не существует такой тип товара.');
     }
     $this->goodTypeName = $oGoodType->name;
     parent::__construct($id, $module, $config);
 }
Пример #5
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));
     }
 }
Пример #6
0
 /**
  * Finds the GoodsType model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return GoodsType the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GoodsType::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getGoodsTypeType()
 {
     return $this->hasOne(GoodsType::className(), ['type' => 'goods_type_type']);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $attr = Attribute::find($id);
     $attr->attr_value = implode(PHP_EOL, unserialize($attr->attr_value));
     return view('admin.attrs.edit')->withAttr($attr)->with('types', GoodsType::all());
 }
Пример #9
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']]);
     }
 }
Пример #10
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;
 }
Пример #11
0
}
?>
    </p>
    <?php 
if ($typePrice) {
    ?>

        <p>
            <?php 
    echo Html::a('Добавить наценку', ['create'], ['class' => 'btn btn-success']);
    ?>
        </p>

        <?php 
    echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'goods_type_type', 'label' => 'Тип товара', 'format' => 'html', 'value' => function ($model) {
        $oGT = \app\models\GoodsType::findOne($model->goods_type_type);
        return '[' . $oGT->type . '] <b>' . $oGT->name . '</b>';
    }], ['attribute' => 'test1', 'label' => 'Параметр', 'format' => 'html', 'value' => function ($model) {
        $arP = explode(';', $model->params);
        $arV = explode(';', $model->values);
        $arPP = [];
        foreach ($arP as $key => $paramId) {
            $oPar = \app\models\GoodsParamsName::findOne($paramId);
            $oVal = app\models\GoodsParams::findOne($arV[$key]);
            if ($oPar instanceof \app\models\GoodsParamsName && $oVal instanceof app\models\GoodsParams) {
                $arPP[] = $oPar->name . ': <b>' . $oVal->value . '</b>';
            }
        }
        return implode('; ', $arPP);
    }], ['attribute' => 'coef1', 'label' => 'Коэффициент', 'format' => 'html', 'value' => function ($model) {
        return $model->coef;
Пример #12
0
 public static function getGoodTypeParams($goodTypeId)
 {
     $goodType = \app\models\GoodsType::findOne($goodTypeId);
     return $goodType->getGoodsParamsNames()->orderBy('sort')->all();
 }
 /**
  * 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');
 }
Пример #14
0
 /**
  * Форма выбора параметров для типа товара $goodType
  * @return mixed
  */
 public function actionGetParamsForm($goodTypeId, $k)
 {
     // Получить отсортированный список параметров для выбранного типа товара
     $goodType = \app\models\GoodsType::findOne($goodTypeId);
     $arGoodsParamsNames = $goodType->getGoodsParamsNames()->orderBy('sort')->all();
     $arParams = [];
     foreach ($arGoodsParamsNames as $oParam) {
         $arParams[$oParam->id]['name'] = $oParam->name;
         if ($oParam->required) {
             $arParams[$oParam->id]['required'] = 1;
         }
         if ($oParam->parent_param) {
             $arParams[$oParam->id]['parent'] = $oParam->parent_param;
         } else {
             $arGoodsParams = $oParam->getGoodsParams()->orderBy('sort')->all();
             // Для каждого параметра получить отсортированный список значений, кроме зависимых
             foreach ($arGoodsParams as $oParamV) {
                 $arParams[$oParam->id]['select'][$oParamV->id] = $oParamV->value;
             }
         }
     }
     $arRes = ['k' => $k, 'params' => $arParams];
     print json_encode($arRes);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $goods = Goods::find($id);
     //栏目下拉框
     $cats = Category::getSelectCats();
     $types = GoodsType::all();
     //获取所有types
     $photos = $goods->photos;
     //to-do
     return view('admin.goods.edit')->with('goods', $goods)->with('types', $types)->with('cats', $cats)->with('photos', $photos);
 }