diff --git a/common/components/artboximage/ArtboxImage.php b/common/components/artboximage/ArtboxImage.php new file mode 100644 index 0000000..244bd62 --- /dev/null +++ b/common/components/artboximage/ArtboxImage.php @@ -0,0 +1,81 @@ + 'jpeg', + 'jpeg' => 'jpeg', + 'png' => 'png', + 'gif' => 'gif', + 'bmp' => 'bmp', + ]; + + public $uploadUrl = '/admin/artboxfile/action/upload'; + + public function load($file = null, $driver = null) { + if(empty($file) || !realpath($file)) { + throw new ErrorException('File name can not be empty and exists'); + } + return Image::factory($file, $driver ? $driver : $this->driver); + } + + public function fileinputWidget($model, $modelField, $formField = 'fileUpload', $multiple = false, $imageOnly = true) { + $options = [ + 'multiple' => $multiple, + ]; + if ($imageOnly) { + $options['accept'] = 'image/*'; + } + return FileInput::widget([ + 'name' => $formField, + 'options' => $options, + 'pluginOptions' => [ + 'allowedFileExtensions' => array_keys($this->extensions), + // @todo set for multiple + 'initialPreview' => $model->{$modelField} ? Html::img($model->{$modelField}) : '', + 'overwriteInitial' => !$multiple, + 'showRemove' => true, + 'showUpload' => false, + 'uploadUrl' => $this->uploadUrl, + 'uploadExtraData' => [ + 'fileField' => $modelField, + 'multiple' => intval($multiple), + ], + ], + 'pluginEvents' => [ + "change" => "function() { console.log('change'); }", + "open" => "function() { console.log('open'); }", + "save" => "function() { console.log('save'); }", + "upload" => "function() { console.log('upload'); }", + "uploaded" => "function() { console.log('uploaded'); }", + "filepreupload" => "function() { console.log('filepreupload'); }", + "fileuploaded" => "function(event, files, extra) { console.log(event, files, extra); }", + "fileuploaderror" => "function() { console.log('fileuploaderror'); }", + "filebatchuploaderror" => "function() { console.log('filebatchuploaderror'); }", + "filebatchuploadsuccess" => "function() { console.log('filebatchuploadsuccess'); }", + "filebatchuploadcomplete" => "function() { console.log('filebatchuploadcomplete'); }", + 'filebatchuploadsuccess' => "function(event, files, extra) { + console.log(event, files, extra); + }", + ], + ]); + } +} \ No newline at end of file diff --git a/common/components/artboximage/ArtboxImageHelper.php b/common/components/artboximage/ArtboxImageHelper.php new file mode 100644 index 0000000..fada295 --- /dev/null +++ b/common/components/artboximage/ArtboxImageHelper.php @@ -0,0 +1,138 @@ +artboximage; + } + return self::$imageDriver; + } + + public function getPreset($preset) { + if (empty(self::$presets)) { + self::$presets = self::getDriver()->presets; + } + return empty(self::$presets[$preset]) ? null : self::$presets[$preset]; + } + + public static function getImage($file, $preset, $imgOptions = []) { + return Html::img(self::getImageSrc($file, $preset), $imgOptions); + } + + public static function getImageSrc($file, $preset, $preset_alias = null) { + if (is_string($preset)) { + $preset_alias = $preset; + $preset = self::getPreset($preset); + } + if (empty($preset) || empty($preset_alias)) { + return $file; + } + $filePath = self::getPathFromUrl($file); + if (!file_exists($filePath) || !preg_match('#^(.*)\.(' . self::getExtensionsRegexp() . ')$#', $file, $matches)) { + return $file; + } + return self::getPresetUrl($filePath, $preset, $preset_alias); + } + + public static function fileinputWidget($model, $modelField, $formField = 'fileUpload', $multiple = false) { + return Yii::$app->artboximage->fileinputWidget($model, $modelField, $formField, $multiple); + } + + private static function getPathFromUrl($url) { + return substr_replace($url, self::getDriver()->rootPath, 0, strlen(self::getDriver()->rootUrl)); + } + + private static function getUrlFromPath($path) { + return substr_replace($path, self::getDriver()->rootUrl, 0, strlen(self::getDriver()->rootPath)); + } + + private static function getPresetUrl($filePath, $preset, $preset_alias) { + $pathinfo = pathinfo($filePath); + $presetPath = $pathinfo['dirname'] .'/styles/'. strtolower($preset_alias); + $presetFilePath = $presetPath .'/'. $pathinfo['basename']; + $presetUrl = self::getUrlFromPath($presetFilePath); + if (file_exists($presetFilePath)) { + return $presetUrl; + } + if (!file_exists($presetPath)) { + @mkdir($presetPath, 0777, true); + } + $output = self::createPresetImage($filePath, $preset, $preset_alias); + if ( !empty($output) ) { + $f = fopen($presetFilePath, 'w'); + fwrite($f, $output); + fclose($f); + return $presetUrl; + } + return false; + } + + private static function createPresetImage($filePath, $preset, $preset_alias) + { + $image = self::getDriver()->load($filePath); + foreach ($preset as $action => $data) { + switch($action) { + case 'resize': + $image->resize($data['width'], $data['height'], @$data['master']); + break; + case 'flip': + $image->flip(@$data['direction']); + break; + default: + break; + } + } + return $image->render(); + } + + /** + * Get extensions regexp + * @return string regexp + */ + private function getExtensionsRegexp() + { + $keys = array_keys(self::getDriver()->extensions); + return '(?i)' . join('|', $keys); + } + + /** + * Get size from suffix + * @param string $suffix + * @return string size + */ + private function getSizeFromSuffix($suffix) + { + return array_search($suffix, $this->getSizeSuffixes()); + } + + /** + * Get suffix from size + * @param string $size + * @return string suffix + */ + private function getSufixFromSize($size) + { + return ArrayHelper::getValue($this->getSizeSuffixes(), $size); + } + + private function getSizeSuffixes() + { + $suffixes = []; + foreach ($this->sizes as $size => $sizeConf) { + $suffixes[$size] = ArrayHelper::getValue($this->sizeSuffixes, $size, $this->defaultSizeSuffix . $size); + } + return $suffixes; + } +} \ No newline at end of file diff --git a/common/config/main.php b/common/config/main.php index 4dcc728..b97e37a 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -63,6 +63,66 @@ return [ ], ], ], + 'artboximage' => [ + 'class' => 'common\components\artboximage\ArtboxImage', + 'driver' => 'GD', //GD or Imagick + 'rootPath' => Yii::getAlias('@storage'), + 'rootUrl' => Yii::getAlias('/storage'), + 'presets' => [ + 'product' => [ + 'resize' => [ + 'width' => 300, + 'height' => 300, + 'master' => null + ], + /*'flip' => [ + 'direction' => \common\components\artboximage\drivers\Image::HORIZONTAL + ]*/ + ], + 'brandlist' => [ + 'resize' => [ + 'width' => 138, + 'height' => 78, + 'master' => null + ], + ], + 'product_trumb' => [ + 'resize' => [ + 'width' => 80, + 'height' => 80, + 'master' => null + ], + ], + 'product_list' => [ + 'resize' => [ + 'width' => 130, + 'height' => 70, + 'master' => null + ], + ], + 'product_list2' => [ + 'resize' => [ + 'width' => 130, + 'height' => 70, + 'master' => null + ], + ], + 'mainmenu' => [ + 'resize' => [ + 'width' => 160, + 'height' => 170, + 'master' => null + ], + ], + 'large' => [ + 'resize' => [ + 'width' => 600, + 'height' => 600, + 'master' => null + ], + ], + ] + ], ], 'modules' => [ diff --git a/common/modules/artboxfile/Module.php b/common/modules/artboxfile/Module.php new file mode 100644 index 0000000..72360d2 --- /dev/null +++ b/common/modules/artboxfile/Module.php @@ -0,0 +1,24 @@ +request->post(); + + $multiple = !empty($request['multiple']); + $fileField = empty($request['fileField']) ? 'file' : $request['fileField']; + $formField = empty($request['formField']) ? 'fileUpload' : $request['formField']; + + + if($_FILES[$formField]) + { + if (($_FILES[$formField] == "none") OR (empty($_FILES[$formField]['name'])) ) + { + $error = "Вы не выбрали файл"; + } + else if ($_FILES[$formField]["size"] == 0 OR $_FILES[$formField]["size"] > 2050000) + { + $error = "Размер файла не соответствует нормам"; + } + /*else if (($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/png") AND ($_FILES['upload']['type'] != 'image/gif')) + { + $message = "Допускается загрузка только картинок JPG, GIF и PNG."; + }*/ + else if (!is_uploaded_file($_FILES[$formField]["tmp_name"])) + { + $error = "Что-то пошло не так. Попытайтесь загрузить файл ещё раз."; + } + else{ + $ext = $this->getex($_FILES[$formField]['name']); + $name = $_FILES[$formField]['name'] .'.'. $ext; + $tmpName = uniqid('tmpfile_') .'.'. $ext; + + $path = Yii::getAlias($this->tmpDir); + if(!is_dir($path)) { + mkdir($path, 0755, true); + } + + if (!move_uploaded_file($_FILES[$formField]['tmp_name'], $path .'/'. $tmpName)) { + $error = "File not uploaded"; + } else { + $full_path = $path .'/'. $tmpName; + $message = "Файл " . $_FILES[$formField]['name'] . " in $full_path загружен"; + } + } + } + if (!empty($error)) { + print json_encode(['error' => $error]); + } else { + $sendingData = [ + 'append' => $multiple, +// 'initialPreview' => Html::img() +// 'initialPreviewConfig' => , +// 'initialPreviewThumbTags' => , + + ]; + print json_encode(['message' => $message, 'tmpfile' => $full_path, 'filename' => $name]); + } + exit; + } + + protected function getex($filename) { + return end(explode(".", $filename)); + } +} \ No newline at end of file diff --git a/common/modules/artboxfile/models/File.php b/common/modules/artboxfile/models/File.php new file mode 100644 index 0000000..f5c4188 --- /dev/null +++ b/common/modules/artboxfile/models/File.php @@ -0,0 +1,34 @@ + 255], + [[$this->fileUploadName], 'safe'], + [[$this->fileUploadName], 'file', 'extensions' => 'jpg, gif, png'], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'file' => Yii::t('artbox', 'File name'), + 'fileUpload' => Yii::t('artbox', 'File'), + ]; + } +} \ No newline at end of file diff --git a/frontend/config/main.php b/frontend/config/main.php index 0485891..59afe50 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -42,14 +42,17 @@ return [ 'class' => 'iutbay\yii2imagecache\ImageCache', 'sourcePath' => '@app/web/images', 'sourceUrl' => '@web/images', + 'thumbsPath' => '@app/web/thumbs', + 'thumbsUrl' => '@web/thumbs', + 'resizeMode' => 'inset', 'sizes' => [ 'brandlist' => [128, 128], 'product' => [300, 300], 'product_trumb' => [80, 80], 'product_trumb2' => [100, 100], - 'product_list' => [130, 70], + 'list' => [134, 200], 'product_list2' => [130, 70], - 'product_variant' => [40, 40], + 'product_variant' => [42, 42], 'mainmenu' => [160, 170], 'large' => [600, 600], ], @@ -99,6 +102,8 @@ return [ 'admin/catalog' => 'admin/catalog/index', 'admin/catalog/save' => 'admin/catalog/save', 'admin/catalog/delete' => 'admin/catalog/delete', + + 'thumbs/' => 'site/thumb', ], 'class' => 'common\components\urlManager\LangUrlManager', 'languages' => ['ru', 'ua', 'en'], diff --git a/frontend/models/ProductFrontendSearch.php b/frontend/models/ProductFrontendSearch.php index 42b9c05..af06749 100755 --- a/frontend/models/ProductFrontendSearch.php +++ b/frontend/models/ProductFrontendSearch.php @@ -53,7 +53,7 @@ class ProductFrontendSearch extends Product { } // $query->joinWith('variant'); $query->joinWith('brand'); - $query->joinWith('image'); +// $query->joinWith('image'); $query->joinWith('categories'); $dataProvider = new ActiveDataProvider([ diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php index d87bfce..7bb8053 100644 --- a/frontend/views/catalog/product.php +++ b/frontend/views/catalog/product.php @@ -92,8 +92,6 @@ $this->registerJs ("
- -

name ?>

Цветовые решения
@@ -135,7 +133,6 @@ $this->registerJs (" сравнение
-
@@ -158,8 +155,6 @@ $this->registerJs ("
- -
imageCache->thumb($product->image->imageUrl, 'product')?> @@ -167,14 +162,11 @@ $this->registerJs ("
- -
\ No newline at end of file diff --git a/frontend/views/catalog/product.tmp.php b/frontend/views/catalog/product.tmp.php new file mode 100644 index 0000000..2b0ced3 --- /dev/null +++ b/frontend/views/catalog/product.tmp.php @@ -0,0 +1,247 @@ +title = $product->name; +foreach($product->category->getParents()->all() as $parent) { + $this->params['breadcrumbs'][] = ['label' => $parent->categoryName->value, 'url' => ['catalog/category', 'category' => $parent]]; +} +$this->params['breadcrumbs'][] = ['label' => $product->category->categoryName->value, 'url' => ['catalog/category', 'category' => $product->category]]; +$this->params['breadcrumbs'][] = $product->name .' #'. $product->variant->sku; +?> +

name .' '. $product->variant->name?>

+ +
+
+
+ image)) :?> + <?= $product->name?> + + <?= $product->image->alt ? $product->image->alt : $product->name?> + + + +
+ + images)) :?> +
+ images as $image) :?> +
+ <?= $image->alt ? $image->alt : $product->name?> +
+ + + + +
+ + +
+ + +
+
+ Код: variant->sku?> + stock !== 0 && $product->variant->price > 0 ? ' есть в наличии' : ' нет в наличии'?> +
+ +
+
+ variant->price > 0) :?> +
+ variant->price?> +
+
грн.
+ +
+ + +
+ +
+
+
+
-
+
+
+
+ + + + +
+
+
+ БЫСТРЫЙ ЗАКАЗ + + +
+
+ +
+

+ Доставка товара на следующий день после выставления счета. Мы доставим “День в
день” — уточните это у менеджера. +

+ Подробно о доставке +
+ +
+ +
+ +

Характеристики

+
    + +
  • +
    +
    name?>
    +
    + _options as $option) :?> ValueRenderHTML?> +
    +
    +
  • + +
