Ejemplo n.º 1
0
 function get_tovar_url($id)
 {
     $tovar = Products::findOne(['id' => $id]);
     $cat = ModArendaTree::findOne(['id' => $tovar->cat_id]);
     $url = [];
     $url[] = $cat->url;
     while ($cat->parent_id != 0) {
         $cat = ModArendaTree::findOne(['id' => $cat->parent_id]);
         $url[] = strtolower($cat->url);
     }
     $total_url = '/catalog';
     for ($i = count($url) - 1; $i >= 0; $i--) {
         $total_url .= '/' . $url[$i];
     }
     $total_url .= '/' . strtolower($this->translit($tovar->name)) . '-' . $tovar->id;
     return $total_url;
 }
Ejemplo n.º 2
0
?>
    <div class="form-group">
        <?php 
echo Html::submitButton('Сохранить', ['class' => 'btn btn-primary']);
?>

    </div>

    <div class="form-group">
        <?php 
echo Html::a('Вернуться к списку', [$cat_parent != 0 ? '/tree/admin?parent_id=' . $cat_parent : '/tree/admin/'], ['class' => 'btn btn-default']);
?>
    </div>
    <div class="form-group">
        <?php 
$res = \app\modules\Tree\models\ModArendaTree::findOne(['parent_id' => $model->id]);
if ($res) {
    echo '
            <div class="alert alert-danger" role="alert">Удалить категорию нельзя (является родителем)</div>';
} else {
    echo '<a class="btn btn-danger" href="/tree/admin/deletecat?id=' . $model->id . '" data-confirm="Вы действительно хотите удалить категорию?" data-method="post">Удалить</a>';
}
?>
    </div>

    <?php 
echo $form->field($model_upload, 'imageFile')->fileInput()->label('Иконка');
?>
    <?php 
