diff --git a/backend/controllers/EventController.php b/backend/controllers/EventController.php index 31d4f6f..49cbd6f 100755 --- a/backend/controllers/EventController.php +++ b/backend/controllers/EventController.php @@ -159,6 +159,14 @@ class EventController extends Controller return $this->redirect(['index']); } + public function actionDelimg($id,$field){ + $model = $this->findModel($id); + $model->$field = ''; + $model->save(); + return true; + } + + /** * Finds the Event model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/backend/views/event/_form.php b/backend/views/event/_form.php index d7285e7..a78ef21 100755 --- a/backend/views/event/_form.php +++ b/backend/views/event/_form.php @@ -51,8 +51,9 @@ use mihaildev\elfinder\ElFinder; 'pluginOptions' => [ 'allowedFileExtensions' => ['jpg', 'gif', 'png'], 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', + 'deleteUrl' => \yii\helpers\Url::to(['/product/manage/delimg', 'id' => $model->primaryKey]), + 'initialPreviewConfig' => $model->getImagesConfig(), 'overwriteInitial' => true, - 'showRemove' => false, 'showUpload' => false, 'previewFileType' => 'image', ], @@ -68,8 +69,9 @@ use mihaildev\elfinder\ElFinder; 'pluginOptions' => [ 'allowedFileExtensions' => ['jpg', 'gif', 'png'], 'initialPreview' => !empty($model->getImageUrl('banner')) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->getImageUrl('banner'), 'list') : '', + 'deleteUrl' => \yii\helpers\Url::to(['/product/manage/delimg', 'id' => $model->primaryKey]), + 'initialPreviewConfig' => $model->getImagesConfig('banner'), 'overwriteInitial' => true, - 'showRemove' => false, 'showUpload' => false, 'previewFileType' => 'image', ], diff --git a/common/behaviors/SaveImgBehavior.php b/common/behaviors/SaveImgBehavior.php index a962955..0f00673 100755 --- a/common/behaviors/SaveImgBehavior.php +++ b/common/behaviors/SaveImgBehavior.php @@ -52,6 +52,23 @@ class SaveImgBehavior extends Behavior } + public function getImagesConfig($image = 'image') { + $op = []; + if ($this->owner->$image) { + + $op[] = [ + 'caption' => $this->owner->$image, + 'url' => \yii\helpers\Url::to(['delimg', 'id' => $this->owner->primaryKey, 'field' =>$image ]), + 'key' => $this->owner->primaryKey, + 'extra' => [ + 'id' => $this->owner->primaryKey, + ], + ]; + + } + return $op; + } + public function beforeInsert($event) { diff --git a/common/config/main.php b/common/config/main.php index bd3e927..8cdba62 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -157,6 +157,13 @@ return [ 'master' => null ], ], + 'banner_list' => [ + 'resize' => [ + 'width' => 160, + 'height' => 60, + 'master' => null + ], + ], 'large' => [ 'resize' => [ 'width' => 600, diff --git a/common/models/Event.php b/common/models/Event.php index 3231f03..7b8317b 100755 --- a/common/models/Event.php +++ b/common/models/Event.php @@ -91,10 +91,10 @@ class Event extends \yii\db\ActiveRecord { return [ [['body', 'seo_text'], 'string'], - [['created_at', 'updated_at','percent','sale','is_event' ], 'integer'], + [['created_at', 'updated_at','percent' ], 'integer'], [['name', 'alias', 'image', 'meta_title', 'description', 'h1','end_at','banner'], 'string', 'max' => 255], [['name','body'], 'required'], - [['imageUpload'], 'safe'], + [['imageUpload','sale','is_event'], 'safe'], [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], [['products_file'], 'file'], ]; diff --git a/common/modules/product/models/Import.php b/common/modules/product/models/Import.php index 8383642..791a83f 100755 --- a/common/modules/product/models/Import.php +++ b/common/modules/product/models/Import.php @@ -248,9 +248,10 @@ class Import extends Model { // 1 Группа (категория) $catalog_names = explode(',',$data[0]); + if (empty ($catalog_names)) { - $result_items[] = "Не указана категория (строка $j)"; + $result_items[] = "Не указана категория (строка $j) "; continue; } @@ -281,7 +282,7 @@ class Import extends Model { // 11 Цена акция $product_cost_old = floatval($data[7]); - + $product_cost = ''; // 10 Цена if ($product_cost_old) { $product_cost_old = floatval($data[6]); @@ -315,15 +316,16 @@ class Import extends Model { $product_image = explode ('=', $data[14]); $product_image = @$product_image[3]; - if ( ($_product = Product::find()->filterWhere(['ilike', 'name', trim($product_name)])->one()) === null ) { + if ( ($_product = Product::find()->filterWhere(['name' => trim($product_name)])->one()) === null ) { $_product = new Product(); } $is_new_product = empty($_product->product_id); - + $category_id = []; foreach($catalog_names as $catalog_name){ + // ==== Set category ==== - if ( ($category = Category::find()->filterWhere(['ilike', 'name', trim($catalog_name)])->one()) === null ) { + if ( ($category = Category::find()->filterWhere([ 'name' => trim($catalog_name)])->one()) === null ) { // Create category $category = new Category(); $category->name = trim($catalog_name); @@ -338,7 +340,7 @@ class Import extends Model { // ===== Set brand ==== if ( $brand_name ) { - if ( ($brand = Brand::find()->filterWhere(['ilike', 'name', trim($brand_name)])->one()) !== null ) { + if ( ($brand = Brand::find()->filterWhere(['name' => trim($brand_name)])->one()) !== null ) { $_product->brand_id = $brand->brand_id; } else { // Create brand @@ -368,7 +370,7 @@ class Import extends Model { $source_image = Yii::getAlias('@uploadDir') . '/product_images/'. urlencode($foto); if (file_exists($source_image)) { - if (($productImage = ProductImage::find()->andFilterWhere(['ilike', 'image', $foto])->andFilterWhere(['product_id' => $_product->product_id])->one()) === null) { + if (($productImage = ProductImage::find()->andFilterWhere(['image'=> $foto])->andFilterWhere(['product_id' => $_product->product_id])->one()) === null) { copy($source_image, Yii::getAlias('@productsDir') . "/" . $foto); $productImage = new ProductImage(); $productImage->product_id = $_product->product_id; @@ -397,7 +399,7 @@ class Import extends Model { $mod_old_cost = floatval($product_cost_old); // Check product variant - if ( ($_productVariant = ProductVariant::find()->andFilterWhere(['ilike', 'sku', $mod_art])->andFilterWhere(['product_id' => $_product->product_id])->one()) === null ) { + if ( ($_productVariant = ProductVariant::find()->andFilterWhere([ 'sku'=> $mod_art])->andFilterWhere(['product_id' => $_product->product_id])->one()) === null ) { $_productVariant = new ProductVariant(); $_productVariant->product_id = $_product->product_id; } @@ -428,7 +430,7 @@ class Import extends Model { // ===== Set variant type ==== if ( $product_variant_type_name ) { - if ( ($product_variant_type = ProductVariantType::find()->filterWhere(['ilike', 'name', $product_variant_type_name])->one()) !== null ) { + if ( ($product_variant_type = ProductVariantType::find()->filterWhere([ 'name'=> $product_variant_type_name])->one()) !== null ) { $_productVariant->product_variant_type_id = $product_variant_type->product_variant_type_id; } else { $product_variant_type = new ProductVariantType(); @@ -443,10 +445,10 @@ class Import extends Model { $MOD_ARRAY[] = $_productVariant->product_variant_id; if ($mod_image) { - $source_image = Yii::getAlias('@uploadDir') . '/product_images/'. urlencode($mod_image); + $source_image = Yii::getAlias('@productsDir') . '/'. urlencode($mod_image); if (file_exists($source_image)) { - if (($variantImage = ProductImage::find()->andFilterWhere(['ilike', 'image', $mod_image])->andFilterWhere(['product_variant_id' => $_productVariant->product_variant_id])->one()) === null) { - copy($source_image, Yii::getAlias('@productsDir') . "/" . $mod_image); + if (($variantImage = ProductImage::find()->andFilterWhere([ 'image' => $mod_image])->andFilterWhere(['product_variant_id' => $_productVariant->product_variant_id])->one()) === null) { +// copy($source_image, Yii::getAlias('@productsDir') . "/" . $mod_image); $variantImage = new ProductImage(); $variantImage->product_id = $_product->product_id; $variantImage->product_variant_id = $_productVariant->product_variant_id; @@ -575,7 +577,7 @@ class Import extends Model { $filters_options = explode(',',$filter[2][0]); foreach($filters_options as $filter_options){ - $value = TaxValueString::find()->innerJoinWith('taxOption')->andFilterWhere(['ilike', 'value', $filter_options])->andFilterWhere(['tax_option.tax_group_id' => $taxGroup->tax_group_id])->one(); + $value = TaxValueString::find()->innerJoinWith('taxOption')->andWhere(['value'=>$filter_options])->andWhere(['tax_option.tax_group_id' => $taxGroup->tax_group_id])->one(); if (!$value instanceof TaxValueString) { // Create option diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index 573458d..799af21 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -37,8 +37,9 @@ use common\models\Event; */ class Product extends \yii\db\ActiveRecord { - /** @var array $_variants */ public $_variants = []; + public $_categories = []; + public $_options = []; /** @var array $_images */ public $imagesUpload = ''; @@ -77,6 +78,11 @@ class Product extends \yii\db\ActiveRecord { return '{{%product}}'; } + + + /** + * @return \yii\db\ActiveQuery + */ public function getEvents(){ return $this->hasMany(Event::className(), ['event_id' => 'event_id'])->viaTable('events_to_products', ['product_id' => 'product_id']); } @@ -159,6 +165,7 @@ class Product extends \yii\db\ActiveRecord return $this->hasMany(ProductImage::className(), ['product_id' => 'product_id'])->where(['product_variant_id' => null]); } + /** * @return \yii\db\ActiveQuery */ @@ -313,21 +320,7 @@ class Product extends \yii\db\ActiveRecord { if(parent::beforeSave($insert)){ - if(!empty($this->categories)){ - $categories = Category::findAll($this->categories); - $this->unlinkAll('categories', true); - foreach($categories as $category){ - $this->link('categories', $category); - } - } - if(!empty($this->options)){ - $options = TaxOption::findAll($this->options); - $this->unlinkAll('options',true); - foreach($options as $option){ - $this->link('options', $option); - } - } return true; } return false; @@ -340,6 +333,24 @@ class Product extends \yii\db\ActiveRecord { parent::afterSave($insert, $changedAttributes); + + if(!empty($this->categories)){ + $categories = Category::findAll($this->categories); + $this->unlinkAll('categories', true); + foreach($categories as $category){ + $this->link('categories', $category); + } + } + + if(!empty($this->options)){ + $options = TaxOption::findAll($this->options); + $this->unlinkAll('options',true); + foreach($options as $option){ + $this->link('options', $option); + } + } + + if (!empty($this->_variants)) { $todel = []; foreach ($this->variants ?: [] as $_variant) { @@ -367,13 +378,18 @@ class Product extends \yii\db\ActiveRecord } public function beforeDelete() { - ProductImage::deleteAll(['product_id' => $this->product_id]); - ProductCategory::deleteAll(['product_id' => $this->product_id]); - ProductVariant::deleteAll(['product_id' => $this->product_id]); - ProductOption::deleteAll(['product_id' => $this->product_id]); - ProductStock::deleteAll(['product_id' => $this->product_id]); - Share::deleteAll(['product_id' => $this->product_id]); - return true; + if(parent::beforeDelete()){ + $this->unlinkAll('categories', true); + $this->unlinkAll('options', true); + ProductImage::deleteAll(['product_id' => $this->product_id]); + + ProductVariant::deleteAll(['product_id' => $this->product_id]); + ProductStock::deleteAll(['product_id' => $this->product_id]); + Share::deleteAll(['product_id' => $this->product_id]); + return true; + } + return false; + } public function imagesUpload() diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index 36b3474..d3742e1 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -38,6 +38,7 @@ class ProductVariant extends \yii\db\ActiveRecord public $translit; public $translit_rubric; private $data; + public $_options = []; /** @var array $_images */ @@ -255,8 +256,18 @@ class ProductVariant extends \yii\db\ActiveRecord return TaxGroup::find()->distinct()->innerJoin('tax_group_to_category', 'tax_group_to_category.tax_group_id = tax_group.tax_group_id')->where(['tax_group_to_category.category_id' => $categories])->where(['level' => $level]); } -// public function afterSave($insert, $changedAttributes) -// { + public function afterSave($insert, $changedAttributes) + { + + if(!empty($this->_options)){ + $options = TaxOption::findAll($this->_options); + $this->unlinkAll('options',true); + foreach($options as $option){ + $this->link('options', $option); + } + } + + // if (!is_null($this->stocks)) { // //ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]); // $values = []; @@ -266,14 +277,17 @@ class ProductVariant extends \yii\db\ActiveRecord // $productStock->save(); // } // } -// parent::afterSave($insert, $changedAttributes); -// } + parent::afterSave($insert, $changedAttributes); + } public function beforeDelete() { - ProductVariantOption::deleteAll(['product_variant_id' => $this->product_variant_id]); - ProductImage::deleteAll(['product_variant_id' => $this->product_variant_id]); - ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]); - return true; + if(parent::beforeDelete()){ + ProductVariantOption::deleteAll(['product_variant_id' => $this->product_variant_id]); + ProductImage::deleteAll(['product_variant_id' => $this->product_variant_id]); + ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]); + return true; + } + return false; } public function imagesUpload() diff --git a/frontend/config/main.php b/frontend/config/main.php index 3c48e12..082a989 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -76,6 +76,7 @@ return [ 'blog' => 'articles/index', 'blog/-' => 'articles/show', 'event' => 'event/index', + 'event/sale/' => 'event/sale', 'event/' => 'event/show', ], 'class' => 'common\components\urlManager\LangUrlManager', diff --git a/frontend/views/catalog/_product_item.php b/frontend/views/catalog/_product_item.php index 509469f..db2c240 100755 --- a/frontend/views/catalog/_product_item.php +++ b/frontend/views/catalog/_product_item.php @@ -17,6 +17,16 @@ use yii\helpers\Url; 'catalog/product', 'product' => $model->alias ]) ?>"> + events as $event){ + if($event->banner){ + echo \common\components\artboximage\ArtboxImageHelper::getImage($event->getImageUrl('banner'), 'banner_list',[ + 'class' => 'banner-in-list' + ]); + } + } + + ?> enabledVariants[ 0 ]->imageUrl, 'list', [ 'alt' => $model->category->name . ' ' . $model->fullname, 'title' => $model->category->name . ' ' . $model->fullname, @@ -37,6 +47,15 @@ use yii\helpers\Url;
+ + variant->price_old){?> +
+ + variant->price_old ?> + грн + +
+
Цена: diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php index c6035d4..aca5c9a 100755 --- a/frontend/views/catalog/product.php +++ b/frontend/views/catalog/product.php @@ -207,7 +207,7 @@ FlipclockAsset::register($this); — Самовывоз Новая Почта - 55 грн.
— Курьер Новая Почта - 88 грн.
— Курьер «ИнТайм» - 60 грн.

- variant->price > 1000){?> + variant->price >= 1000){?>

Киев:
— Курьер - 50 грн. diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 1e0d2e3..621a88e 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -23,10 +23,9 @@ use common\models\Event; - - <?= Seo::widget([ 'row'=>'title'])?> + <?= Seo::widget([ 'row'=>'title'])?> 'description'])?> - 'meta'])?> */?> + 'meta'])?> diff --git a/frontend/views/search/_product_search_item.php b/frontend/views/search/_product_search_item.php deleted file mode 100755 index c51a8e5..0000000 --- a/frontend/views/search/_product_search_item.php +++ /dev/null @@ -1,92 +0,0 @@ - -

