Ejemplo n.º 1
0
 public function actionSearch()
 {
     $objects = array();
     $criteria = new CDbCriteria();
     $criteria->alias = 'co';
     $criteria->condition = "is_active = 1 AND is_deleted = 0";
     $criteria->addCondition("lang_id = " . $this->lang);
     $criteria->addCondition("category_id = 1");
     //@todo - искать в реальной категории
     if (isset($_REQUEST['data'])) {
         $data = $_REQUEST['data'];
         if (is_array($data) && count($data)) {
             $criteria->join = "";
             $i = 0;
             foreach ($data as $fieldName => $items) {
                 $field = CatalogFilteredFields::model()->findByAttributes(array("category_id" => 1, "name" => $fieldName));
                 if (is_object($field) && is_array($items) && count($items)) {
                     $cond = '(';
                     $i1 = true;
                     foreach ($items as $item) {
                         if (is_numeric($item)) {
                             if (!$i1) {
                                 $cond .= "OR (`fv{$i}`.`field_id` = {$field->id} AND `fv{$i}`.`int_val` = {$item}) ";
                             } else {
                                 $cond .= "(`fv{$i}`.`field_id` = {$field->id} AND `fv{$i}`.`int_val` = {$item}) ";
                                 $i1 = false;
                             }
                         }
                     }
                     $cond .= ')';
                     $criteria->join .= "INNER JOIN `catalog_filtered_fields_values` AS `fv{$i}` ON `co`.`id` = `fv{$i}`.`object_id` " . "AND {$cond} ";
                     $i++;
                 }
             }
         }
     }
     //$criteria->group = "object_id";
     if (isset($_REQUEST['min_price']) && isset($_REQUEST['max_price'])) {
         //$criteria->join = "LEFT JOIN `catalog_objects` ON `catalog_filtered_fields_values`.`object_id` = `catalog_objects`.`id`";
         $criteria->addBetweenCondition('price', CatalogObjects::convertPrice($_REQUEST['min_price']), CatalogObjects::convertPrice($_REQUEST['max_price']));
     }
     $count = CatalogObjects::model()->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 2;
     $pages->applyLimit($criteria);
     $objects = CatalogObjects::model()->findAll($criteria);
     $this->renderPartial('objects', array('objects' => $objects, 'pages' => $pages));
 }
Ejemplo n.º 2
0
</option>
                                            <?php 
    }
}
?>
                                </select>
                            </div>
                        </div>
                        <div class="col-lg-8">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    Наименования в заказе
                                </div>
                                <div class="panel-body">
                                    <?php 
$objects = new CatalogObjects('search');
$objects->unsetAttributes();
if (isset($_GET['CatalogObjects'])) {
    $model->attributes = $_GET['CatalogObjects'];
}
$this->widget('CCustomGridView', array('id' => 'order-items-grid', 'dataProvider' => $objects->search(), 'filter' => $objects, 'columns' => array('id', array('name' => 'category_id', 'type' => 'raw', 'value' => 'CatalogCategories::model()->findByPk($data->category_id)->name'), 'name', 'price', array('class' => 'CCustomButtonColumn', 'template' => '{update}', 'buttons' => array('update' => array('url' => 'Support::doImplode(array($data->primaryKey, $data->name), "|")', 'label' => '<i class="fa fa-plus"></i>', 'options' => array('class' => 'btn btn-primary btn-circle append-order-item', 'title' => 'Добавить к заказу')))))));
?>
                                    <table class="table table-striped order-items-list" style="display:none;">
                                        <thead>
                                            <th style="width: 50%;">Название</th>
                                            <th>Количество</th>
                                            <th style="width: 100px;" class="text-center">Действие</th>
                                        </thead>
                                        <tbody>

                                        </tbody>
Ejemplo n.º 3
0
                </div>
            </div>
        </div>
        </form>  
        <form action="/admin/catalog/saveRelations/?id=<?php 
echo is_object($model) ? $model->id : 0;
?>
" id="catalog-relations" method="post" role="form">
            <input type="hidden" name="related" value="" />
            <div class="panel panel-default">
                <div class="panel-heading clearfix">
                    <select class="rel-selector select2">
                        <?php 
$criteria = new CDbCriteria();
$criteria->condition = "id <> " . $model->id;
$items = CatalogObjects::model()->findAll($criteria);
?>
                        <option value="0">Выберите товар...</option>
                        <?php 