if (!empty($icon)) {
    echo '<img  src="/images/cats_images/' . $icon->cat_id . '/' . $icon->url . '">';
Ejemplo n.º 3
0
                    <p class="ad_add_title"> Выберите категорию</p>
                    <div class="row">
                        ';
foreach ($categories as $key => $value) {
    echo '
                        <div class="col-md-4 main_cat_item" data-id="' . $value['id'] . '">
                         <div class="row item_row">
                           <div class="col-md-2 item_img">
                                <img  class="pull-right" src="/images/cats_images/' . $value['id'] . '/' . $value['image_url'] . '">
                           </div>
                           <div class="col-md-10 item_text">
                                <header>
                                    ' . $value['name'] . '
                                </header>
                                <footer>';
    $childs = \app\modules\Tree\models\ModArendaTree::find()->where(['parent_id' => $value['id']])->asArray()->all();
    if (!empty($childs)) {
        $text = '<p>';
        foreach ($childs as $key1 => $value1) {
            $text .= $value1['name'] . ', ';
        }
        $text = substr($text, 0, -2);
        $text .= '</p>';
    } else {
        $text = 'Нет подкатегорий';
    }
    echo $text;
    echo '</footer>
                           </div>
                        </div>
                        </div>
Ejemplo n.º 4
0
 public function actionGetcharacteristics($id)
 {
     $model = new Characteristics();
     $result = $model->getCharacteristics($id);
     while (empty($result)) {
         $parent = ModArendaTree::findOne(['id' => $id]);
         $parent = ModArendaTree::findOne(['id' => $parent->parent_id]);
         if (empty($parent)) {
             return false;
         }
         $result = $model->getCharacteristics($parent->id);
         $id = $parent->id;
     }
     return $result;
 }
Ejemplo n.º 5
0
 public function actionEdit($id)
 {
     $model = Products::findOne(['id' => $id]);
     $all_cats = ModArendaTree::find()->asArray()->all();
     if ($model->load(Yii::$app->request->post())) {
         $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
         if ($model->validate()) {
             if (!empty($model->imageFile)) {
                 $model->upload();
                 $model->image = md5($model->imageFile->baseName . date("Y-m-d-H-i-s")) . '.' . $model->imageFile->extension;
             }
             if ($model->save()) {
                 $last_id = $_GET['id'];
                 foreach (Yii::$app->request->post('character') as $key => $value) {
                     $model1 = CharacteristicsProducts::findOne(['product_id' => $last_id, 'character_id' => $key]);
                     if (!$model1) {
                         $model1 = new CharacteristicsProducts();
                         $model1->product_id = $last_id;
                     }
                     $model1->character_id = $key;
                     $model1->value = empty($value) ? 'none' : $value;
                     $model1->save();
                 }
             }
             // form inputs are valid, do something here
         }
     }
     $result = CharacteristicsForCats::find()->select(['characteristics_for_cats.*', 'characteristics.name AS characteristic_name'])->where(['cat_id' => $model->cat_id])->leftJoin('characteristics', 'characteristics_for_cats.character_id=characteristics.id')->leftJoin('characteristics_products', 'characteristics_for_cats.character_id=characteristics_products.character_id')->asArray()->all();
     if (empty($result)) {
         $cat = ModArendaTree::findOne(['id' => $model->cat_id]);
         while ($cat->parent_id != 0) {
             $result = CharacteristicsForCats::find()->select(['characteristics_for_cats.*', 'characteristics.name AS characteristic_name', 'characteristics_products.value AS VALUE'])->where(['cat_id' => $cat->parent_id])->leftJoin('characteristics', 'characteristics_for_cats.character_id=characteristics.id')->leftJoin('characteristics_products', 'characteristics_for_cats.character_id=characteristics_products.character_id AND characteristics_products.product_id="' . $_GET['id'] . '"')->asArray()->all();
             if (!empty($result)) {
                 break;
             }
             $cat = ModArendaTree::findOne(['id' => $cat->parent_id]);
         }
     } else {
     }
     $html = '';
     if (!empty($result)) {
         foreach ($result as $key => $value) {
             $VAL = !empty($value['VALUE']) ? $value['VALUE'] : '';
             $html .= '
             <div class="form-group">
                 <label><p>' . $value['characteristic_name'] . '</p>
                 <input value="' . $VAL . '" type="text" class="form-control" name="character[' . $value['character_id'] . ']" >
                 </label>
             </div>
             ';
         }
     }
     return $this->render('edit', ['model' => $model, 'all_cats' => $all_cats, 'html' => $html]);
 }
Ejemplo n.º 6
0
<?php

use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\modules\Tree\assets\TreeAsset;
use app\modules\Tree\models\ModArendaTree;
TreeAsset::register($this);
$b_id = $parent_id;
$result = ModArendaTree::findOne(['id' => $b_id]);
if ($result) {
    $this_cat = $result;
    $this->params['breadcrumbs'][] = ['label' => 'Весь список категорий', 'url' => ['/tree/admin']];
    $nn_mas = [];
    while ($result->parent_id != 0) {
        $result = ModArendaTree::findOne(['id' => $result->parent_id]);
        $nn_mas[] = ['id' => $result->id, 'name' => $result->name];
    }
    for ($i = count($nn_mas) - 1; $i >= 0; $i--) {
        $this->params['breadcrumbs'][] = ['label' => $nn_mas[$i]['name'], 'url' => ['/tree/admin?parent_id=' . $nn_mas[$i]['id']]];
    }
    $this->params['breadcrumbs'][] = 'Структура категории "' . $this_cat->name . '"';
    $h2 = '<h2>Структура категории "' . $this_cat->name . '"</h2>';
} else {
    $this->params['breadcrumbs'][] = 'Весь список категорий';
    $h2 = '';
}
$session = Yii::$app->session;
echo $session->getFlash('add_cat');
echo $session->getFlash('delete_cat');
?>
Ejemplo n.º 7
0
?>
<div class="products-create">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
    <input type="hidden" id="parent_id" value="<?php 
echo $model->cat_id;
?>
">

    <?php 
echo $form->field($model, 'name')->textInput()->label('Название');
?>
    <?php 
echo $form->field($model, 'cat_id')->dropDownList(ArrayHelper::map(\app\modules\Tree\models\ModArendaTree::find()->all(), 'id', 'name'))->label('Категория');
?>

    <?php 
echo $form->field($model, 'description')->widget(CKEditor::className(), ['options' => ['rows' => 6]]);
?>
    <?php 
echo $form->field($model, 'price')->textInput()->label('Цена (0 - по запросу)');
?>
    <?php 
echo $form->field($model, 'imageFile')->fileInput();
?>
    <?php 
echo empty($model->image) ? '<p>Фотография не загружена</p>' : '<img width=200" src="/img/products/' . $model->image . '"';
?>
    <div class="clearfix"></div>
Ejemplo n.º 8
0
 public function actionGetcharacteristics($id)
 {
     $result = CharacteristicsForCats::find()->select(['characteristics_for_cats.*', 'characteristics.name AS characteristic_name'])->where(['cat_id' => $id])->leftJoin('characteristics', 'characteristics_for_cats.character_id=characteristics.id')->asArray()->all();
     if (empty($result)) {
         $cat = ModArendaTree::findOne(['id' => $id]);
         while ($cat->parent_id != 0) {
             $result = CharacteristicsForCats::find()->select(['characteristics_for_cats.*', 'characteristics.name AS characteristic_name'])->where(['cat_id' => $cat->parent_id])->leftJoin('characteristics', 'characteristics_for_cats.character_id=characteristics.id')->asArray()->all();
             if (!empty($result)) {
                 break;
             }
             $cat = ModArendaTree::findOne(['id' => $cat->parent_id]);
         }
     } else {
     }
     if (!empty($result)) {
         $html = '';
         foreach ($result as $key => $value) {
             $html .= '
             <div class="form-group">
                 <label><p>' . $value['characteristic_name'] . '</p>
                 <input type="text" class="form-control" name="character[' . $value['character_id'] . ']" >
                 </label>
             </div>
             ';
         }
         return $html;
     } else {
         return 'empty';
     }
 }
Ejemplo n.º 9
0
 public function actionViewarendatype($id)
 {
     @session_start();
     $_SESSION['menu'] = 4;
     if (Yii::$app->request->post()) {
         ArendaTypesForCats::deleteAll(['arenda_type_id' => $id]);
         if (Yii::$app->request->post('delete_arenda_type')) {
             $delete_arenda_type = ArendaTypes::findOne(['id' => key(Yii::$app->request->post('delete_arenda_type'))]);
             if ($delete_arenda_type->delete()) {
                 return $this->redirect('arendatypes');
             }
         } else {
             if (Yii::$app->request->post('cats')) {
                 $arenda_types = Yii::$app->request->post('cats');
                 foreach ($arenda_types as $key => $value) {
                     $model_d_t = new ArendaTypesForCats();
                     $model_d_t->arenda_type_id = $id;
                     $model_d_t->cat_id = $key;
                     $model_d_t->save();
                 }
             }
         }
     }
     $model = new ArendaTypes();
     $arenda_type = $model->findOne(['id' => $id]);
     //Получаем активные категории
     $active_cats = ArendaTypesForCats::find()->where(['arenda_type_id' => $id])->asArray()->all();
     //получаем категории и подкатегории
     $cats_model = new ModArendaTree();
     $cats = $cats_model->view_cat_for_characters($cats_model->get_cat(), 0, $active_cats);
     return $this->render('view_arenda_type', ['model' => $arenda_type, 'tree' => $cats]);
 }