-
-
- -
- name, Url::to(['catalog/product', 'product' => $model->alias]), ['class'=>'btn-product-details'] )?> -
- -
-
- Цена: - - variant->price ?> - грн - -
-
-
-
Особенности
-
-
-
    - -
  • Бренд: brand->name ?>
  • - - getActiveProperties($model->category->category_id) as $group): ?> -
  • name ?> _options as $option) : ?> ValueRenderHTML ?>
  • - - - -
-
-
-
- -
-
-
-
-
-
\ No newline at end of file diff --git a/frontend/views/search/index.php b/frontend/views/search/index.php index 5477246..3ad9db7 100755 --- a/frontend/views/search/index.php +++ b/frontend/views/search/index.php @@ -84,8 +84,9 @@ $this->params['breadcrumbs'][] = 'Поиск'; $productProvider, 'itemView' => function ($model, $key, $index, $widget) { - return $this->render('_product_search_item',[ - 'model' => $model + return $this->render('../catalog/_product_item',[ + 'model' => $model, + 'category' => $model->category ]); }, 'layout' => "{items}
{pager}", diff --git a/frontend/web/css/css_header.css b/frontend/web/css/css_header.css index 46d2700..13131c6 100755 --- a/frontend/web/css/css_header.css +++ b/frontend/web/css/css_header.css @@ -14544,4 +14544,8 @@ ul.product-special li.promo div{ -ms-filter: grayscale(0%); -o-filter: grayscale(0%); -moz-filter: grayscale(0%); +} + +.banner-in-list{ + margin: 0 !important; } \ No newline at end of file -- libgit2 0.21.4