Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionView($url)
- {
- $category = Categories::model()->find(array('condition'=>'alias="' . $url . '" AND visible=1', 'limit'=>1));
- if ($category == null)
- throw new CHttpException(404, 'Запрашиваемая страница не найдена.');
- $subcategories = Categories::model()->count(array('condition'=>'parent_id=' . $category->id));
- if ($subcategories == 0)
- {
- $ids = array();
- $filter_values = array();
- $page_size = 10;
- if (isset($_POST['Filter']) || isset($_POST['Cost']))
- {
- $cost = null;
- if (isset($_POST['Cost']))
- {
- $cost = Yii::app()->request->getPost('Cost');
- $tmp = explode(";", $cost['prices']);
- $cost['start'] = $tmp[0];
- $cost['finish'] = $tmp[1];
- if (!empty($cost['finish']) && !empty($cost['start']) && $cost['start'] > $cost['finish'])
- $cost['start'] = $cost['finish'];
- }
- $page_size = 100;
- $list = array();
- $goods = array();
- $goods_list = Goods::model()->findAll(array('condition'=>'visible=1 AND category_id=' . $category->id, 'order'=>((int)$_POST['sort'] == 2 ? 'price9 DESC' : 'price9 ASC')));
- foreach($goods_list as $item)
- {
- $goods[$item->id] = array();
- $goods[$item->id]['id'] = $item->id;
- $goods[$item->id]['show_price'] = $item->show_price;
- $goods[$item->id]['price1'] = $item->price1;
- $goods[$item->id]['price2'] = $item->price2;
- $goods[$item->id]['price3'] = $item->price3;
- $goods[$item->id]['price4'] = $item->price4;
- $goods[$item->id]['price5'] = $item->price5;
- $goods[$item->id]['price6'] = $item->price6;
- $goods[$item->id]['price8'] = $item->price8;
- $goods[$item->id]['price9'] = $item->price9;
- $list[] = $item->id;
- }
- $criteria_price = new CDbCriteria();
- $criteria_price->addCondition('visible', 1);
- $criteria_price->addInCondition('good_id', $list);
- $filter_values = FilterGoods::model()->findAll($criteria_price);
- foreach($filter_values as $item)
- {
- $goods[$item->good_id][$item->filter_id] = str_replace(",", ".", $item->value_id);
- }
- $values = Yii::app()->request->getPost('Filter');
- $posted = array();
- foreach($values as $item => $key)
- {
- if (strpos($key, ';') !== false)
- {
- $tmp = explode(";", $key);
- $posted[$item] = array('id'=>$item, 'start'=>$tmp[0], 'finish'=>$tmp[1]);
- }
- else if ($key != '- Выберите значение -')
- $posted[$item] = array('id'=>$item, 'value'=>$key);
- }
- foreach($goods as $item)
- {
- $deleted = false;
- if (!isset($cost['only']) && $cost != null && $item['show_price'] == 0)
- {
- unset($goods[$item['id']]);
- $deleted = true;
- }
- if (!$deleted && $cost != null && $item['show_price'] == 1 && ($cost['start'] > $item['price9'] || $cost['finish'] < $item['price9']))
- {
- unset($goods[$item['id']]);
- $deleted = true;
- }
- if (!$deleted)
- {
- foreach($posted as $tmp)
- {
- if (!$deleted)
- {
- if(isset($tmp['value']))
- {
- if (!isset($item[$tmp['id']]) || $tmp['value'] != $item[$tmp['id']])
- {
- unset($goods[$item['id']]);
- $deleted = true;
- }
- }
- else
- {
- if (!isset($item[$tmp['id']]) || $tmp['start'] > $item[$tmp['id']] || $tmp['finish'] < $item[$tmp['id']])
- {
- unset($goods[$item['id']]);
- $deleted = true;
- }
- }
- }
- }
- }
- }
- if (count($goods) == 0 && gettype($goods) == 'array')
- $ids[] = 0;
- else
- {
- foreach($goods as $item)
- $ids[] = $item['id'];
- }
- }
- $criteria = new CDbCriteria();
- $criteria->condition = 'category_id=' . $category->id;
- if (count($ids) > 0)
- $criteria->addInCondition('id', $ids);
- if (isset($_POST['sort']) && is_numeric($_POST['sort']) && (int)$_POST['sort'] !== 0)
- $criteria->order = ((int)$_POST['sort'] == '2' ? 'price9 ASC' : 'price9 DESC');
- $dataProvider=new CActiveDataProvider('Goods', array(
- 'criteria'=>$criteria,
- 'pagination'=>array(
- 'pageSize'=>$page_size,
- 'pageVar'=>'page',
- ),
- 'sort'=>array(
- 'defaultOrder'=>array(
- 'name'=>CSort::SORT_ASC,
- )
- )
- ));
- $content_type = ContentType::getField("category", $category->id, "description-text", 9);
- $this->render('view', array(
- 'category'=>$category,
- 'dataProvider'=>$dataProvider,
- 'pages'=>$pages,
- 'breadcrumbs' => Categories::getBreadCrumbs($category->parent_id),
- 'content_text'=>$content_type,
- ));
- }
- else
- {
- $content = '';
- $sub = Categories::model()->findAll(array('condition'=>'parent_id=' . $category->id, 'order'=>'name ASC'));
- foreach($sub as $item)
- {
- $goods = '';
- $goods_list = GoodsCategory::model()->findAll(array('condition'=>'visible=1 AND category_id=' . $item->id, 'limit'=>4, 'order'=>'sort DESC, RAND()'));
- foreach($goods_list as $tmp)
- {
- $good = Goods::model()->findByPk($tmp->good_id);
- $image = GoodsImages::model()->find(array('condition'=>'good_id=' . $tmp->good_id));
- $goods .= '<div class="col-md-3 goods text-center"><a href="/good/' . $good->id . '" class="title" title="' . $good->name . '"><img src="' . (strpos($image->image, 'http://') > 0 ? $image->image : '/images/goods/' . $image->image) . '" alt="' . $good->name . '" class="img-responsive" style="display:block;margin:0 auto 9px;height:120px"><div>' . mb_substr($good->name, 0, 32, 'UTF-8') . '...</div></a><div class="price">' . ($good->price9 > 0 ? '<span>' . $good->price9 . '</span> р.' : '<b alt="' . $good->id . '">Узнать цену</b>') . '</div><a href="javascript://" class="buy" rel="' . $good->id . '"><strong>+</strong> В корзину</a></div>' . PHP_EOL;
- }
- if (empty($goods))
- $goods = $item->small_description;
- $content .= '<div style="padding-top:0px"><a href="/catalog/' . $item->alias . '" class="pull-right btn btn-primary btn-sm">Перейти в категорию</a><div class="content_title"><a href="/catalog/' . $item->alias . '" style="color:#333">' . $item->name . '</a></div><div class="content_desc"><div class="row best_goods">' . $goods . '</div></div></div>' . PHP_EOL;
- }
- $content_type = ContentType::getField("category", $category->id, "description-text", 9);
- $this->render('subview', array(
- 'category'=>$category,
- 'content'=>$content,
- 'breadcrumbs' => Categories::getBreadCrumbs($category->parent_id),
- 'content_text'=>$content_type,
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement