/**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $categoryModel = new ProductCategory();
     $companyModel = new ProductCompany();
     $treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
     $treeCompany = ArrayHelper::map($companyModel->findAll(['status' => 10]), 'id', 'title');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'treeParents' => $treeParents, 'treeCompany' => $treeCompany]);
     }
 }
 protected function findModel($id)
 {
     if ($model = ProductCategory::findOne($id)) {
         return $model;
     } else {
         throw new NotFoundHttpException();
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'lvl' => $this->lvl, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'main_image', $this->main_image])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'slug', $this->slug]);
     return $dataProvider;
 }
Example #4
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $allCategories = ProductCategory::find()->with('products')->all();
     $allProducts = Product::find()->all();
     $recProducts = array();
     for ($i = 0; $i < 3; $i++) {
         $currRand = rand(0, count($allProducts) - 1);
         $recProducts[] = $allProducts[$currRand];
     }
     return $this->render('index', ['allCats' => $allCategories, 'recProducts' => $recProducts]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['like', '_id', $this->_id])->andFilterWhere(['like', 'product_category_id', $this->product_category_id])->andFilterWhere(['like', 'product_category_parent_id', $this->product_category_parent_id])->andFilterWhere(['like', 'product_category_name', $this->product_category_name])->andFilterWhere(['like', 'product_category_tag', $this->product_category_tag])->andFilterWhere(['like', 'product_category_keywords', $this->product_category_keywords])->andFilterWhere(['like', 'product_category_icon', $this->product_category_icon])->andFilterWhere(['like', 'product_category_icon_mobile', $this->product_category_icon_mobile])->andFilterWhere(['like', 'product_category_create_date', $this->product_category_create_date])->andFilterWhere(['like', 'product_category_create_user_id', $this->product_category_create_user_id])->andFilterWhere(['like', 'product_category_last_update_date', $this->product_category_last_update_date])->andFilterWhere(['like', 'product_category_last_update_user_id', $this->product_category_last_update_user_id])->andFilterWhere(['like', 'product_category_status', $this->product_category_status])->andFilterWhere(['like', 'merchant_brand_fk', $this->merchant_brand_fk]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'lft' => $this->lft, 'rgt' => $this->rgt, 'depth' => $this->depth, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'meta_description', $this->meta_description]);
     return $dataProvider;
 }
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(ProductCategory::className(), ['id' => 'category_id']);
 }
 public function down()
 {
     $this->dropColumn(ProductCategory::tableName(), 'level');
 }
 public function actionGetCategoryTree()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $getParams = Yii::$app->request->get();
     $searchCri = array('product_category_parent_id' => '');
     $allCategories = ProductCategory::findAll($searchCri);
     $jsonData = array();
     foreach ($allCategories as $catLvl1) {
         $currObj = array();
         $checked = false;
         if (!empty($getParams)) {
             if ($getParams['evalType'] == 'catParentId' && $getParams['evalVal'] == $catLvl1->product_category_id || $getParams['evalType'] == 'catId' && $getParams['evalVal'] == $catLvl1->product_category_id) {
                 $checked = true;
             }
         }
         $currObj['item'] = array('id' => $catLvl1->product_category_id, 'label' => $catLvl1->product_category_name, 'checked' => $checked);
         if (!empty($catLvl1->subcategories)) {
             $subCats = $catLvl1->subcategories;
             foreach ($subCats as $catLvl2) {
                 $checked2 = false;
                 if (!empty($getParams)) {
                     if ($getParams['evalType'] == 'catParentId' && $getParams['evalVal'] == $catLvl2->product_category_id || $getParams['evalType'] == 'catId' && $getParams['evalVal'] == $catLvl2->product_category_id) {
                         $checked2 = true;
                     }
                 }
                 $currObj['children'][]['item'] = array('id' => $catLvl2->product_category_id, 'label' => $catLvl2->product_category_name, 'checked' => $checked2);
             }
         }
         $jsonData[] = $currObj;
     }
     return $jsonData;
 }
 /**
  * Finds the ProductCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ProductCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ProductCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model_category = new Category();
     $model_product_category = new ProductCategory();
     $model_manufacturer = new Manufacturer();
     $model_product_manufacturer = new ProductManufacturer();
     $upload_model = new UploadForm();
     $resource = new Resources();
     $resource_product = new ResourcesProduct();
     if (isset($_POST['Product']) && !empty($_POST['Product'])) {
         $model->attributes = $_POST['Product'];
         $model->beforeSave(FALSE);
         if ($model->validate() && $model->save()) {
             if (empty($_POST['ProductCategory']['category_id'])) {
                 $model_product_category->addError('category_id', 'No category selected.');
             } else {
                 (new Query())->createCommand()->delete(ProductCategory::tableName(), ['product_id' => $model->id])->execute();
                 foreach ($_POST['ProductCategory']['category_id'] as $category) {
                     $model_product_category = new ProductCategory();
                     $model_product_category->product_id = $model->id;
                     $model_product_category->category_id = $category;
                     $model_product_category->save();
                 }
             }
             if (isset($_POST['ProductManufacturer']) && !empty($_POST['ProductManufacturer']['manufacturer_id'])) {
                 (new Query())->createCommand()->delete(ProductManufacturer::tableName(), ['product_id' => $model->id])->execute();
                 $model_product_manufacturer->attributes = $_POST['ProductManufacturer'];
                 $model_product_manufacturer->product_id = $model->id;
                 $model_product_manufacturer->save();
             }
             if (isset($_FILES['UploadForm']) && !empty($_FILES['UploadForm'])) {
                 $upload_model->imageFiles = UploadedFile::getInstances($upload_model, 'imageFiles');
                 $uploaded_files = $upload_model->upload('product_image');
                 if (!empty($uploaded_files)) {
                     foreach ($uploaded_files as $uploaded_file) {
                         $resource = new Resources();
                         $resource->attributes = $uploaded_file;
                         $resource->beforeSave(FALSE);
                         if ($resource->validate() && $resource->save()) {
                             $resource_product = new ResourcesProduct();
                             $resource_product->product_id = $model->id;
                             $resource_product->resources_id = $resource->id;
                             $resource_product->save();
                         }
                     }
                 }
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('update', ['model' => $model, 'model_manufacturer' => $model_manufacturer, 'model_product_manufacturer' => $model_product_manufacturer, 'model_category' => $model_category, 'model_product_category' => $model_product_category, 'upload_model' => $upload_model]);
     }
 }
Example #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductCategories()
 {
     return $this->hasMany(ProductCategory::className(), ['category_id' => 'id']);
 }
Example #13
0
use yii\bootstrap\ActiveForm;
use common\models\ProductCategory;
?>
<div class="row">
    <?php 
$form = ActiveForm::begin(['method' => 'post', 'layout' => 'horizontal']);
?>
            <?php 
echo $form->field($model, 'name')->textInput();
?>
            <?php 
echo $form->field($model, 'icon_class')->textInput();
?>
s
            <?php 
echo $form->field($model, 'parent_id')->dropDownList(ProductCategory::getTreeIdNameList(), ['class' => 'form-control chosen-select']);
?>
            <?php 
echo $form->field($model, 'display_order')->textInput();
?>
        
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-6">
                <button class="btn btn-primary pull-right btn-block">提交</button>
            </div>
        </div>
    <?php 
ActiveForm::end();
?>
</div>
Example #14
0
                    <div class="cat">
                        <h3><a href=""><?php 
    echo $productCategory->name;
    ?>
</a> <b></b></h3>
                        <div class="cat_detail">
                            <?php 
    foreach (ProductCategory::getListByParentId($productCategory->id) as $secondProductCategory) {
        ?>
                                <dl class="dl_1st">
                                    <dt><a href=""><?php 
        echo $secondProductCategory->name;
        ?>
</a></dt>
                                    <?php 
        $lastProductCategories = ProductCategory::getListByParentId($secondProductCategory->id);
        ?>
                                    <?php 
        if ($lastProductCategories) {
            ?>
                                        <dd>
                                            <?php 
            foreach ($lastProductCategories as $lastProductCategory) {
                ?>
                                                <a href=""><?php 
                echo $lastProductCategory->name;
                ?>
</a>
                                            <?php 
            }
            ?>
Example #15
0
 public function getSubcategories()
 {
     return $this->hasMany(ProductCategory::className(), ['product_category_parent_id' => 'product_category_id']);
 }
Example #16
0
        <header class="panel-heading bg-light">
            <ul class="nav nav-tabs pull-right">
            <li class="active"><a href="#basic" data-toggle="tab" aria-expanded="true"><i class="fa fa-comments text-muted"></i> 基本信息</a></li>
            <li class=""><a href="#description" data-toggle="tab" aria-expanded="false"><i class="fa fa-user text-muted"></i> 描述</a></li>
            <li class=""><a href="#picture" data-toggle="tab" aria-expanded="false"><i class="fa fa-cog text-muted"></i> 图片</a></li>
            </ul>
            <span class="hidden-sm"><?php 
echo $this->title;
?>
</span>
        </header>
        <div class="panel-body">
            <div class="tab-content">              
            <div class="tab-pane active" id="basic">
                <?php 
echo $form->field($model, 'category_id')->dropDownList(ProductCategory::getTreeIdNameList(), ['class' => ['class' => 'chosen-select form-control']]);
?>
            
                <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
                
                <?php 
echo $form->field($model, 'code')->textInput(['maxlength' => true]);
?>
                
                <?php 
echo $form->field($model, 'inventory')->input('number');
?>
            
                <?php 
Example #17
0
 /**
  * function ->delete ()
  */
 public function delete()
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = $this;
     if ($log = new UserLog()) {
         $log->username = $username;
         $log->action = 'Delete';
         $log->object_class = 'ProductCategory';
         $log->object_pk = $model->id;
         $log->created_at = $now;
         $log->is_success = 0;
         $log->save();
     }
     if (parent::delete()) {
         if ($log) {
             $log->is_success = 1;
             $log->save();
         }
         FileUtils::removeFolder(Yii::$app->params['images_folder'] . $model->image_path);
         return true;
     }
     return false;
 }
Example #18
0
 public function getRelateCategories()
 {
     if ($this->_relateCategories === null) {
         $this->_relateCategories = [];
         if ($this->category && $this->category->parent) {
             $this->_relateCategories = ProductCategory::findAll(['parent_id' => $this->category->parent->id]);
         }
     }
     return $this->_relateCategories;
 }
 public function actionGetCategoryTree()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $productCategoryKeys = $this->getProductCategoryKeys(Yii::$app->request->get('productId'));
     $productCategories = ProductCategory::findAll(['product_category_parent_id' => '']);
     return $this->buildCategoryTree($productCategoryKeys, $productCategories);
 }
 public function scenarios()
 {
     return parent::scenarios();
 }
 public function down()
 {
     $this->dropColumn(ProductCategory::tableName(), 'icon_class');
 }