From 37415bee4fc1e7726fa78de3b4173357910b940d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 7 Oct 2016 12:52:33 +0300 Subject: [PATCH] big commti --- common/behaviors/SaveImgBehavior.php | 8 ++++---- common/behaviors/SaveMultipleImgBehavior.php | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/behaviors/Slug.php | 1 + common/config/main.php | 3 +-- common/modules/product/controllers/ManageController.php | 28 +--------------------------- common/modules/product/models/Category.php | 6 ++++-- common/modules/product/models/Import.php | 8 ++++---- common/modules/product/models/Product.php | 50 ++++++++++++++++++++++++++++++++++---------------- common/modules/product/models/ProductVariant.php | 2 +- console/config/bootstrap.php | 2 +- console/controllers/ImportController.php | 20 ++++++++++++++++++++ console/migrations/m160920_193158_add_isEvent_to_event.php | 27 +++++++++++++++++++++++++++ console/migrations/m160920_193159_add_isEvent_to_event.php | 27 --------------------------- frontend/config/bootstrap.php | 1 + frontend/config/main.php | 2 +- frontend/controllers/CatalogController.php | 2 +- frontend/controllers/EventController.php | 4 ++-- frontend/controllers/OrderController.php | 5 ++++- frontend/controllers/SiteController.php | 6 ++++++ frontend/views/catalog/product.php | 59 +++++++++++++++++++++++++++++++++++++++-------------------- frontend/views/event/_objects.php | 4 ++-- frontend/views/site/error.php | 10 +++++----- frontend/web/css/css_header.css | 11 +++++------ 23 files changed, 299 insertions(+), 122 deletions(-) create mode 100755 common/behaviors/SaveMultipleImgBehavior.php create mode 100755 console/migrations/m160920_193158_add_isEvent_to_event.php delete mode 100755 console/migrations/m160920_193159_add_isEvent_to_event.php diff --git a/common/behaviors/SaveImgBehavior.php b/common/behaviors/SaveImgBehavior.php index eaa5389..a962955 100755 --- a/common/behaviors/SaveImgBehavior.php +++ b/common/behaviors/SaveImgBehavior.php @@ -29,11 +29,11 @@ class SaveImgBehavior extends Behavior { foreach($this->fields as $field){ if ( ($image = UploadedFile::getInstance($this->owner, $field['name'])) ) { - $this->owner->image = $image->name; + $this->owner->{$field['name']} = $image->name; } - if(!$this->owner->image){ - $this->owner->image = $this->owner->getOldAttribute($field['name']); + if(!$this->owner->{$field['name']}){ + $this->owner->{$field['name']} = $this->owner->getOldAttribute($field['name']); } @@ -58,7 +58,7 @@ class SaveImgBehavior extends Behavior foreach($this->fields as $field){ if ( ($image = UploadedFile::getInstance($this->owner, $field['name'])) ) { - $this->owner->$field['name'] = $image->name; + $this->owner->{$field['name']} = $image->name; } diff --git a/common/behaviors/SaveMultipleImgBehavior.php b/common/behaviors/SaveMultipleImgBehavior.php new file mode 100755 index 0000000..ddd2f72 --- /dev/null +++ b/common/behaviors/SaveMultipleImgBehavior.php @@ -0,0 +1,135 @@ + 'downloadImages', + ActiveRecord::EVENT_BEFORE_INSERT => 'downloadImages', + ]; + } + + public function downloadImages($event) + { + foreach($this->fields as $field){ + + + $this->imagesUpload = UploadedFile::getInstances($this->owner, $field['name']); + + if ( ($images = $this->imagesUpload($field)) !== FALSE) { + + foreach ($images as $image) { + $imageModel = new ProductImage(); + $imageModel->product_id = $this->owner->product_id; + $imageModel->image = $image; + $imageModel->save(); + } + + + } + + } + } + + + + /** + * @param $field array ['directory','name'] + * @return array + */ + + public function imagesUpload($field) + { + $images = []; + + /** + * @var $image UploadedFile + */ + + foreach ($this->imagesUpload as $image) { + + $imageName = $image->baseName . '.' . $image->extension; + $i = 0; + + while (file_exists(\Yii::getAlias('@imagesDir/'.$field['directory'].'/' . $imageName))) { + $i++; + $imageName = $image->baseName . '_' . $i . '.' . $image->extension; + } + + $imgDir = \Yii::getAlias('@imagesDir/'.$field['directory'].'/'); + + if (!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + + $image->saveAs($imgDir . $imageName); + + $images[] = $imageName; + + } + return $images; + } + + + + + public function getImageFile($image = 'image') { + return empty($this->owner->$image) ? null : '/storage/'.$this->fields[0]['directory'].'/'. $this->owner->$image; + } + + public function getImageUrl($image = 'image') { + return empty($this->owner->$image) ? null : '/storage/'.$this->fields[0]['directory'].'/'. $this->owner->$image; + } + + public function getImagesConfig() { + $op = []; + if ($this->owner->images) { + foreach ($this->owner->images as $image) { + $op[] = [ + 'caption' => $image->owner->image, + 'url' => \yii\helpers\Url::to(['/product/manage/delimg', 'id' => $image->product_image_id]), + 'key' => $image->primaryKey, + 'extra' => [ + 'id' => $image->primaryKey, + ], + ]; + } + } + return $op; + } + + public function getImagesHTML() { + $op = []; + if ($this->images) { + foreach ($this->images as $image) { + $op[] = \common\components\artboximage\ArtboxImageHelper::getImage($image->imageUrl, 'admin_thumb'); + } + } + return $op; + } + + + + + + + +} \ No newline at end of file diff --git a/common/behaviors/Slug.php b/common/behaviors/Slug.php index 214f701..4b316cf 100755 --- a/common/behaviors/Slug.php +++ b/common/behaviors/Slug.php @@ -22,6 +22,7 @@ class Slug extends Behavior public function getSlug( $event ) { + if(!empty($this->owner->{$this->in_attribute})){ if ( empty( $this->owner->{$this->out_attribute} ) ) { $this->owner->{$this->out_attribute} = $this->generateSlug( $this->owner->{$this->in_attribute} ); diff --git a/common/config/main.php b/common/config/main.php index a00ee66..bd3e927 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -127,8 +127,7 @@ return [ 'event_left' => [ 'resize' => [ - 'width' => 960, - 'height' => 400, + 'width' => 1140, 'master' => null ], ], diff --git a/common/modules/product/controllers/ManageController.php b/common/modules/product/controllers/ManageController.php index 0f5b159..bf5864b 100755 --- a/common/modules/product/controllers/ManageController.php +++ b/common/modules/product/controllers/ManageController.php @@ -82,20 +82,7 @@ class ManageController extends Controller $model = new Product(); if ($model->load(Yii::$app->request->post())) { - $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); - - if ($model->save() && $model->imagesUpload) { - - $imgDir = Yii::getAlias('@storage/articles/'); - - if ( ($images = $model->imagesUpload()) !== FALSE) { - foreach ($images as $image) { - $imageModel = new ProductImage(); - $imageModel->product_id = $model->product_id; - $imageModel->image = $image; - $imageModel->save(); - } - } + if ($model->save()) { return $this->redirect(['view', 'id' => $model->product_id]); } @@ -116,20 +103,7 @@ class ManageController extends Controller { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { - $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); if ($model->save()) { -// foreach ($model->images as $image) { -// $image->delete(); -// } - if ( ($images = $model->imagesUpload()) !== FALSE) { - foreach ($images as $image) { - $imageModel = new ProductImage(); - $imageModel->product_id = $model->product_id; - $imageModel->image = $image; - $imageModel->save(); - } - } - return $this->redirect(['view', 'id' => $model->product_id]); } } else { diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index d803136..b09dd64 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -209,7 +209,8 @@ class Category extends \yii\db\ActiveRecord ->innerJoin('product', 'product.product_id = product_variant.product_id') ->innerJoin('product_category', 'product_category.product_id = product.product_id') ->innerJoin('tax_value_string', 'tax_value_string.tax_option_id = tax_option.tax_option_id') - ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE]) + ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id') + ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE,'tax_group_to_category.category_id'=>$this->category_id]) ->andWhere(['!=', 'product_variant.stock', 0]); $query2 = (new Query()) @@ -224,7 +225,8 @@ class Category extends \yii\db\ActiveRecord ->innerJoin('product_category', 'product_category.product_id = product.product_id') ->innerJoin('product_variant', 'product_variant.product_id = product.product_id') ->innerJoin('tax_value_string', 'tax_value_string.tax_option_id = tax_option.tax_option_id') - ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE]) + ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id') + ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE,'tax_group_to_category.category_id'=>$this->category_id]) ->andWhere(['!=', 'product_variant.stock', 0]); $query3 = (new Query()) ->select([ diff --git a/common/modules/product/models/Import.php b/common/modules/product/models/Import.php index f3c0450..8383642 100755 --- a/common/modules/product/models/Import.php +++ b/common/modules/product/models/Import.php @@ -443,17 +443,17 @@ class Import extends Model { $MOD_ARRAY[] = $_productVariant->product_variant_id; if ($mod_image) { -// $source_image = Yii::getAlias('@uploadDir') . '/product_images/'. urlencode($mod_image); -// if (file_exists($source_image)) { + $source_image = Yii::getAlias('@uploadDir') . '/product_images/'. 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); + 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; $variantImage->image = $mod_image; $variantImage->save(); } -// } + } } } } diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index a2e648b..573458d 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -2,6 +2,7 @@ namespace common\modules\product\models; +use common\behaviors\SaveMultipleImgBehavior; use common\behaviors\Slug; use common\models\ProductToRating; use common\models\Share; @@ -42,6 +43,9 @@ class Product extends \yii\db\ActiveRecord /** @var array $_images */ public $imagesUpload = ''; + + + /** * @inheritdoc */ @@ -49,7 +53,13 @@ class Product extends \yii\db\ActiveRecord { return [ [ - 'class' =>FilterBehavior::className(), + 'class' => SaveMultipleImgBehavior::className(), + 'fields' => [ + ['name'=>'imagesUpload','directory' => 'products' ] + ] + ], + [ + 'class' => FilterBehavior::className(), ], [ 'class' => Slug::className(), @@ -298,28 +308,37 @@ class Product extends \yii\db\ActiveRecord ->sum('quantity'); } - public function afterSave($insert, $changedAttributes) + + public function beforeSave($insert) { - parent::afterSave($insert, $changedAttributes); + 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->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; - if(!empty($this->options)){ - $options = TaxOption::findAll($this->options); - $this->unlinkAll('options',true); - foreach($options as $option){ - $this->link('options', $option); - } - } + } + + public function afterSave($insert, $changedAttributes) + { + parent::afterSave($insert, $changedAttributes); if (!empty($this->_variants)) { $todel = []; @@ -399,7 +418,6 @@ class Product extends \yii\db\ActiveRecord foreach ($this->images as $image) { $op[] = [ 'caption' => $image->image, - 'width' => '120px', 'url' => \yii\helpers\Url::to(['/product/manage/delimg', 'id' => $image->product_image_id]), 'key' => $image->product_image_id, 'extra' => [ diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index aa42bec..36b3474 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -163,7 +163,7 @@ class ProductVariant extends \yii\db\ActiveRecord public function getImageUrl() { // return a default image placeholder if your source image is not found - return !empty($this->image) ? $this->image->imageUrl : '/images/no_photo.png'; + return (!empty($this->image) && file_exists(Yii::getAlias('@productsDir') . "/" . $this->image->image )) ? $this->image->imageUrl : '/images/no_photo.png'; } public function getFullname() { diff --git a/console/config/bootstrap.php b/console/config/bootstrap.php index 5005cb3..1924a47 100755 --- a/console/config/bootstrap.php +++ b/console/config/bootstrap.php @@ -6,4 +6,4 @@ Yii::setAlias('@uploadFilePricesAway', 'price_product_away.csv'); Yii::setAlias('@uploadFilePricesDuplicate', 'price_duplicate.csv'); Yii::setAlias('@uploadFilePricesNoVariant', 'price_no_variant.csv'); -Yii::setAlias('@productsDir', '@frontend/web/images/products'); \ No newline at end of file +Yii::setAlias('@productsDir', '@storage/products'); \ No newline at end of file diff --git a/console/controllers/ImportController.php b/console/controllers/ImportController.php index b6a7c79..e7abad1 100755 --- a/console/controllers/ImportController.php +++ b/console/controllers/ImportController.php @@ -20,6 +20,26 @@ class ImportController extends Controller { public $errors = []; + public function actionImages(){ + $files = ProductImage::find()->all(); + foreach($files as $file_object){ + $file = $file_object->image; + $file_array = explode('/',$file); + if(is_array($file_array) && count($file_array) >3){ + $count = count($file_array); + $file_name = $file_array[$count-2]."_".$file_array[$count-1]; + print_r($file_name); + $save_image = Yii::getAlias('@productsDir') . "/" . $file_name; + copy($file, $save_image); + $file_object->image = $file_name; + $file_object->save(); + } + + } + + + } + private function getProductsFile($file_type = 'uploadFileProducts') { $filename = Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@'. $file_type); if (!is_file($filename)) { diff --git a/console/migrations/m160920_193158_add_isEvent_to_event.php b/console/migrations/m160920_193158_add_isEvent_to_event.php new file mode 100755 index 0000000..8f6cc7e --- /dev/null +++ b/console/migrations/m160920_193158_add_isEvent_to_event.php @@ -0,0 +1,27 @@ +addColumn('event', 'is_event', $this->boolean()); + } + + public function down() + { + $this->dropColumn('event', 'is_event'); + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/console/migrations/m160920_193159_add_isEvent_to_event.php b/console/migrations/m160920_193159_add_isEvent_to_event.php deleted file mode 100755 index 2bdc786..0000000 --- a/console/migrations/m160920_193159_add_isEvent_to_event.php +++ /dev/null @@ -1,27 +0,0 @@ -addColumn('event', 'is_event', $this->boolean()); - } - - public function down() - { - $this->dropColumn('event', 'is_event'); - } - - /* - // Use safeUp/safeDown to run migration code within a transaction - public function safeUp() - { - } - - public function safeDown() - { - } - */ -} diff --git a/frontend/config/bootstrap.php b/frontend/config/bootstrap.php index 6fd199e..dca846e 100755 --- a/frontend/config/bootstrap.php +++ b/frontend/config/bootstrap.php @@ -1 +1,2 @@ 'articles/index', 'blog/-' => 'articles/show', 'event' => 'event/index', - 'event/-' => 'event/show', + 'event/' => 'event/show', ], 'class' => 'common\components\urlManager\LangUrlManager', 'languages' => ['ru', 'ua', 'en'], diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index afe354c..0eb1aed 100755 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -24,6 +24,7 @@ use yii\data\Pagination; use yii\data\Sort; use yii\db\ActiveQuery; use yii\helpers\ArrayHelper; +use yii\helpers\VarDumper; use yii\web\HttpException; class CatalogController extends \yii\web\Controller @@ -117,7 +118,6 @@ class CatalogController extends \yii\web\Controller $groups = $category->getActiveFilters()->all(); $groups = ArrayHelper::index($groups, null, 'name'); - $priceLimits = $productModel->priceLimits($category, $params); /* diff --git a/frontend/controllers/EventController.php b/frontend/controllers/EventController.php index 234d0e4..7a8a07f 100755 --- a/frontend/controllers/EventController.php +++ b/frontend/controllers/EventController.php @@ -17,7 +17,7 @@ class EventController extends Controller { $dataProvider = new ActiveDataProvider([ - 'query' => Event::find() ]); + 'query' => Event::find()->where(['is_event'=>true]) ]); return $this->render('index', [ 'dataProvider' => $dataProvider, @@ -54,7 +54,7 @@ class EventController extends Controller protected function findModel($alias) { - if (($model = Event::findOne(["alias"=>$alias,'is_event' => true])) !== null) { + if (($model = Event::findOne(["alias"=>$alias])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); diff --git a/frontend/controllers/OrderController.php b/frontend/controllers/OrderController.php index ec33e10..7d326aa 100755 --- a/frontend/controllers/OrderController.php +++ b/frontend/controllers/OrderController.php @@ -70,7 +70,10 @@ $modelOrdersProducts->validate(); $modelOrdersProducts->save(); $productV[ $index ] = ArrayHelper::toArray($modelOrdersProducts); - $productV[ $index ][ 'img' ] = \common\components\artboximage\ArtboxImageHelper::getImageSrc($product->image->imageUrl, 'list'); + if(isset($product->image)){ + $productV[ $index ][ 'img' ] = \common\components\artboximage\ArtboxImageHelper::getImageSrc($product->image->imageUrl, 'list'); + } + } } /** diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 73f1c5f..87bd9f9 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -92,5 +92,11 @@ class SiteController extends Controller ]); } + public function actionError(){ + return $this->render('error', [ + 'code'=>'404', +// 'message'=>Yii::$app->errorHandler->exception->getMessage(), + ]); + } } diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php index e2bdaf5..c6035d4 100755 --- a/frontend/views/catalog/product.php +++ b/frontend/views/catalog/product.php @@ -96,7 +96,10 @@ FlipclockAsset::register($this); - variant->price_old ?> грн. + variant->price_old ){?> + variant->price_old ?> грн. + + variant->price ?> грн. @@ -204,7 +207,7 @@ FlipclockAsset::register($this); — Самовывоз Новая Почта - 55 грн.
— Курьер Новая Почта - 88 грн.
— Курьер «ИнТайм» - 60 грн.

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

Киев:
— Курьер - 50 грн. @@ -214,8 +217,19 @@ FlipclockAsset::register($this); бесплатно!
— Пункт Новой Почты - 55 грн. бесплатно! - *

- + * +

+ +

+ Киев:
+ — Курьер - 50 грн + *
+ — Самовывоз - + бесплатно!
+ — Пункт Новой Почты - 55 грн. + * +

+

* Стоимость расчитана для оформляемого заказа

@@ -254,9 +268,15 @@ FlipclockAsset::register($this);
- - + +
+ variant->price_old){?> + + variant->price_old ?> +  грн. + + variant->price ?>  грн. @@ -271,21 +291,20 @@ FlipclockAsset::register($this);
Купить - -
- Оплатить - - - - -
- */ - ?> + +
- +
+
+ Оплатить + + + +
+
+
+ diff --git a/frontend/views/event/_objects.php b/frontend/views/event/_objects.php index c02e301..d2e0f76 100755 --- a/frontend/views/event/_objects.php +++ b/frontend/views/event/_objects.php @@ -9,11 +9,11 @@ FlipclockAsset::register($this);
- name?> + name?>
- + imageUrl, 'event_left', ['align' => 'left'])?> diff --git a/frontend/views/site/error.php b/frontend/views/site/error.php index 69c6a65..d147e7c 100755 --- a/frontend/views/site/error.php +++ b/frontend/views/site/error.php @@ -62,8 +62,8 @@ $this->title = 'Ошибка '.$code; margin-right: 24px; width: 180px; height: 38px; - background: #95ba2f; - border-bottom: 3px solid #799920; + background: #0f6fc7; + border-bottom: 3px solid #075fb0; box-sizing: border-box; text-align: center; text-transform: uppercase; @@ -75,11 +75,11 @@ $this->title = 'Ошибка '.$code; border-radius: 4px; } .button-home-404 a:hover { - border-bottom: 3px solid #95ba2f; + border-bottom: 3px solid #0f6fc7; } .button-home-404 a:active { - background: #799920; - border-bottom: 3px solid #799920; + background: #0f6fc7; + border-bottom: 3px solid #075fb0; } diff --git a/frontend/web/css/css_header.css b/frontend/web/css/css_header.css index ba4dbc8..ad43436 100755 --- a/frontend/web/css/css_header.css +++ b/frontend/web/css/css_header.css @@ -11704,13 +11704,13 @@ a.preview { border-bottom: 1px dashed #0156a9 } -.product_detail .info_table .price_block .buy_button .payment_visa { +.product_detail .info_table .price_block .payment_visa { font: 14px/20px 'roboto', sans-serif; color: #666; margin: 0 0 10px 0 } -.product_detail .info_table .price_block .buy_button .payment_visa .visa { +.product_detail .info_table .price_block .payment_visa .visa { display: inline-block; width: 92px; height: 18px; @@ -11719,11 +11719,11 @@ a.preview { cursor: pointer } -.product_detail .info_table .price_block .buy_button .payment_visa .visa:hover { +.product_detail .info_table .price_block .payment_visa .visa:hover { background-position: 0 -18px } -.product_detail .info_table .price_block .buy_button .payment_visa .webmoney { +.product_detail .info_table .price_block .payment_visa .webmoney { display: inline-block; width: 30px; height: 18px; @@ -11732,7 +11732,7 @@ a.preview { cursor: pointer } -.product_detail .info_table .price_block .buy_button .payment_visa .webmoney:hover { +.product_detail .info_table .price_block .payment_visa .webmoney:hover { background-position: -92px -18px } @@ -14501,7 +14501,6 @@ ul.product-special li.promo div{ .news_item{ display: block; - height: 270px; } .news_item{ margin-bottom: 20px -- libgit2 0.21.4