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); }
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']]); }
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); }
/** * 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.'); } }
} ?> </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;
public static function getGoodTypeParams($goodTypeId) { $goodType = \app\models\GoodsType::findOne($goodTypeId); return $goodType->getGoodsParamsNames()->orderBy('sort')->all(); }
/** * Форма выбора параметров для типа товара $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); }