Exemple #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find()->with('mySelf');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['class' => 'yii\\data\\Pagination', 'defaultPageSize' => 16], 'sort' => ['class' => 'yii\\data\\Sort', 'defaultOrder' => ['parent_id' => SORT_ASC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'top' => $this->top, 'column' => $this->column, 'sort' => $this->sort, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'keyword', $this->keyword])->andFilterWhere(['like', 'brief', $this->brief])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Exemple #2
0
use common\helpers\General;
use common\models\catalog\Category;
use common\models\catalog\Brand;
use backend\assets\DatePickerAsset;
/* @var $this yii\web\View */
/* @var $model common\models\catalog\Product */
/* @var $form yii\widgets\ActiveForm */
//加载一插件
DatePickerAsset::register($this);
//使用插件
$this->registerJs("\n\t\$('#product-promote_start_date, #product-promote_end_date').datepicker({\n        language: '" . Yii::$app->language . "',//使用当前语言\n\t    format: 'yyyy/mm/dd'\n\t});\n");
$model->promote_start_date = Yii::$app->getFormatter()->asDate($model->promote_start_date, 'yyyy/MM/dd');
//与js配合
$model->promote_end_date = Yii::$app->getFormatter()->asDate($model->promote_end_date, 'yyyy/MM/dd');
//与js配合
$cateList = ArrayHelper::map(General::recursiveObj(Category::find()->orderBy(['sort' => SORT_ASC])->all()), 'id', 'name');
$brandList = ArrayHelper::map(Brand::find()->orderBy(['sort' => SORT_ASC])->all(), 'id', 'name');
?>

<!-- 导航 -->
<div id="product_nav">
    <ul>
        <li><a href="#home"><?php 
echo Yii::t('catalog', 'Base');
?>
</a></li>
        <li><a href="#declare"><?php 
echo Yii::t('catalog', 'Declare');
?>
</a></li>
        <li><a href="#price"><?php 
Exemple #3
0
                <div class="tab-pane active category-index">
                
                <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>
                        
                    <!-- 
                        <p>
                            <?php 
echo Html::a(Yii::t('catalog', 'Create Category'), ['create'], ['class' => 'btn btn-success']);
?>
                        </p>
                     -->
            
                <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'options' => ['class' => 'grid-view box-body table-responsive no-padding'], 'tableOptions' => ['class' => 'table table-hover table-striped table-bordered'], 'headerRowOptions' => [], 'footerRowOptions' => [], 'showHeader' => true, 'showFooter' => false, 'layout' => "{summary}\n{errors}\n{items}\n{pager}", 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', ['attribute' => 'parent_id', 'filter' => ArrayHelper::merge([0 => Yii::t('catalog', 'Top Category')], ArrayHelper::map(General::recursiveObj(Category::find()->orderBy(['sort' => SORT_ASC])->all()), 'id', 'name')), 'value' => function ($model, $key, $index, $_this) {
    if (!$model->parent_id) {
        return Yii::t('catalog', 'Top Category');
    } else {
        return $model->getRelatedRecords()['mySelf']->name;
    }
}], ['attribute' => 'top', 'filter' => [Category::CATEGORY_IS_TOP => Yii::t('catalog', 'Is Top'), Category::CATEGORY_NOT_TOP => Yii::t('catalog', 'Not Top')], 'value' => function ($model, $key, $index, $_this) {
    return $model->top ? Yii::t('catalog', 'Is Top') : Yii::t('catalog', 'Not Top');
}], ['attribute' => 'status', 'filter' => [Category::CATEGORY_STATUS_ON => Yii::t('catalog', 'Status On'), Category::CATEGORY_STATUS_OFF => Yii::t('catalog', 'Status Off')], 'value' => function ($model, $key, $index, $_this) {
    return $model->status ? Yii::t('catalog', 'Status On') : Yii::t('catalog', 'Status Off');
}], ['attribute' => 'sort', 'filter' => false], ['attribute' => 'updated_at', 'format' => 'datetime', 'filter' => false], ['class' => 'yii\\grid\\ActionColumn', 'header' => Yii::t('common', 'Opration')]]]);
?>
                                
                </div>
                
            </div>
