예제 #1
0
 public function addCat($name, $sort, $desc)
 {
     //用户名已存在
     if (ProductCategory::findOne($name)) {
         return false;
     }
     $model = new ProductCategory();
     $model->categoryName = $name;
     $model->sort = $sort;
     $model->desc = $desc;
     $model->addTime = date('Y-m-d H:i:s', time());
     $model->addUser = \Yii::$app->session->get(Variable::$session_userId_str);
     if ($model->save() > 0) {
         return true;
     }
     return false;
 }
예제 #2
0
 /**
  * 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 any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'cat_title', $this->cat_title])->andFilterWhere(['like', 'cat_desc', $this->cat_desc]);
     return $dataProvider;
 }
예제 #3
0
 /**
  * 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, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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, 'position' => $this->position, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status, 'is_active' => $this->is_active, 'is_hot' => $this->is_hot]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'old_slugs', $this->old_slugs])->andFilterWhere(['like', 'image_path', $this->image_path])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'banner', $this->banner])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'updated_by', $this->updated_by])->andFilterWhere(['like', 'link', $this->link]);
     return $dataProvider;
 }
예제 #4
0
 public function init()
 {
     parent::init();
     $this->languages_codeToName = ArrayHelper::map(Language::find()->all(), 'code', 'name');
     $this->languages_idToName = ArrayHelper::map(Language::find()->all(), 'id', 'name');
     $this->currencies_idToName = ArrayHelper::map(Currency::find()->all(), 'id', 'name');
     $this->parent_productCategories_idToSlug = ArrayHelper::map(ProductCategory::find()->where(['parent_id' => null])->all(), 'id', 'slug');
     foreach ($this->parent_productCategories_idToSlug as $id => $slug) {
         $this->productCategories_idToSlug[$slug] = ArrayHelper::map(ProductCategory::find()->where(['parent_id' => $id])->all(), 'id', 'slug');
     }
     is_array($this->productCategories_idToSlug) or $this->productCategories_idToSlug = array();
     $this->productCollections_idToSlug = ArrayHelper::map(ProductCollection::find()->all(), 'id', 'slug');
     I18n::$currency_params = ['exchange_rate' => 1, 'prefix' => '', 'suffix' => 'đ', 'thousand_separator' => '.', 'decimal_point' => ',', 'number_digits_after_decimal_point' => 0];
 }
예제 #5
0
 public static function get_subcategory_list($parent)
 {
     $html = '';
     $child_pages = ProductCategory::find()->joinWith('cat_rel')->where(['category_self_rel.parent_cat_id' => $parent])->all();
     if (!empty($child_pages)) {
         $html .= '<ul>';
         foreach ($child_pages as $key => $value) {
             $html .= '<li><a href="#" data_cat_id="' . $value->id . '">' . $value->cat_title . '</a></li>';
             self::get_subcategory_list($value->id, $html);
         }
         $html .= '</ul>';
     }
     return $html;
 }
예제 #6
0
                <?php 
$form = ActiveForm::begin(['id' => 'product_update-form']);
?>

                  <div class="col-md-4">

                        <input type="hidden" name="id" value="<?php 
echo $model->id;
?>
" id="product_id">

                          <?php 
echo Html::activeLabel($ProductCategoryRel, 'category_id');
?>
                          <?php 
echo Select2::widget(['model' => $ProductCategoryRel, 'attribute' => 'category_id', 'data' => ProductCategory::getHierarchy_cat(), 'options' => ['placeholder' => 'Select Category ...', 'multiple' => true], 'pluginOptions' => ['allowClear' => true]]);
?>

                          <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 255]);
?>
                          <?php 
echo $form->field($model, 'slug')->textInput(['maxlength' => 255]);
?>
                          <?php 
echo $form->field($model, 'short_desc')->textArea(['col' => 2]);
?>
                      
                          <?php 
echo $form->field($model, 'sort_order')->textInput(['maxlength' => 255]);
?>
예제 #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductCategory()
 {
     return $this->hasOne(ProductCategory::className(), ['id' => 'product_category_id']);
 }
예제 #8
0
 /**
  * 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.');
     }
 }
예제 #9
0
파일: Page.php 프로젝트: hsleonis/basetech
 public function getCategory_list()
 {
     return $this->hasOne(ProductCategory::className(), ['id' => 'category_id'])->viaTable('page_category_rel', ['page_id' => 'id']);
 }
예제 #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductCategories()
 {
     return $this->hasMany(ProductCategory::className(), ['parent_id' => 'id']);
 }
 public function actionProductcat()
 {
     $user = new AdminUser();
     if (!$user->checkUserIsLogin()) {
         $this->redirect(Variable::$home_url);
         return;
     }
     $query = ProductCategory::find();
     $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $query->count()]);
     $countries = $query->orderBy('addTime DESC')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render(Variable::$productCat_view, ['countries' => $countries, 'pagination' => $pagination]);
 }
예제 #12
0
 /**
  * Displays a single Settings model.
  * @param integer $id
  * @return mixed
  */
 public function actionTabular_input()
 {
     $model = new ProductCategory();
     $query = ProductCategory::find()->indexBy('id');
     // where `id` is your primary key
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 5]]);
     $models = $dataProvider->getModels();
     if (Yii::$app->request->isAjax) {
         if (isset($_POST['ProductCategory']) && isset($_POST['ProductCategory']['cat_create'])) {
             $model = new ProductCategory();
             $model->attributes = $_POST['ProductCategory'];
             if ($model->save()) {
                 $response['files'] = ['ok'];
                 $response['result'] = 'success';
                 $model_uu = new ProductCategory();
                 $query = ProductCategory::find()->indexBy('id');
                 // where `id` is your primary key
                 $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 5]]);
                 $models = $dataProvider->getModels();
                 $response['post_list'] = $this->renderAjax('ajax_cont', ['dataProvider' => $dataProvider, 'model' => $model_uu]);
                 return json_encode($response);
             } else {
                 $response['result'] = 'error';
                 $response['files'] = Html::errorSummary($model);
                 return json_encode($response);
             }
         } else {
             if (ProductCategory::loadMultiple($models, Yii::$app->request->post()) && ProductCategory::validateMultiple($models)) {
                 $count = 0;
                 foreach ($models as $index => $model) {
                     // populate and save records for each model
                     if ($model->save()) {
                         $count++;
                     }
                 }
                 Yii::$app->session->setFlash('success', "Processed {$count} records successfully.");
                 $response['files'] = "Processed {$count} records successfully.";
                 $response['result'] = 'success';
                 return json_encode($response);
             }
         }
     }
     return $this->render('tabular_input', ['dataProvider' => $dataProvider, 'model' => $model]);
 }