Пример #1
0
 /**
  * Вывод категории (подкатегории и товары)
  */
 public function actionIndex($id = 0)
 {
     if (!($category = $this->loadModel($id))) {
         $category = new CatalogCategory();
         $category->id = 0;
         $category->title = 'Каталог животных';
     }
     $this->breadcrumbs = CatalogCategory::getParents($category->id);
     $this->breadcrumbs[] = $category->title;
     $category_criteria = new CDbCriteria();
     $category_criteria->compare('parent_id', $category->id);
     $categoryDataProvider = new CActiveDataProvider('CatalogCategory', array('criteria' => $category_criteria, 'sort' => array('defaultOrder' => 'sort_order ASC'), 'pagination' => false));
     $products = new CatalogProduct('search');
     $products->unsetAttributes();
     $products->id_category = $category->id;
     $products->attach = 0;
     if (isset($_GET['CatalogProduct'])) {
         $products->attributes = $_GET['CatalogProduct'];
     }
     $this->render('index', array('products' => $products, 'categoryDataProvider' => $categoryDataProvider, 'category' => $category));
 }
Пример #2
0
 public function actionIndex()
 {
     $this->metaInfoGenerate('Предложить животное', 'Предложить животное', 'Предложить животное');
     $model = new ResponseForm();
     if (isset($_POST['ResponseForm'])) {
         $model->attributes = $_POST['ResponseForm'];
         if ($model->validate()) {
             $product = new CatalogProduct('response');
             $product->attributes = $model->getProductAttributes();
             if ($product->save()) {
                 $admin = User::model()->findByPk(1);
                 $body = $this->renderPartial('template', array_merge(array('product' => $product)), true);
                 if (Yii::app()->getModule('callback')->sendMessage($admin->email, 'Предложение животного с сайта ' . Yii::app()->config->sitename, $body)) {
                     Yii::app()->user->setFlash('callback_message', 'Ваше предложение успешно отправлено администратору сайта.');
                 } else {
                     Yii::app()->user->setFlash('callback_message', 'В данный момент отправка предложения невозможна.');
                 }
             }
         }
     }
     $this->render('index', array('model' => $model));
 }
 public function run()
 {
     // устанавливаем условие для отбора
     $criteria = new CDbCriteria();
     $criteria->select = 't.title,t.photo,t.price,t.link, t.article, t.state';
     $criteria->compare('on_main', true);
     $criteria->with = array('idCategoryFast');
     /*$dataProvider = new CActiveDataProvider('CatalogProduct', array(
                'criteria'=>$criteria,
     		'sort' => array(
     			'defaultOrder' => 'sort_order ASC',
     			),
                'pagination'=>false,
            ));*/
     $products = CatalogProduct::model()->findAll($criteria);
     // Тасуем продукты
     if (is_array($products)) {
         shuffle($products);
     }
     $this->render('prodtomain', array('products' => $products));
     return parent::run();
 }
Пример #4
0
 public function parseUrl($manager, $request, $pathInfo, $rawPathInfo)
 {
     if (preg_match('%^(/?([\\w\\-.]+))+$%', $pathInfo, $matches)) {
         //разбиваем путь по слешам и берем последнюю составляющую пути
         $pages = preg_split("/\\//", $pathInfo);
         //$element = end($pages);
         $element_arr = explode('.', end($pages));
         $element = $element_arr[0];
         if (in_array('brands', $pages)) {
             if (count($pages) == 3) {
                 if ($brand = CatalogBrands::model()->find(array('select' => 'id', 'condition' => 'link=:link', 'params' => array(':link' => $element)))) {
                     return 'catalog/brands/index/view/' . $element;
                 } else {
                     return false;
                 }
             } elseif (count($pages) == 4) {
                 return 'catalog/brands/index/view/' . $pages[2] . '/coll/' . $element;
             } else {
                 return false;
             }
         } else {
             if ($page = CatalogCategory::model()->find(array('select' => 'id', 'condition' => 'link=:link', 'params' => array(':link' => $element)))) {
                 // если есть - преобразуем адрес
                 return '/catalog/default/category/link/' . $element;
             } else {
                 // если такой категории нет - проверяем, может быть есть такой товар
                 if ($product = CatalogProduct::model()->find(array('select' => 'id', 'condition' => 'link=:link', 'params' => array(':link' => $element)))) {
                     // если есть - преобразуем адрес
                     return '/catalog/default/product/id/' . $product->id;
                 } else {
                     // если нет - не применяем правило
                     return false;
                 }
             }
         }
     }
     return false;
     // не применяем данное правило
 }
