Commit c4015198e75f02738407ae270d872f90bc703471
1 parent
316bebf4
big commti
Showing
30 changed files
with
110 additions
and
49 deletions
Show diff stats
common/components/artboximage/ArtboxImageHelper.php
| ... | ... | @@ -40,6 +40,7 @@ class ArtboxImageHelper extends Object { |
| 40 | 40 | if (empty($preset) || empty($preset_alias)) { |
| 41 | 41 | return $file; |
| 42 | 42 | } |
| 43 | + | |
| 43 | 44 | $filePath = self::getPathFromUrl($file); |
| 44 | 45 | if (!file_exists($filePath) || !preg_match('#^(.*)\.(' . self::getExtensionsRegexp() . ')$#', $file, $matches)) { |
| 45 | 46 | return $file; | ... | ... |
common/config/main.php
common/modules/product/models/Category.php
| ... | ... | @@ -240,7 +240,7 @@ class Category extends \yii\db\ActiveRecord |
| 240 | 240 | return $query3; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - public function getTaxGroupsByAlias($alias) | |
| 243 | + public function getTaxGroupsForMenu() | |
| 244 | 244 | { |
| 245 | 245 | |
| 246 | 246 | $connection = Yii::$app->getDb(); |
| ... | ... | @@ -255,9 +255,8 @@ class Category extends \yii\db\ActiveRecord |
| 255 | 255 | SELECT product_id FROM product_category WHERE category_id = :category_id |
| 256 | 256 | ) |
| 257 | 257 | ) |
| 258 | - AND tax_group.alias = :alias', | |
| 258 | + AND tax_group.is_menu = true', | |
| 259 | 259 | [ |
| 260 | - ':alias' => $alias, | |
| 261 | 260 | ':category_id' => $this->category_id |
| 262 | 261 | |
| 263 | 262 | ]); | ... | ... |
common/modules/product/models/Export.php
| ... | ... | @@ -18,7 +18,8 @@ class Export extends Model { |
| 18 | 18 | $handle = fopen($dirName .'/'. $filename, "w"); |
| 19 | 19 | ///$products = Product::find()->joinWith(['variants'])->where(['!=', ProductVariant::tableName() .'.stock', 0])->select('product.product_id')->all(); |
| 20 | 20 | $products = Product::find() |
| 21 | - ->with(['variantsWithFilters','brand','categories'])->all(); | |
| 21 | + ->with(['variantsWithFilters','brand','categories','filters'])->all(); | |
| 22 | + | |
| 22 | 23 | |
| 23 | 24 | $i = 0; |
| 24 | 25 | foreach ($products as $product) |
| ... | ... | @@ -89,6 +90,7 @@ class Export extends Model { |
| 89 | 90 | |
| 90 | 91 | |
| 91 | 92 | fputcsv($handle, $to_write, ';'); |
| 93 | + unset($product); | |
| 92 | 94 | } |
| 93 | 95 | |
| 94 | 96 | ... | ... |
common/modules/product/models/Product.php
| ... | ... | @@ -231,7 +231,7 @@ class Product extends \yii\db\ActiveRecord |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | public function getVariantsWithFilters(){ |
| 234 | - return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with(['filters','images']); | |
| 234 | + return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with(['filters','image']); | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** | ... | ... |
common/modules/rubrication/controllers/TaxOptionController.php
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | namespace common\modules\rubrication\controllers; |
| 4 | 4 | |
| 5 | 5 | use common\modules\rubrication\models\TaxGroup; |
| 6 | +use common\modules\rubrication\models\TaxOptionImage; | |
| 6 | 7 | use Yii; |
| 7 | 8 | use common\modules\rubrication\models\TaxOption; |
| 8 | 9 | use common\modules\rubrication\models\TaxOptionSearch; |
| ... | ... | @@ -10,6 +11,7 @@ use yii\data\ActiveDataProvider; |
| 10 | 11 | use yii\web\Controller; |
| 11 | 12 | use yii\web\NotFoundHttpException; |
| 12 | 13 | use yii\filters\VerbFilter; |
| 14 | +use yii\web\UploadedFile; | |
| 13 | 15 | |
| 14 | 16 | /** |
| 15 | 17 | * TaxOptionController implements the CRUD actions for TaxOption model. |
| ... | ... | @@ -78,7 +80,29 @@ class TaxOptionController extends Controller |
| 78 | 80 | |
| 79 | 81 | if ($model->load(Yii::$app->request->post())) { |
| 80 | 82 | |
| 81 | - $model->save(); | |
| 83 | + if ($model->save() && ($image = UploadedFile::getInstance($model, 'image')) ) { | |
| 84 | + $imageModel = TaxOptionImage::find()->where(['tax_option_id' => $model->tax_option_id])->one(); | |
| 85 | + | |
| 86 | + if($imageModel instanceof TaxOptionImage) { | |
| 87 | + $imageModel->product_variant_id = $model->product_variant_id; | |
| 88 | + $imageModel->image = $image->name; | |
| 89 | + $imageModel->save(); | |
| 90 | + } else { | |
| 91 | + $imageModel = new TaxOptionImage(); | |
| 92 | + $imageModel->product_variant_id = $model->product_variant_id; | |
| 93 | + $imageModel->image = $image->name; | |
| 94 | + $imageModel->save(); | |
| 95 | + } | |
| 96 | + | |
| 97 | + | |
| 98 | + $imgDir = Yii::getAlias('@storage/tax_option/'); | |
| 99 | + | |
| 100 | + if(!is_dir($imgDir)) { | |
| 101 | + mkdir($imgDir, 0755, true); | |
| 102 | + } | |
| 103 | + | |
| 104 | + $image->saveAs(Yii::getAlias('@storage/tax_option/' . $image->name)); | |
| 105 | + } | |
| 82 | 106 | |
| 83 | 107 | $valueModel->tax_option_id = $model->tax_option_id; |
| 84 | 108 | $valueModel->value = $model->name; |
| ... | ... | @@ -111,26 +135,32 @@ class TaxOptionController extends Controller |
| 111 | 135 | { |
| 112 | 136 | $model = $this->findModel($id); |
| 113 | 137 | $group = TaxGroup::findOne($model->tax_group_id); |
| 114 | - $valueModelName = $this->getValueModelName($group); | |
| 115 | - $valueModel = $valueModelName::findOne($model->default_value); | |
| 138 | + | |
| 116 | 139 | |
| 117 | 140 | if ($model->load(Yii::$app->request->post())) { |
| 118 | - $model->save(); | |
| 119 | - $valueModel->tax_option_id = $model->tax_option_id; | |
| 120 | - $valueModel->value = $model->name; | |
| 121 | - $valueModel->save(); | |
| 122 | 141 | |
| 123 | - $model->default_value = $valueModel->tax_value_id; | |
| 124 | - $model->save(); | |
| 125 | 142 | |
| 126 | - TaxOption::find()->rebuildMP($model->tax_group_id); | |
| 143 | + if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | |
| 144 | + $model->image = $image->name; | |
| 145 | + } | |
| 146 | + if ($model->save() && $image) { | |
| 147 | + | |
| 148 | + $imgDir = Yii::getAlias('@storage/tax_option/'); | |
| 149 | + | |
| 150 | + if(!is_dir($imgDir)) { | |
| 151 | + mkdir($imgDir, 0755, true); | |
| 152 | + } | |
| 153 | + | |
| 154 | + $image->saveAs(Yii::getAlias('@storage/tax_option/' . $image->name)); | |
| 155 | + } | |
| 156 | + | |
| 157 | + //TaxOption::find()->rebuildMP($model->tax_group_id); | |
| 127 | 158 | |
| 128 | 159 | return $this->redirect(['view', 'id' => $model->tax_option_id]); |
| 129 | 160 | } else { |
| 130 | 161 | return $this->render('update', [ |
| 131 | 162 | 'model' => $model, |
| 132 | - 'group' => $group, | |
| 133 | - 'valueModel' => $valueModel, | |
| 163 | + 'group' => $group | |
| 134 | 164 | ]); |
| 135 | 165 | } |
| 136 | 166 | } | ... | ... |
common/modules/rubrication/models/TaxGroup.php
| ... | ... | @@ -19,6 +19,7 @@ use Yii; |
| 19 | 19 | * @property integer $level |
| 20 | 20 | * @property integer $sort |
| 21 | 21 | * @property boolean $display |
| 22 | + * @property boolean $is_menu | |
| 22 | 23 | * @property TaxGroupToGroup[] $taxGroupToGroups |
| 23 | 24 | * @property TaxGroupToGroup[] $taxGroupToGroups0 |
| 24 | 25 | * @property TaxOption[] $taxOptions |
| ... | ... | @@ -58,7 +59,7 @@ class TaxGroup extends \yii\db\ActiveRecord |
| 58 | 59 | return [ |
| 59 | 60 | [['name', 'module'], 'required'], |
| 60 | 61 | [['description', 'settings'], 'string'], |
| 61 | - [['hierarchical', 'is_filter', 'display'], 'boolean'], | |
| 62 | + [['hierarchical', 'is_filter', 'display','is_menu'], 'boolean'], | |
| 62 | 63 | [['level', 'sort'], 'integer'], |
| 63 | 64 | [['alias', 'module'], 'string', 'max' => 50], |
| 64 | 65 | [['name'], 'string', 'max' => 255], |
| ... | ... | @@ -82,6 +83,7 @@ class TaxGroup extends \yii\db\ActiveRecord |
| 82 | 83 | 'is_filter' => 'Use in filter', |
| 83 | 84 | 'sort' => 'Sort', |
| 84 | 85 | 'display' => 'Display', |
| 86 | + 'is_menu' => 'Отображать в меню', | |
| 85 | 87 | ]; |
| 86 | 88 | } |
| 87 | 89 | ... | ... |
common/modules/rubrication/models/TaxGroupToCategory.php
100644 → 100755
common/modules/rubrication/models/TaxOption.php
| ... | ... | @@ -2,7 +2,6 @@ |
| 2 | 2 | |
| 3 | 3 | namespace common\modules\rubrication\models; |
| 4 | 4 | |
| 5 | -use common\modules\relation\relationBehavior; | |
| 6 | 5 | use Yii; |
| 7 | 6 | use common\components\artboxtree\ArtboxTreeBehavior; |
| 8 | 7 | use yii\db\ActiveRecord; |
| ... | ... | @@ -20,6 +19,7 @@ use yii\db\ActiveRecord; |
| 20 | 19 | * @property integer $sort |
| 21 | 20 | * @property integer $default_value |
| 22 | 21 | * @property integer $name |
| 22 | + * @property array $image | |
| 23 | 23 | * |
| 24 | 24 | * @property TaxEntityRelation[] $taxEntityRelations |
| 25 | 25 | * @property TaxGroup $taxGroup |
| ... | ... | @@ -74,9 +74,8 @@ class TaxOption extends \yii\db\ActiveRecord |
| 74 | 74 | return [ |
| 75 | 75 | [['tax_group_id','name'], 'required'], |
| 76 | 76 | [['tax_group_id', 'parent_id', 'sort', 'default_value'], 'integer'], |
| 77 | - [['alias', 'value'], 'string', 'max' => 50], | |
| 77 | + [['image','alias', 'value'], 'string', 'max' => 255], | |
| 78 | 78 | [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']], |
| 79 | -// [['parent_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxOption::className(), 'targetAttribute' => ['parent_id' => 'tax_option_id']], | |
| 80 | 79 | ]; |
| 81 | 80 | } |
| 82 | 81 | |
| ... | ... | @@ -92,6 +91,7 @@ class TaxOption extends \yii\db\ActiveRecord |
| 92 | 91 | 'alias' => Yii::t('app', 'Alias'), |
| 93 | 92 | 'sort' => Yii::t('app', 'Sort'), |
| 94 | 93 | 'default_value' => Yii::t('app', 'Default Value'), |
| 94 | + 'image' => Yii::t('product', 'Image'), | |
| 95 | 95 | ]; |
| 96 | 96 | } |
| 97 | 97 | |
| ... | ... | @@ -210,15 +210,12 @@ class TaxOption extends \yii\db\ActiveRecord |
| 210 | 210 | return false; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | -// public function beforeDelete() { | |
| 214 | -// if ( ($model = $this->getValueModelName()) !== FALSE ) { | |
| 215 | -// | |
| 216 | -// } | |
| 217 | -// } | |
| 213 | + public function getImageFile() { | |
| 214 | + return empty($this->image) ? null : Yii::getAlias('@imagesDir/tax_option/'. $this->image); | |
| 215 | + } | |
| 218 | 216 | |
| 219 | - private function getValueModelName() { | |
| 220 | - $group = $this->taxGroup; | |
| 221 | - $valueClass = '\common\modules\rubrication\models\TaxValue'. ucfirst($group->module); | |
| 222 | - return class_exists($valueClass) ? $valueClass : FALSE; | |
| 217 | + public function getImageUrl() | |
| 218 | + { | |
| 219 | + return empty($this->image) ? null : Yii::getAlias('@imagesUrl/tax_option/' . $this->image); | |
| 223 | 220 | } |
| 224 | 221 | } | ... | ... |
common/modules/rubrication/views/tax-group/_form.php
| ... | ... | @@ -13,7 +13,7 @@ use common\components\artboxtree\ArtboxTreeHelper; |
| 13 | 13 | |
| 14 | 14 | <div class="tax-group-form"> |
| 15 | 15 | |
| 16 | - <?php $form = ActiveForm::begin(); ?> | |
| 16 | + <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> | |
| 17 | 17 | |
| 18 | 18 | <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> |
| 19 | 19 | |
| ... | ... | @@ -37,7 +37,9 @@ use common\components\artboxtree\ArtboxTreeHelper; |
| 37 | 37 | <?= $form->field($model, 'is_filter')->checkbox() ?> |
| 38 | 38 | |
| 39 | 39 | <?= $form->field($model, 'display')->checkbox() ?> |
| 40 | - | |
| 40 | + | |
| 41 | + <?= $form->field($model, 'is_menu')->checkbox() ?> | |
| 42 | + | |
| 41 | 43 | <?= $form->field($model, 'sort')->textInput() ?> |
| 42 | 44 | |
| 43 | 45 | <div class="form-group"> | ... | ... |
common/modules/rubrication/views/tax-option/_form.php
| ... | ... | @@ -15,7 +15,7 @@ use common\modules\rubrication\helpers\RubricationHelper; |
| 15 | 15 | |
| 16 | 16 | <div class="tax-option-form"> |
| 17 | 17 | |
| 18 | - <?php $form = ActiveForm::begin(); ?> | |
| 18 | + <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> | |
| 19 | 19 | <?php if (empty($group->tax_group_id)) :?> |
| 20 | 20 | <?= $form->field($model, 'tax_group_id')->dropDownList( |
| 21 | 21 | ArrayHelper::map(TaxOption::find()->all(), 'tax_group_id', 'name'), |
| ... | ... | @@ -33,23 +33,39 @@ use common\modules\rubrication\helpers\RubricationHelper; |
| 33 | 33 | |
| 34 | 34 | <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> |
| 35 | 35 | |
| 36 | - <?php if ($group->hierarchical) :?> | |
| 37 | - <?php | |
| 36 | + <?php if ($group->hierarchical) { | |
| 38 | 37 | $tree = TaxOption::find()->getTree($model->tax_group_id); |
| 39 | - ?> | |
| 40 | - <?= $form->field($model, 'parent_id')->dropDownList( | |
| 38 | + $form->field($model, 'parent_id')->dropDownList( | |
| 41 | 39 | ArtboxTreeHelper::treeMap($tree, 'tax_option_id', 'ValueRenderFlash', '.'), |
| 42 | 40 | [ |
| 43 | 41 | 'prompt' => Yii::t('rubrication', 'Root level'), |
| 44 | 42 | 'options' => [ |
| 45 | 43 | $model->tax_option_id => ['disabled' => true] |
| 46 | 44 | ] |
| 47 | - ] | |
| 48 | - ) ?> | |
| 49 | - <?php else :?> | |
| 50 | - <?= $form->field($model, 'parent_id')->hiddenInput()->label('') ?> | |
| 51 | - <?php endif?> | |
| 45 | + ]); | |
| 46 | + | |
| 47 | + }else { | |
| 48 | + | |
| 49 | + $form->field($model, 'parent_id')->hiddenInput()->label(''); | |
| 50 | + } | |
| 51 | + ?> | |
| 52 | + | |
| 52 | 53 | |
| 54 | + <?= $form->field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ | |
| 55 | + 'language' => 'ru', | |
| 56 | + 'options' => [ | |
| 57 | + 'accept' => 'image/*', | |
| 58 | + 'multiple' => false, | |
| 59 | + ], | |
| 60 | + 'pluginOptions' => [ | |
| 61 | + 'allowedFileExtensions' => ['jpg', 'gif', 'png'], | |
| 62 | + 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', | |
| 63 | + 'overwriteInitial' => true, | |
| 64 | + 'showRemove' => false, | |
| 65 | + 'showUpload' => false, | |
| 66 | + 'previewFileType' => 'image', | |
| 67 | + ], | |
| 68 | + ]); ?> | |
| 53 | 69 | <?= $form->field($model, 'sort')->dropDownList(RubricationHelper::SortArray()) ?> |
| 54 | 70 | |
| 55 | 71 | <div class="form-group"> | ... | ... |
common/modules/rubrication/views/tax-option/create.php
common/modules/rubrication/views/tax-option/update.php
| ... | ... | @@ -19,8 +19,7 @@ $this->params['breadcrumbs'][] = Yii::t('rubrication', 'Update'); |
| 19 | 19 | |
| 20 | 20 | <?= $this->render('_form', [ |
| 21 | 21 | 'model' => $model, |
| 22 | - 'group' => $group, | |
| 23 | - 'valueModel' => $valueModel, | |
| 22 | + 'group' => $group | |
| 24 | 23 | ]) ?> |
| 25 | 24 | |
| 26 | 25 | </div> | ... | ... |
console/migrations/m160812_140415_tax_group_to_category.php
100644 → 100755
console/migrations/m160815_101433_add_name_to_category.php
100644 → 100755
console/migrations/m160815_101441_add_name_to_brand.php
100644 → 100755
frontend/views/layouts/main-menu.php
| 1 | 1 | <?php |
| 2 | +use common\components\artboximage\ArtboxImageHelper; | |
| 2 | 3 | use common\modules\product\models\Category; |
| 4 | +use yii\helpers\Html; | |
| 3 | 5 | use yii\helpers\Url; |
| 4 | 6 | |
| 5 | 7 | $models = Category::find()->all(); |
| ... | ... | @@ -24,11 +26,13 @@ $models = Category::find()->all(); |
| 24 | 26 | |
| 25 | 27 | <ul> |
| 26 | 28 | |
| 27 | - <?php foreach($model->getTaxGroupsByAlias('naznacenie') as $group): ?> | |
| 29 | + <?php foreach($model->getTaxGroupsForMenu() as $group): ?> | |
| 28 | 30 | <li> |
| 29 | 31 | |
| 30 | - <a href="<?= Url::to(['catalog/category','category' => $model['alias'],'filters' => ['naznacenie' => [$group['option_alias']]]]) ?>"> | |
| 31 | - <i class="spritecat spritecat-klassicheskie_4"></i> | |
| 32 | + <a href="<?= Url::to(['catalog/category','category' => $model['alias'],'filters' => [$group['alias'] => [$group['option_alias']]]]) ?>"> | |
| 33 | + <div class="option_image_block"> | |
| 34 | + <?= Html::img(ArtboxImageHelper::getImageSrc(Yii::getAlias('@imagesUrl/tax_option/'. $group['image']), 'option_menu'))?> | |
| 35 | + </div> | |
| 32 | 36 | <div class="clearfix"></div> |
| 33 | 37 | <span class="menu-bar-cat-name"><?=$group['value']?></span> |
| 34 | 38 | </a> | ... | ... |
frontend/web/css/css_header.css
| ... | ... | @@ -9,6 +9,10 @@ |
| 9 | 9 | top: 0px; |
| 10 | 10 | right: -7px; |
| 11 | 11 | } |
| 12 | + | |
| 13 | +.option_image_block{ | |
| 14 | + height: 110px; | |
| 15 | +} | |
| 12 | 16 | /*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */ |
| 13 | 17 | html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:0.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em |
| 14 | 18 | 40px}hr{box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button, | ... | ... |