+ + + + +
+
+ +

С этим товаром покупают

+ +
+ +
+
АКЦИЯ
+
Toп
+
+
Штукатурка гипсовая Кнауф Ротбанд 30 кг белая
+
Бренд: Knauf
+
Штукатурки
+
102.05 грн.
+ + добавить к сравнению + +
+ +
+
АКЦИЯ
+
Toп
+
+
Штукатурка гипсовая Кнауф Ротбанд 30 кг белая
+
Бренд: Knauf
+
Штукатурки
+
102.05 грн.
+ + добавить к сравнению + +
+ +
+
АКЦИЯ
+
Toп
+
+
Штукатурка гипсовая Кнауф Ротбанд 30 кг белая
+
Бренд: Knauf
+
Штукатурки
+
102.05 грн.
+ + добавить к сравнению + +
+ +
+
АКЦИЯ
+
Toп
+
+
Штукатурка гипсовая Кнауф Ротбанд 30 кг белая
+
Бренд: Knauf
+
Штукатурки
+
102.05 грн.
+ + добавить к сравнению + +
+ +
+
+
+
    + +
  • Характеристики
  • + + description)) :?> +
  • Описание
  • + + video)) :?> +
  • Видео
  • + + +
+
+ +
+
    + +
  • +
    +
    name?>
    +
    + _options as $option) :?> ValueRenderHTML?> +
    +
    +
  • + +
