public function actionView($id, $alias)
 {
     $storeCategory = StoreCategory::find()->where(['id' => $id])->one();
     if ($storeCategory !== null) {
         $storeCategoryDescendant = StoreCategory::getDescendant($id);
         if (!empty($storeCategoryDescendant)) {
             $dataProvider = new ActiveDataProvider(['query' => StoreCategory::find()->category($storeCategoryDescendant)]);
             $this->storeReturnUrl();
             return $this->render('view-category', ['dataProvider' => $dataProvider]);
         }
     } else {
         throw new HttpException(404);
     }
     $storeProduct = StoreProduct::find()->product($id);
     if ($storeProduct !== null) {
         $dataProvider = new ActiveDataProvider(['query' => $storeProduct]);
         $this->storeReturnUrl();
         return $this->render('view-product', ['dataProvider' => $dataProvider]);
     } else {
         throw new HttpException(404);
     }
 }
Ejemplo n.º 2
0
 /**
  * Получение потомков категории товара
  * @param $idStoreCategory
  * @return array|bool
  */
 public static function getDescendant($idStoreCategory)
 {
     $storeCategories = StoreCategory::find()->orderBy('lft')->all();
     $array = [];
     $init = false;
     $level = null;
     $a = 0;
     foreach ($storeCategories as $storeCategory) {
         if ($storeCategory['id'] == $idStoreCategory) {
             $init = true;
             $level = $storeCategory['lvl'];
         } elseif ($init == true && $level >= $storeCategory['lvl']) {
             $init = false;
         } elseif ($init == true && $level - $storeCategory['lvl'] == -1) {
             array_push($array, $storeCategory['id']);
             $a++;
         }
     }
     if (!empty($array)) {
         return $array;
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
<?php

use alexsers\store\Module;
use alexsers\themes\backend\widgets\Box;
use alexsers\themes\backend\widgets\GridView;
use kartik\tree\TreeView;
use alexsers\store\models\StoreCategory;
use kartik\tree\models\Tree;
$this->title = Module::t('store', 'Категории товара');
$this->params['subtitle'] = Module::t('store', 'Список категорий');
$this->params['breadcrumbs'] = [$this->title];
echo TreeView::widget(['query' => StoreCategory::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Категории'], 'fontAwesome' => false, 'isAdmin' => true, 'displayValue' => 1, 'softDelete' => true, 'cacheSettings' => ['enableCache' => true]]);
/*echo'<pre>';
print_r(Tree::find()->addOrderBy('root, lft'));
echo'</pre>';*/
Ejemplo n.º 4
0
/* @var $model alexsers\store\models\StoreProduct */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="store-product-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->errorSummary($model);
?>
    <label class="control-label">Категория товара</label>
    <?php 
echo \kartik\tree\TreeViewInput::widget(['query' => StoreCategory::find()->addOrderBy('root, lft'), 'model' => $model, 'attribute' => 'category_id', 'fontAwesome' => false, 'asDropdown' => true, 'multiple' => false]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'description')->textarea(['rows' => 6]);
?>

    <?php 
echo $form->field($model, 'price')->textInput();
?>

    <?php 
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(StoreCategory::className(), ['id' => 'category_id']);
 }