public function actionIndexOLD()
 {
     $slug = 'products';
     $filterForm = new GadgetsStoresFilterForm();
     $cat = Category::findOne(1);
     if (!$cat) {
         throw new NotFoundHttpException('Shop category not found.');
     }
     $filters = null;
     if ($filterForm->load(Yii::$app->request->get()) && $filterForm->validate()) {
         $filters = $filterForm->parse();
     }
     //$sliderFilters= $filters ;
     //$this->view->params['sliderFilters'] = $filters;
     //  var_dump($filters['speed']);//die;
     return $this->render('index', ['cat' => $cat]);
 }
Esempio n. 2
0
 public function actionFields($id)
 {
     if (!($model = Category::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if (Yii::$app->request->post('save')) {
         $fields = Yii::$app->request->post('Field') ?: [];
         $result = [];
         foreach ($fields as $field) {
             $temp = json_decode($field);
             if ($temp === null && json_last_error() !== JSON_ERROR_NONE || empty($temp->name) || empty($temp->title) || empty($temp->type) || !($temp->name = trim($temp->name)) || !($temp->title = trim($temp->title)) || !array_key_exists($temp->type, Category::$fieldTypes)) {
                 continue;
             }
             $options = '';
             if ($temp->type == 'select' || $temp->type == 'checkbox') {
                 if (empty($temp->options) || !($temp->options = trim($temp->options))) {
                     continue;
                 }
                 $options = [];
                 foreach (explode(',', $temp->options) as $option) {
                     $options[] = trim($option);
                 }
             }
             $result[] = ['name' => \yii\helpers\Inflector::slug($temp->name), 'title' => $temp->title, 'type' => $temp->type, 'options' => $options];
         }
         $model->fields = $result;
         if ($model->save()) {
             $ids = [];
             foreach ($model->children()->all() as $child) {
                 $ids[] = $child->primaryKey;
             }
             if (count($ids)) {
                 Category::updateAll(['fields' => json_encode($model->fields)], ['in', 'category_id', $ids]);
             }
             $this->flash('success', Yii::t('easyii/customers', 'Category updated'));
         } else {
             $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
         }
         return $this->refresh();
     } else {
         return $this->render('fields', ['model' => $model]);
     }
 }
Esempio n. 3
0
 public function actionCreate($id)
 {
     if (!($category = Category::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     $model = new Item();
     if ($model->load(Yii::$app->request->post())) {
         $data = Yii::$app->request->post('Item');
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             $model->category_id = $category->primaryKey;
             $model->data = Yii::$app->request->post('Data');
             if (isset($_FILES) && $this->module->settings['itemThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'customers');
                 } else {
                     $model->image = '';
                 }
             }
             if ($model->save()) {
                 //save related items
                 foreach (Yii::$app->request->post('products') as $item) {
                     $CustomerData = new CustomerItems();
                     $CustomerData->item_id = $item;
                     $CustomerData->customer_id = $model->item_id;
                     $CustomerData->save();
                 }
                 $this->flash('success', Yii::t('easyii/customers', 'Item created'));
                 return $this->redirect(['/admin/' . $this->module->id . '/items/edit/', 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         $selected = '';
         return $this->render('create', ['model' => $model, 'category' => $category, 'selectedData' => $selected, 'dataForm' => $this->generateForm($category->fields)]);
     }
 }
Esempio n. 4
0
 private function findCategory($id_slug)
 {
     $category = Category::find()->where(['or', 'category_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     return $category ? new CategoryObject($category) : null;
 }
Esempio n. 5
0
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['category_id' => 'category_id']);
 }
Esempio n. 6
0
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
$category = \app\modules\customers\models\Category::findOne(1);
echo $this->render('_menu', ['category' => $category]);
?>

<?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
echo $form->field($model, 'file')->fileInput();
?>

    <div class="form-group">
        <?php 
echo Html::submitButton('Save', ['class' => 'btn btn-primary']);
?>
    </div>
<?php 
ActiveForm::end();