+
+ + + description)) :?> +
+ description?> +
+ + video)) :?> +
+ video?> +
+ + +
+
+
+ +
+
+ + +
+
+

Вы недавно просматривали

+
+ + + +
+
+ + +
diff --git a/frontend/views/catalog/product_item.php b/frontend/views/catalog/product_item.php index d24518e..de19184 100644 --- a/frontend/views/catalog/product_item.php +++ b/frontend/views/catalog/product_item.php @@ -2,7 +2,7 @@ /** @var \common\modules\product\models\Product $product */ use yii\helpers\Url; ?> -
  • variant) ? ' style="opacity: 0.5"' : '')?>> +
  • @@ -52,7 +52,7 @@ use yii\helpers\Url; 'catalog/product', 'product' => $product, '#' => 'm' . $variant->product_variant_id]) ?>"> - imageCache->thumb($variant->image->imageUrl, 'product_list')?> + imageCache->thumb($variant->image->imageUrl, 'product_variant')?>
  • diff --git a/frontend/views/catalog/products.php b/frontend/views/catalog/products.php index 86a5f93..39cc79d 100644 --- a/frontend/views/catalog/products.php +++ b/frontend/views/catalog/products.php @@ -6,6 +6,7 @@ use yii\helpers\Url; use yii\widgets\Breadcrumbs; +use yii\web\View; use common\modules\product\helpers\ProductHelper; $this->title = $category->categoryName->value; @@ -19,35 +20,12 @@ $this->params['seo']['h1'] = 'TEST H1'; $this->params['seo']['description'] = 'TEST DESCRIPTION'; $this->params['seo']['fields']['name'] = 'TEST NAME FROM FIELD'; $this->params['seo']['key']= 'product_list'; + +$this->registerCssFile (Yii::$app->request->BaseUrl . '/css/begunok.css'); +$this->registerJsFile (Yii::$app->request->baseUrl . '/js/jquery.ui-slider.js', ['position' => View::POS_HEAD, 'depends' => ['yii\web\JqueryAsset']]); +$this->registerJsFile (Yii::$app->request->baseUrl . '/js/begunok.js', ['position' => View::POS_HEAD, 'depends' => ['yii\web\JqueryAsset']]); ?> - +