Exemple #4
0
            <div class="tab-content clearfix">
                <div class="tab-pane active product-index">
                    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>
                    <!-- 
                        <p>
                            <?php 
echo Html::a(Yii::t('catalog', 'Create Product'), ['create'], ['class' => 'btn btn-success']);
?>
                        </p>
                     -->
                    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'options' => ['class' => 'grid-view box-body table-responsive no-padding'], 'tableOptions' => ['class' => 'table table-hover table-striped table-bordered'], 'headerRowOptions' => [], 'footerRowOptions' => [], 'showHeader' => true, 'showFooter' => false, 'layout' => "{summary}\n{errors}\n{items}\n{pager}", 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', 'shop_price:currency', 'sku', ['attribute' => 'category_id', 'value' => function ($model, $key, $index, $_this) {
    return $model->getRelatedRecords()['category']->name;
}, 'filter' => ArrayHelper::map(General::recursiveObj(Category::find()->orderBy(['sort' => SORT_ASC])->all()), 'id', 'name')], ['header' => Yii::t('catalog', 'Shortcut'), 'format' => 'raw', 'value' => function ($model, $key, $index, $_this) {
    $str = '';
    //$str .= '<a href="javascript:;" title="'.Yii::t('catalog', 'Is Del').'" data-id="'.$model->id.'" data-status="'.$model->is_del.'"><span class="label label-'.($model->is_del?'danger':'success').'">&nbsp;</span></a> ';
    $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is Promote') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_promote . '"><span class="label label-' . ($model->is_promote ? 'success' : 'danger') . '">&nbsp;</span></a> ';
    $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is Hot') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_hot . '"><span class="label label-' . ($model->is_hot ? 'success' : 'danger') . '">&nbsp;</span></a> ';
    $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is New') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_new . '"><span class="label label-' . ($model->is_new ? 'success' : 'danger') . '">&nbsp;</span></a> ';
    $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is Best') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_best . '"><span class="label label-' . ($model->is_best ? 'success' : 'danger') . '">&nbsp;</span></a> ';
    $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is Free Shipping') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_free_shipping . '"><span class="label label-' . ($model->is_free_shipping ? 'success' : 'danger') . '">&nbsp;</span></a> ';
    return $str;
}], 'date_available:datetime', 'updated_at:datetime', ['attribute' => 'status', 'format' => 'html', 'value' => function ($model, $key, $index, $_this) {
    return '<span class="label label-' . ($model->status ? 'success' : 'danger') . '">&nbsp;</span>';
}, 'filter' => [Product::PRODUCT_STATUS_ON => Yii::t('catalog', 'Status On'), Product::PRODUCT_STATUS_OFF => Yii::t('catalog', 'Status Off')]], ['class' => 'yii\\grid\\ActionColumn', 'header' => Yii::t('common', 'Opration')]]]);
?>
                                
                </div>
                
Exemple #5
0
 /**
  * 自我表关联
  */
 public function getMySelf()
 {
     return $this->hasOne(Category::className(), ['id' => 'parent_id']);
 }
Exemple #6
0
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #7
0
use yii\helpers\Html;
//use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
use common\components\helpers\General;
use common\models\catalog\Category;
use backend\components\uploadify\UploadifyWidget;
use backend\components\ueditor\UeditorWidget;
/* @var $this yii\web\View */
/* @var $model common\models\catalog\Category */
/* @var $form yii\widgets\ActiveForm */
if ($model->isNewRecord) {
    $model->status = true;
}
$parentList = ArrayHelper::merge([0 => Yii::t('catalog', 'Top Category')], ArrayHelper::map(General::recursiveObj(Category::find()->orderBy(['sort' => SORT_ASC])->all()), 'id', 'name'));
?>

<div class="row category-form">
    <div class="col-md-1"></div>
    <div class="col-md-12 col-lg-6">
        <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
        <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'parent_id')->dropDownList($parentList);
?>
        
Exemple #8
0
 /**
  * 与产品分类联表
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }