/** * Updates an existing GoodsType model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { $arObjParams = \app\models\GoodsParamsName::find()->where('goods_type_type=:goods_type_type', [':goods_type_type' => $id])->all(); return $this->render('update', ['arObjParams' => $arObjParams, 'model' => $model]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = GoodsParamsName::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(['required' => $this->required, 'sort' => $this->sort]); $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'data_type', $this->data_type])->andFilterWhere(['like', 'parent_param', $this->parent_param])->andFilterWhere(['like', 'goods_type_type', $this->goods_type_type]); return $dataProvider; }
public function actionLinkFilerRows($paramId, $parentParamId) { $paramsName = \app\models\GoodsParamsName::findOne($paramId); if ($parentParamId) { $paramsValues = \app\models\GoodsParams::find()->where('goods_params_name_id = :goods_params_name_id AND link_category = :link_category', [':goods_params_name_id' => $paramId, ':link_category' => $parentParamId])->all(); } else { $paramsValues = \app\models\GoodsParams::find()->where('goods_params_name_id = :goods_params_name_id', [':goods_params_name_id' => $paramId])->all(); } $data = \yii\helpers\ArrayHelper::map($paramsValues, 'id', 'value'); $arRes = ['title' => $paramsName->name, 'name' => $paramsName->id, 'data' => ['' => ' - Все - '] + $data, 'parent_param' => $paramsName->parent_param, 'ch' => '']; header('Content-Type: utf-8'); // print $this->renderPartial('_row_filter', $arRes); $arRres = ['paramId' => $paramId, 'html' => $this->renderPartial('_row_filter', $arRes)]; print json_encode($arRres); }
/** * Deletes an existing GoodsParams model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionTech() { exit; $GoodsParamsName = \app\models\GoodsParamsName::find()->all(); foreach ($GoodsParamsName as $gpn) { print '============================== <br>'; print $gpn->id . '<br>'; $oGP = \app\models\GoodsParams::find()->where('goods_params_name_id=:goods_params_name_id', [':goods_params_name_id' => $gpn->id])->all(); // print ('<pre>');print_r($oGP);print('</pre>'); $arGP = \yii\helpers\ArrayHelper::map($oGP, 'id', 'id'); print implode(',', $arGP) . '<br>'; if (count($arGP) == 0) { continue; } // $goods = \app\components\Goods::find($gpn->goods_type_type, $gpn->id . ' not in (:ids)', [':ids' => implode(',',$arGP)])->all(); $goods = \app\components\Goods::find($gpn->goods_type_type, $gpn->id . ' not in (' . implode(',', $arGP) . ')', [])->all(); foreach ($goods as $good) { $ar = \yii\helpers\ArrayHelper::toArray($good); print '<pre>'; print_r($ar); print '</pre>'; \app\models\Goods::deleteAll('id=:goods_id', [':goods_id' => $good->goods_id]); } } }
/** * Finds the GoodsParamsName model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return GoodsParamsName the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = GoodsParamsName::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionGetTypeParams($type) { $params = \app\models\GoodsParamsName::find()->where('goods_type_type=:goods_type_type', [':goods_type_type' => $type])->orderBy('sort ASC')->all(); $arParams = ['' => ' - Добавить параметр - ']; $arLinks = []; foreach ($params as $param) { $arParams[$param->id] = $param->name; if ($param->parent_param) { $arLinks[$param->id] = $param->parent_param; } } print '<script>oLinks = ' . json_encode($arLinks) . '</script>'; print \yii\helpers\BaseHtml::dropDownList('listParams', '', $arParams); }
<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; }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> <?php } ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getGoodsParamsName() { return $this->hasOne(GoodsParamsName::className(), ['id' => 'goods_params_name_id']); }
/** * @return \yii\db\ActiveQuery */ public function getGoodsParamsNames() { return $this->hasMany(GoodsParamsName::className(), ['goods_type_type' => 'type']); }