/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = GoodsParams::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(['id' => $this->id, 'sort' => $this->sort, 'link_category' => $this->link_category]); $query->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'public_value', $this->public_value])->andFilterWhere(['like', 'goods_params_name_id', $this->goods_params_name_id]); return $dataProvider; }
/** * * @param type $id * @return type */ public static function getName($id, $mode = 'name') { $good = \app\models\Goods::findOne($id); \app\models\GoodsT::$tabName = self::$goodTablePefix . $good->goods_type_type; $goodT = \app\models\GoodsT::findOne($id); // $arGoodsParamsNames = self::getGoodTypeParams($good->goods_type_type); $goodType = \app\models\GoodsType::findOne($good->goods_type_type); $arGoodsParamsNames = $goodType->getGoodsParamsNames()->orderBy('sort')->all(); $arParams = ['goodType' => $goodType->name]; foreach ($arGoodsParamsNames as $oParam) { $idParamVal = $goodT->{$oParam->id}; $oParamValue = \app\models\GoodsParams::findOne($idParamVal); $arParams[$oParam->id] = $oParamValue->public_value ? $oParamValue->public_value == \Yii::$app->params['emptyStringParam'] ? '' : $oParamValue->public_value : $oParamValue->value; } $tpl = $goodType->template_view; if ($mode == 'array') { return ['name' => self::fullName($arParams, $tpl), 'goodTipe' => $goodType, 'good' => $good, 'params' => $arGoodsParamsNames, 'values' => $arParams]; } return self::fullName($arParams, $tpl); }
/** * Finds the GoodsParams model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return GoodsParams the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = GoodsParams::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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']]); }
public function actionRefreshRender($val) { $arRes = []; $arVals = explode(';', $val); foreach ($arVals as $val) { $oVal = \app\models\GoodsParams::findOne($val); // print ('<pre>');print_r($oVal);print('</pre>'); // $oPar = $oVal->getGoodsParamsName(); $oPar = \app\models\GoodsParamsNameSearch::findOne($oVal->goods_params_name_id); // print ('<pre>');print_r($oPar);print('</pre>');exit('100'); $arRes[$oPar->id] = ['paramId' => $oPar->id, 'paramName' => $oPar->name, 'valId' => $oVal->id, 'valValue' => $oVal->value]; } print json_encode(['res' => 'ok', 'items' => $arRes]); }
/** * @return \yii\db\ActiveQuery */ public function getGoodsParams() { return $this->hasMany(GoodsParams::className(), ['goods_params_name_id' => 'id']); }
/** * Список значений параметра зависимого от $parentParam * @return mixed */ public function actionGetChildParams($k, $paramId, $parentParamVal) { $GoodsParams = \app\models\GoodsParams::find()->where('link_category=:parentId AND goods_params_name_id=:goods_params_name_id', [':parentId' => $parentParamVal, ':goods_params_name_id' => $paramId])->orderBy('sort')->all(); $arParams = []; foreach ($GoodsParams as $oParam) { $arParams[$oParam->id] = $oParam->value; } $arRes = ['k' => $k, 'paramId' => $paramId, 'params' => $arParams]; print json_encode($arRes); }