if (is_array($items) && count($items)) {
    foreach ($items as $item) {
        ?>
                                <option value="<?php 
        echo $item->id;
        ?>
" data-url="/admin/catalog/edit/<?php 
        echo $item->id;
        ?>
"><?php 
        echo $item->field("artikul")->value();
        ?>
Ejemplo n.º 4
0
 public function actionDelete()
 {
     $success = false;
     $id = $_REQUEST['id'];
     if (is_numeric($id)) {
         $model = CatalogCategories::model()->findByPk($id);
         if (is_object($model)) {
             $anons_pic = Yii::app()->basePath . "/.." . $model->anons_pic;
             $content_pic = Yii::app()->basePath . "/.." . $model->content_pic;
             //remove category, objects in category and tags relations
             $categoryId = $model->id;
             if ($model->delete()) {
                 $success = true;
                 //remove all news in category
                 $news = CatalogObjects::model()->findAllByAttributes(array("category_id" => $model->id));
                 if (is_array($news) && count($news)) {
                     foreach ($news as $element) {
                         $element->delete();
                     }
                 }
                 //remove tags relations
                 $tagsRelations = TagsRelations::model()->findAllByAttributes(array("object_id" => $id, "model" => "catalog_category"));
                 if (is_array($tagsRelations) && count($tagsRelations)) {
                     foreach ($tagsRelations as $tr) {
                         $tr->delete();
                     }
                 }
                 //remove images if exists
                 if (is_file($anons_pic)) {
                     unlink($anons_pic);
                 }
                 if (is_file($content_pic)) {
                     unlink($content_pic);
                 }
             }
         }
     }
     echo json_encode(array('status' => $success ? 'success' : 'fail'));
 }
Ejemplo n.º 5
0
 public function createObject($name, $langId, $dataArray)
 {
     $model = new CatalogObjects();
     //prepare data
     $uploaddir = 'images/upload/' . date("d.m.Y", time());
     $attributes = array();
     switch ($langId) {
         case 19:
             $attributes['category_id'] = 1;
             //@todo Выбор категории для импорта
             break;
         case 20:
             $attributes['category_id'] = 5;
             break;
         case 21:
             $attributes['category_id'] = 9;
             break;
     }
     $attributes['name'] = $name;
     $attributes['h1'] = $name;
     $attributes['title'] = $name;
     $toUrl = $langId == 21 ? $name . "-" . $dataArray['artikul'] . "-fr" : $name . "-" . $dataArray['artikul'];
     $attributes['url'] = translit::convert($toUrl, "-");
     $attributes['price'] = isset($dataArray['price']) ? str_replace(",", ".", $dataArray['price']) : 0;
     $attributes['is_active'] = 0;
     $attributes['is_deleted'] = 0;
     $attributes['on_main'] = 0;
     $attributes['lang_id'] = $langId;
     $attributes['views_count'] = 0;
     $artikul = isset($dataArray['artikul']) ? $dataArray['artikul'] : '';
     if ($langId == 19) {
         $attributes['anons'] = $dataArray['name_ru'];
     } else {
         $attributes['anons'] = '';
     }
     if (is_dir('import_images/' . $artikul)) {
         if (is_file('import_images/' . $artikul . '/1.jpg')) {
             $anonsPicPath = $uploaddir . "/a_" . md5(time() . $artikul . "a1") . ".jpg";
             $contentPicPath = $uploaddir . "/c_" . md5(time() . $artikul . "c1") . ".jpg";
             if (copy('import_images/' . $artikul . '/1.jpg', $anonsPicPath)) {
                 $attributes['anons_pic'] = "/" . $anonsPicPath;
             }
             if (copy('import_images/' . $artikul . '/1.jpg', $contentPicPath)) {
                 $attributes['content_pic'] = "/" . $contentPicPath;
             }
         }
         if (is_file('import_images/' . $artikul . '/2.jpg')) {
             $extraPicPath = $uploaddir . "/e_" . md5(time() . $artikul . "2") . ".jpg";
             if (copy('import_images/' . $artikul . '/2.jpg', $extraPicPath)) {
                 $attributes['extra_img'] = "/" . $extraPicPath;
             }
         }
     }
     //push data
     $model->setAttributes($attributes);
     if ($model->save()) {
         //prepare additional data
         if (isset($dataArray['ratings']['RP'])) {
             $model->field('rp')->setValue($dataArray['ratings']['RP']);
         }
         if (isset($dataArray['ratings']['WS'])) {
             $model->field('ws')->setValue($dataArray['ratings']['WS']);
         }
         $additionalFields = CatalogFilteredFields::model()->findAllByAttributes(array("category_id" => $model->category_id));
         if (is_array($additionalFields) && count($additionalFields)) {
             foreach ($additionalFields as $f) {
                 $fieldData = isset($dataArray[$f->name]) ? $dataArray[$f->name] : null;
                 $langPrefix = 'ru';
                 switch ($langId) {
                     case 19:
                         $langPrefix = 'ru';
                         break;
                     case 20:
                         $langPrefix = 'en';
                         break;
                     case 21:
                         $langPrefix = 'fr';
                         break;
                 }
                 if (is_array($fieldData) || $fieldData && !is_array($fieldData)) {
                     switch ($f->data_type) {
                         case 'int':
                             if (is_numeric($dataArray[$f->name])) {
                                 $model->field($f->name)->setValue($dataArray[$f->name]);
                             }
                             break;
                         case 'date':
                             if ($dataArray[$f->name]) {
                                 $model->field($f->name)->setValue(strtotime($dataArray[$f->name]));
                             }
                             break;
                         case 'bool':
                             $model->field($f->name)->setValue($fieldData ? 1 : 0);
                             break;
                         case 'multiple':
                             if (is_array($fieldData) && isset($fieldData[$langPrefix])) {
                                 $values = $fieldData[$langPrefix];
                                 if (is_array($values) && count($values)) {
                                     $setArr = array();
                                     $num = 0;
                                     foreach ($values as $value) {
                                         $listItem = ListsItems::model()->findByAttributes(array("list_id" => $f->rel, "name" => $value));
                                         if (!is_object($listItem)) {
                                             $listItem = new ListsItems();
                                             $listItem->setAttributes(array("list_id" => $f->rel, "name" => $value));
                                             $listItem->save();
                                             if (isset($fieldData['en'][$num]) && $fieldData['en'][$num]) {
                                                 $listItem->field("en_name")->setValue($fieldData['en'][$num]);
                                             }
                                             if (isset($fieldData['fr'][$num]) && $fieldData['fr'][$num]) {
                                                 $listItem->field("fr_name")->setValue($fieldData['fr'][$num]);
                                             }
                                         }
                                         $setArr[] = $listItem->id;
                                         $num++;
                                     }
                                     $model->field($f->name)->setValue($setArr);
                                 }
                             } else {
                                 if (is_array($fieldData)) {
                                     $values = $fieldData;
                                     if (is_array($values) && count($values)) {
                                         $setArr = array();
                                         foreach ($values as $value) {
                                             $listItem = ListsItems::model()->findByAttributes(array("list_id" => $f->rel, "name" => $value));
                                             if (!is_object($listItem)) {
                                                 $listItem = new ListsItems();
                                                 $listItem->setAttributes(array("list_id" => $f->rel, "name" => $value));
                                                 $listItem->save();
                                             }
                                             $setArr[] = $listItem->id;
                                         }
                                         $model->field($f->name)->setValue($setArr);
                                     }
                                 }
                             }
                             break;
                         case 'list':
                             if (is_array($fieldData) && isset($fieldData[$langPrefix])) {
                                 $value = $fieldData[$langPrefix];
                                 $listItem = ListsItems::model()->findByAttributes(array("list_id" => $f->rel, "name" => $value));
                                 if (!is_object($listItem)) {
                                     $listItem = new ListsItems();
                                     $listItem->setAttributes(array("list_id" => $f->rel, "name" => $value));
                                     $listItem->save();
                                     if (isset($fieldData['en']) && $fieldData['en']) {
                                         $listItem->field("en_name")->setValue($fieldData['en']);
                                     }
                                     if (isset($fieldData['fr']) && $fieldData['fr']) {
                                         $listItem->field("fr_name")->setValue($fieldData['fr']);
                                     }
                                 }
                                 $model->field($f->name)->setValue($listItem->id);
                             } else {
                                 if ($f->name == 'brand') {
                                     $brandName = $fieldData['name'];
                                     $value = $brandName;
                                     $listItem = ListsItems::model()->findByAttributes(array("list_id" => $f->rel, "name" => $value));
                                     if (!is_object($listItem)) {
                                         $listItem = new ListsItems();
                                         $listItem->setAttributes(array("list_id" => $f->rel, "name" => $value));
                                         $listItem->save();
                                         if (isset($fieldData['en']) && $fieldData['en']) {
                                             $listItem->field("en_name")->setValue($fieldData['en']);
                                         }
                                         if (isset($fieldData['fr']) && $fieldData['fr']) {
                                             $listItem->field("fr_name")->setValue($fieldData['fr']);
                                         }
                                         if (isset($fieldData['site'])) {
                                             $listItem->field('ru_site')->setValue($fieldData['site']);
                                         }
                                     } else {
                                         if (isset($fieldData['en']) && $fieldData['en']) {
                                             $listItem->field("en_name")->setValue($fieldData['en']);
                                         }
                                         if (isset($fieldData['fr']) && $fieldData['fr']) {
                                             $listItem->field("fr_name")->setValue($fieldData['fr']);
                                         }
                                         if (isset($fieldData['site'])) {
                                             $listItem->field('ru_site')->setValue($fieldData['site']);
                                         }
                                     }
                                     $model->field($f->name)->setValue($listItem->id);
                                 } else {
                                     if (!is_array($fieldData)) {
                                         //$value = $fieldData;
                                         $listItem = ListsItems::model()->findByAttributes(array("list_id" => $f->rel, "name" => $fieldData));
                                         if (!is_object($listItem)) {
                                             $listItem = new ListsItems();
                                             $listItem->setAttributes(array("list_id" => $f->rel, "name" => $fieldData));
                                             $listItem->save();
                                         }
                                         $model->field($f->name)->setValue($listItem->id);
                                     }
                                 }
                             }
                             break;
                         default:
                             $value = is_array($fieldData) && isset($fieldData[$langPrefix]) ? $fieldData[$langPrefix] : $fieldData;
                             $model->field($f->name)->setValue(trim($value));
                             break;
                     }
                 }
             }
         }
     } else {
         print_r($model->errors);
         die;
     }
 }
Ejemplo n.º 6
0
<form action="/catalog/<?php 
echo $this->currentCategory->url;
?>
" name="catalog-filter" id="catalog-filter"></form>
<ul class="price_menu">
    <?php 
$min = CatalogObjects::convertPrice(CatalogObjects::getMinPrice($this->currentCategory->id));
$max = CatalogObjects::convertPrice(CatalogObjects::getMaxPrice($this->currentCategory->id)) + 10;
$minValue = isset($_REQUEST['min_price']) ? $_REQUEST['min_price'] : ($min < 500 ? $min : 500);
$maxValue = isset($_REQUEST['max_price']) ? $_REQUEST['max_price'] : ($max ? $max : 100000);
?>
    <li>
        <p><span><?php 
echo Localization::translate('filter_cost', $this->lang);
?>
</span></p>
        <div class="newForm">
            <form action="#" method="post">
                <div class="formCost">
                    <label for="minCost">От</label> <input type="text" id="minCost" name="min_price" value="<?php 
echo $minValue;
?>
" form="catalog-filter" />
                    <label for="maxCost">до</label> <input type="text" id="maxCost" name="max_price" value="<?php 
echo $maxValue;
?>
" form="catalog-filter" />
                </div>
                <div class="sliderCont">
                    <div id="slider" data-min="<?php 
echo $min < 500 ? $min : 500;
Ejemplo n.º 7
0
 /**
  * Возвращает максимальную цену в категории
  * @param int $categoryId
  * @return float
  */
 public static function getMaxPrice($categoryId)
 {
     $criteria = new CDbCriteria();
     $criteria->select = "MAX(price) as max_price";
     $criteria->condition = "is_active = 1 AND is_deleted = 0";
     $criteria->addCondition("category_id = " . $categoryId);
     return CatalogObjects::model()->find($criteria)->max_price;
 }
Ejemplo n.º 8
0
 public function actionSearch()
 {
     if (empty($_GET['search_string'])) {
         $search = "";
     } else {
         $search = $_GET['search_string'];
     }
     if (isset($_GET['all_news']) and $_GET['all_news'] == 1) {
         $allN = true;
     } else {
         $allN = false;
     }
     if (isset($_GET['all_catalog']) and $_GET['all_catalog'] == 1) {
         $allC = true;
     } else {
         $allC = false;
     }
     $criteria = new CDbCriteria();
     $criteria->addSearchCondition('h1', $search, true, 'OR');
     $criteria->addSearchCondition('content', $search, true, 'OR');
     $criteria->addSearchCondition('anons', $search, true, 'OR');
     $criteria->addSearchCondition('name', $search, true, 'OR');
     $criteria->addSearchCondition('title', $search, true, 'OR');
     $criteria->addSearchCondition('lang_id', $this->lang, true, 'AND');
     $criteria->addSearchCondition('is_active', "1", true, 'AND');
     $modelNews = News::model()->findAll($criteria);
     ////////////////////////////////////////////////////////////////////////////////////////////
     $criteriac = new CDbCriteria();
     $criteriac->addSearchCondition('h1', $search, true, 'OR');
     $criteriac->addSearchCondition('content', $search, true, 'OR');
     $criteriac->addSearchCondition('anons', $search, true, 'OR');
     $criteriac->addSearchCondition('name', $search, true, 'OR');
     $criteriac->addSearchCondition('title', $search, true, 'OR');
     $criteriac->addSearchCondition('lang_id', $this->lang, true, 'AND');
     $criteriac->addSearchCondition('is_active', "1", true, 'AND');
     $modelCatalog = CatalogObjects::model()->findAll($criteriac);
     switch ($this->lang) {
         case 19:
             $this->pageTitle = "Поиск по сайту";
             $this->pageDescription = "Поиск по сайту";
             $this->pageKeywords = "Поиск по сайту";
             break;
         case 20:
             $this->pageTitle = "Search";
             $this->pageDescription = "Search";
             $this->pageKeywords = "Search";
             break;
         case 21:
             $this->pageTitle = "Recherche sur le site";
             $this->pageDescription = "Recherche sur le site";
             $this->pageKeywords = "Recherche sur le site";
             break;
     }
     if ($allN or $allC) {
         if ($allN) {
             $this->render('search_all_news', array('modelNews' => $modelNews, 'search' => $search));
         }
         if ($allC) {
             $this->render('search_all_catalog', array('modelCatalog' => $modelCatalog, 'search' => $search));
         }
     } else {
         $this->render('search_all', array('modelNews' => $modelNews, 'modelCatalog' => $modelCatalog, 'search' => $search));
     }
 }
Ejemplo n.º 9
0
 public function actionEdit()
 {
     $this->layout = '//layouts/admin';
     $success = false;
     $id = $_REQUEST['id'];
     $model = Orders::model()->findByPk($id);
     $this->pageTitle = is_object($model) ? "Заказ #" . $model->id : 'Новый заказ';
     $this->breadcrumbs = array('Заказы' => array('/admin/orders'), is_object($model) ? "Заказ #" . $model->id : 'Новый заказ');
     if (isset($_POST['data']) && is_object($model)) {
         $dataArray = $_POST['data'];
         $dataArray['timestamp'] = isset($dataArray['timestamp']) ? strtotime($dataArray['timestamp']) : time();
         $orderItems = json_decode($dataArray['order_items'], true);
         unset($dataArray['order_items']);
         $model->setAttributes($dataArray);
         if ($model->save()) {
             $success = true;
             $oldItems = OrderItems::model()->findAllByAttributes(array("order_id" => $model->id));
             if (is_array($oldItems) && count($oldItems)) {
                 foreach ($oldItems as $item) {
                     $item->delete();
                 }
             }
             if (is_array($orderItems) && count($orderItems)) {
                 foreach ($orderItems as $oItem) {
                     foreach ($oItem as $oId => $amount) {
                         $object = CatalogObjects::model()->findByPk($oId);
                         if (is_object($object) && $amount) {
                             $oItemModel = new OrderItems();
                             $attributes = array();
                             $attributes['order_id'] = $model->id;
                             $attributes['name'] = $object->name;
                             $attributes['product_id'] = $object->id;
                             $attributes['price'] = $object->price;
                             $attributes['amount'] = $amount;
                             $oItemModel->setAttributes($attributes);
                             $oItemModel->save();
                         }
                     }
                 }
             }
         }
     }
     $this->render('edit', array('model' => $model, 'success' => $success, 'errors' => $model->errors));
 }