public function loadModel($id) { if (($model = StoneSeoPage::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
public function run() { if (empty($this->type) || empty($this->series)) { return; } $colorLinks = StoneSeoPage::model()->published()->type($this->type->id)->series($this->series->id)->findAll(array('condition' => 'color_id IS NOT NULL AND country_id IS NULL', 'order' => 't.sort ASC')); $countryLinks = StoneSeoPage::model()->published()->type($this->type->id)->series($this->series->id)->findAll(array('condition' => 'country_id IS NOT NULL AND color_id IS NULL', 'order' => 't.sort ASC')); if (empty($colorLinks) && empty($countryLinks)) { return; } $this->render($this->view, array('colorLinks' => $colorLinks, 'countryLinks' => $countryLinks, 'series' => $this->series, 'type' => $this->type)); }
/** * Returns the static model of the specified AR class. * @return Category the static model class */ public static function model($className = __CLASS__) { return parent::model($className); }
public function actionSyncSeoPages() { $oldPages = StoneSeoPageOld::model()->findAll(array('condition' => 't.full_text != ""')); $counter = 0; foreach ($oldPages as $oldPage) { $counter++; echo $counter . '. ' . $oldPage->title . '<br />'; $newPage = StoneSeoPage::model()->findByAttributes(array('type_id' => ProductType::STONES_CATALOG_ID, 'series_id' => $oldPage->series_id, 'color_id' => $oldPage->color_id, 'country_id' => $oldPage->country_id)); echo $newPage->title . '<hr />'; $newPage->full_text = $oldPage->full_text; $newPage->update(array('full_text')); } }
public function actionIndex($type = '', $series = '') { $type = trim($type); $type = $type == '' ? 'stone' : $type; $productType = ProductType::model()->published()->findByAlias($type); if (!$productType) { throw new CHttpException(404); } $page = $productType; //$this->processPageRequest('page'); $series = trim($series); $filter = array(); $seoFilter = array('series_id' => null, 'color_id' => null, 'country_id' => null); $seoFlag = false; // Список видов камней $seriesList = Series::model()->published()->findAll(array('order' => 't.sort ASC')); // Определяем, выбран или нет вид камня $currentSeries = null; $currentColor = null; $currentCountry = null; if (!empty($series)) { // Если выбран вид камня $currentSeries = Series::model()->published()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC'), 'images' => array('scopes' => 'published', 'order' => 'images.sort ASC')))->find('t.alias = :alias', array(':alias' => $series)); if (!$currentSeries) { throw new CHttpException(404); } $filter['series_id'] = $currentSeries->id; $seoFilter['series_id'] = $currentSeries->id; $seoFlag = true; // Если выбран цвет или страна if (isset($_GET['colorCountry'])) { $code = trim($_GET['colorCountry']); $currentDictData = DictionaryData::model()->active()->with('group')->findByCode($code); if ($currentDictData !== null) { if ($currentDictData->group->code == 'colors') { $currentColor = $currentDictData; $seoFilter['color_id'] = $currentColor->id; } elseif ($currentDictData->group->code == 'country') { $currentCountry = $currentDictData; $seoFilter['country_id'] = $currentCountry->id; } } } // Если выбран только цвет if (isset($_GET['color'])) { $code = trim($_GET['color']); $currentColor = DictionaryData::model()->active()->findByCode($code); if ($currentColor !== null) { $seoFilter['color_id'] = $currentColor->id; } } // Если выбрана только страна if (isset($_GET['country'])) { $code = trim($_GET['country']); $currentCountry = DictionaryData::model()->active()->findByCode($code); if ($currentCountry !== null) { $seoFilter['country_id'] = $currentCountry->id; } } } if ($seoFlag) { $seoPage = StoneSeoPage::model()->published()->type($productType->id)->findByAttributes($seoFilter); $page = $seoPage !== null ? $seoPage : $page; } // Список товаров $model = new Stone('user_search'); $model->unsetAttributes(); $model->type_id = $productType->id; // Если выбран вид камня if (!empty($currentSeries)) { $model->series_id = $currentSeries->id; } // Если выбран цвет камня if (!empty($currentColor)) { $model->color_id = $currentColor->id; $filter['color_id'] = $currentColor->id; } // Если выбрана страна if (!empty($currentCountry)) { $model->country_id = $currentCountry->id; $filter['country_id'] = $currentCountry->id; } if (isset($_GET['Stone'])) { $model->attributes = $_GET['Stone']; if ($model->title != '') { $filter['title'] = $model->title; } if (!empty($model->color_id)) { $filter['color_id'] = $model->color_id; } if (!empty($model->country_id)) { $filter['country_id'] = $model->country_id; } } // Поиск товаров $dataProvider = $model->user_search(); // Сохраняем ссылку для возврата Yii::app()->user->setState('stoneCatalogReturnUrl', Yii::app()->request->requestUri); //var_dump(Yii::app()->user->getState('stoneCatalogReturnUrl')); // Сохраняем данные фильтра в сессии //$filter['page'] = (int) Yii::app()->request->getParam('page', 1); Yii::app()->user->setState('stoneCatalogFilter', $filter); if (Yii::app()->request->isAjaxRequest) { // Обновление списка для бесконечной загрузки элементов if (isset($_GET['showMore'])) { $this->renderPartial('_list_ajax', array('dataProvider' => $dataProvider, 'pageNumber' => (int) Yii::app()->request->getParam('page', 1))); } else { $this->renderPartial('_list', array('dataProvider' => $dataProvider, 'productType' => $productType), false, true); } Yii::app()->end(); } else { // Вывод каталога $this->render('index', array('page' => $page, 'model' => $model, 'dataProvider' => $dataProvider, 'seriesList' => $seriesList, 'series' => $currentSeries, 'productType' => $productType)); } }