Пример #5
0
					<?php 
$attached = CatalogProduct::getAttachCount();
?>
					<div class="helps" title="Мы помогли найти дом <?php 
echo $attached;
?>
 питомцам">
						<div class="att"><?php 
echo $attached;
?>
</div>
						<div>Мы помогли найти дом <?php 
echo $attached;
?>
 <?php 
echo CatalogProduct::getAttachWordForm($attached);
?>
</div>
					</div>
				</div>
				<div class="track-line"></div>
				<div class="bot">
					<div class="bot-l">
						<?php 
if ($this->layout == 'first_page') {
    ?>
							<a href="/ja-hochu-pomoch" class="s-btn">Я хочу помочь</a>
							<a href="/catalog/response" class="s-btn par">Предложить животное</a>
						<?php 
} else {
    ?>
Пример #6
0
 public function getExistingParameters()
 {
     // Выбираем все товары из категории
     /*$criteria=new CDbCriteria;
       //$criteria->compare('id_category', $this->id);
       //$criteria->compare('hide', 0);
       $criteria->condition='id_category=:id_category AND (hide=0 OR hide is NULL)';
       $criteria->params=array(':id_category'=>$this->id);
       $products=CatalogProduct::model()->findAll($criteria);*/
     // Возвращаем массив используемых значений
     return CatalogProduct::getAllExistedParameters($this->catalogProductsForExist);
     //return CatalogProduct::getAllExistedParameters($products);
 }
Пример #7
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = CatalogProduct::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Пример #8
0
 public function run()
 {
     /**
      * КАТЕГОРИИ
      */
     CatalogCategory::create(array('id' => 1, 'active' => 1, 'slug' => 'bicycles', 'lft' => 1, 'rgt' => 8));
     CatalogCategoryMeta::create(array('category_id' => 1, 'language' => 'ru', 'active' => 1, 'name' => 'Велосипеды'));
     CatalogCategoryMeta::create(array('category_id' => 1, 'language' => 'en', 'active' => 1, 'name' => 'Bicycles'));
     CatalogCategory::create(array('id' => 2, 'active' => 1, 'slug' => 'mountain', 'lft' => 2, 'rgt' => 3));
     CatalogCategoryMeta::create(array('category_id' => 2, 'language' => 'ru', 'active' => 1, 'name' => 'Горные'));
     CatalogCategory::create(array('id' => 3, 'active' => 1, 'slug' => 'road', 'lft' => 4, 'rgt' => 5));
     CatalogCategoryMeta::create(array('category_id' => 3, 'language' => 'ru', 'active' => 1, 'name' => 'Шоссейные'));
     CatalogCategory::create(array('id' => 4, 'active' => 1, 'slug' => 'city', 'lft' => 6, 'rgt' => 7));
     CatalogCategoryMeta::create(array('category_id' => 4, 'language' => 'ru', 'active' => 1, 'name' => 'Городские'));
     CatalogCategory::create(array('id' => 5, 'active' => 1, 'slug' => 'pc', 'lft' => 9, 'rgt' => 10));
     CatalogCategoryMeta::create(array('category_id' => 5, 'language' => 'ru', 'active' => 1, 'name' => 'Компьютеры'));
     /**
      * ТОВАРЫ
      */
     CatalogProduct::create(array('id' => 1, 'active' => 1, 'category_id' => 1, 'slug' => 'normal_bike', 'article' => 'sku0001', 'amount' => '5', 'lft' => 1, 'rgt' => 2));
     CatalogProductMeta::create(array('product_id' => 1, 'language' => 'ru', 'active' => 1, 'name' => 'Обычный велосипед', 'description' => 'Какое-то описание продукта...', 'price' => '25000'));
     CatalogProduct::create(array('id' => 2, 'active' => 1, 'category_id' => 1, 'slug' => 'normal_bike_2', 'article' => 'sku0002', 'amount' => '5', 'lft' => 3, 'rgt' => 4));
     CatalogProductMeta::create(array('product_id' => 2, 'language' => 'ru', 'active' => 1, 'name' => 'Обычный велосипед 2', 'description' => 'Какое-то описание продукта...', 'price' => '25000'));
     CatalogProduct::create(array('id' => 3, 'active' => 1, 'category_id' => 1, 'slug' => 'normal_bike_3', 'article' => 'sku0003', 'amount' => '5', 'lft' => 5, 'rgt' => 6));
     CatalogProductMeta::create(array('product_id' => 3, 'language' => 'ru', 'active' => 1, 'name' => 'Обычный велосипед 3', 'description' => 'Какое-то описание продукта...', 'price' => '25000'));
     /**
      * АТРИБУТЫ
      */
     CatalogAttributeGroup::create(array('id' => 1, 'category_id' => 1, 'active' => 1, 'slug' => 'default', 'lft' => 1, 'rgt' => 2));
     CatalogAttributeGroupMeta::create(array('attributes_group_id' => 1, 'language' => 'ru', 'active' => 1, 'name' => 'По умолчанию'));
     CatalogAttribute::create(array('id' => 1, 'active' => 1, 'slug' => 'wheel_radius', 'attributes_group_id' => 1, 'type' => 'text', 'lft' => 1, 'rgt' => 2));
     CatalogAttributeMeta::create(array('attribute_id' => 1, 'language' => 'ru', 'active' => 1, 'name' => 'Радиус колеса'));
     CatalogAttribute::create(array('id' => 2, 'active' => 1, 'slug' => 'material', 'attributes_group_id' => 1, 'type' => 'textarea', 'lft' => 3, 'rgt' => 4));
     CatalogAttributeMeta::create(array('attribute_id' => 2, 'language' => 'ru', 'active' => 1, 'name' => 'Материал рамы'));
     CatalogAttributeGroup::create(array('id' => 2, 'category_id' => 1, 'active' => 1, 'slug' => 'additional', 'lft' => 3, 'rgt' => 4));
     CatalogAttributeGroupMeta::create(array('attributes_group_id' => 2, 'language' => 'ru', 'active' => 1, 'name' => 'Дополнительно'));
     CatalogAttribute::create(array('id' => 3, 'active' => 1, 'slug' => 'flashlight', 'attributes_group_id' => 2, 'type' => 'checkbox', 'lft' => 5, 'rgt' => 6));
     CatalogAttributeMeta::create(array('attribute_id' => 3, 'language' => 'ru', 'active' => 1, 'name' => 'Наличие фары освещения'));
     CatalogAttribute::create(array('id' => 4, 'active' => 1, 'slug' => 'breaks', 'attributes_group_id' => 2, 'type' => 'select', 'settings' => '{"selectable":1}', 'lft' => 7, 'rgt' => 8));
     CatalogAttributeMeta::create(array('attribute_id' => 4, 'language' => 'ru', 'active' => 1, 'name' => 'Тормоза', 'settings' => '{"values":"\\u0414\\u0438\\u0441\\u043a\\u043e\\u0432\\u044b\\u0435\\n\\u041a\\u043e\\u043b\\u043e\\u0434\\u043e\\u0447\\u043d\\u044b\\u0435"}'));
     /**
      * ЗНАЧЕНИЯ АТРИБУТОВ для ТОВАРА
      */
     CatalogAttributeValue::create(array('product_id' => 1, 'attribute_id' => 1, 'language' => 'ru', 'value' => 'R22'));
     CatalogAttributeValue::create(array('product_id' => 1, 'attribute_id' => 2, 'language' => 'ru', 'value' => '', 'settings' => '{"value":"\\u041a\\u0430\\u0440\\u0431\\u043e\\u043d\\/\\u0430\\u043b\\u044e\\u043c\\u0438\\u043d\\u0438\\u0439"}'));
     CatalogAttributeValue::create(array('product_id' => 1, 'attribute_id' => 3, 'language' => 'ru', 'value' => '1'));
     CatalogAttributeValue::create(array('product_id' => 1, 'attribute_id' => 4, 'language' => 'ru', 'value' => 'Дисковые'));
     /**
      * СТАТУСЫ ЗАКАЗОВ
      */
     CatalogOrderStatus::create(array('id' => 1, 'sort_order' => 1));
     CatalogOrderStatusMeta::create(array('status_id' => 1, 'language' => 'ru', 'title' => 'В обработке'));
     CatalogOrderStatus::create(array('id' => 2, 'sort_order' => 2));
     CatalogOrderStatusMeta::create(array('status_id' => 2, 'language' => 'ru', 'title' => 'Ожидает оплаты'));
     CatalogOrderStatus::create(array('id' => 3, 'sort_order' => 3));
     CatalogOrderStatusMeta::create(array('status_id' => 3, 'language' => 'ru', 'title' => 'Оплачен'));
     CatalogOrderStatus::create(array('id' => 4, 'sort_order' => 4));
     CatalogOrderStatusMeta::create(array('status_id' => 4, 'language' => 'ru', 'title' => 'Ожидает отправки'));
     CatalogOrderStatus::create(array('id' => 5, 'sort_order' => 5));
     CatalogOrderStatusMeta::create(array('status_id' => 5, 'language' => 'ru', 'title' => 'Завершен'));
     /**
      * ЗАКАЗЫ
      */
     CatalogOrder::create(array('id' => 1, 'status_id' => 4, 'total_sum' => 120000, 'client_id' => NULL, 'client_name' => 'Покупатель', 'delivery_info' => 'г.Ростов-на-Дону, ул Суворова 52а, оф.301', 'comment' => 'Комментарий покупателя к заказу'));
     CatalogOrderProduct::create(array('order_id' => 1, 'product_id' => 1, 'count' => 2, 'price' => 25000, 'product_cache' => '[]'));
     CatalogOrderProductAttribute::create(array('order_id' => 1, 'product_id' => 1, 'attribute_id' => 4, 'attribute_cache' => 'Тормоза', 'value' => 'Дисковые'));
     CatalogOrderProduct::create(array('order_id' => 1, 'product_id' => 2, 'count' => 3, 'price' => 24000, 'product_cache' => '[]'));
     CatalogOrderProductAttribute::create(array('order_id' => 1, 'product_id' => 2, 'attribute_id' => 4, 'attribute_cache' => 'Тормоза', 'value' => 'Колодочные'));
     CatalogOrderProduct::create(array('order_id' => 1, 'product_id' => 3, 'count' => 1, 'price' => 23000, 'product_cache' => '[]'));
     CatalogOrderProductAttribute::create(array('order_id' => 1, 'product_id' => 3, 'attribute_id' => 4, 'attribute_cache' => 'Тормоза', 'value' => 'Без тормозов'));
     /**
      * ИСТОРИЯ СТАТУСОВ ЗАКАЗА
      */
     CatalogOrderStatusHistory::create(array('order_id' => 1, 'status_id' => 1, 'comment' => 'Заказ сделан, ожидает обработки...', 'changer_name' => 'Покупатель'));
     CatalogOrderStatusHistory::create(array('order_id' => 1, 'status_id' => 2, 'comment' => 'Менеджер обработал заказ, ожидание оплаты', 'changer_name' => 'Продавец'));
     CatalogOrderStatusHistory::create(array('order_id' => 1, 'status_id' => 3, 'comment' => 'Покупатель оплатил товар', 'changer_name' => 'Покупатель'));
     CatalogOrderStatusHistory::create(array('order_id' => 1, 'status_id' => 4, 'comment' => 'Товар был успешно оплачен, ожидание отправки', 'changer_name' => 'Продавец'));
 }
Пример #9
0
 public function getMaxSortOrder()
 {
     $models = CatalogProduct::model()->findAll();
     foreach ($models as $model) {
         $sort_orders[] = $model->sort_order;
     }
     if (!empty($sort_orders)) {
         arsort($sort_orders);
         $max_order = current($sort_orders);
     } else {
         $max_order = 0;
     }
     return $max_order;
 }
Пример #10
0
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     // если формируем ссылку на категорию
     if ($route == 'category') {
         if (isset($params['link'])) {
             return '/catalog' . CatalogCategory::getCategoryRoute($params['link']);
         }
     }
     // если формируем ссылку на товар
     if ($route == 'product') {
         // если передано id товара
         if (isset($params['id'])) {
             // если существует такой продукт
             if ($product = CatalogProduct::model()->find(array('condition' => 'id=:id', 'params' => array(':id' => $params['id'])))) {
                 // берем категорию продукта
                 $category = CatalogCategory::model()->with('parentShort')->findByPk($product->id_category);
                 // возвращаем путь к категории товара и прибавляем в конце id
                 return '/catalog' . CatalogCategory::getCategoryRouteFast($category) . '/' . $product->id;
             }
         }
     }
     // если условия не сработали - формируем адрес обычным образом
     return parent::createUrl($route, $params, $ampersand);
 }