From ccc7a9d3dfbff0e810c213d72495c55bb116b44a Mon Sep 17 00:00:00 2001 From: Karnovsky A Date: Thu, 12 May 2016 08:26:36 +0300 Subject: [PATCH] Karnovsky 12052016 --- .htaccess | 4 +++- backend/config/bootstrap.php | 2 +- backend/views/category/_form.php | 13 ------------- backend/views/layouts/main-sidebar.php | 6 ++++-- common/modules/product/CatalogUrlManager.php | 10 ++++++++++ common/modules/product/controllers/ManageController.php | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- common/modules/product/controllers/ProductUnitController.php | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/product/models/Brand.php | 18 +++++++++++++++++- common/modules/product/models/BrandSearch.php | 25 ++++++++++++++++++------- common/modules/product/models/Category.php | 29 ++++++++++++++++++++++------- common/modules/product/models/Product.php | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------- common/modules/product/models/ProductImage.php | 44 ++++++++++++++++++++++++++++++-------------- common/modules/product/models/ProductSearch.php | 22 ++++++++++++++++++++-- common/modules/product/models/ProductUnitSearch.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/product/models/ProductVariant.php | 45 ++++++++++++++++++++++++++++++++------------- common/modules/product/models/RemoteCategories.php | 63 --------------------------------------------------------------- common/modules/product/models/RemoteCategoriesSearch.php | 71 ----------------------------------------------------------------------- common/modules/product/models/RemoteProducts.php | 77 ----------------------------------------------------------------------------- common/modules/product/models/RemoteProductsSearch.php | 77 ----------------------------------------------------------------------------- common/modules/product/views/manage/_form.php | 38 +++++++++++++++++++++++++------------- common/modules/product/views/manage/index.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- common/modules/product/views/manage/view.php | 1 + common/modules/product/views/product-unit/_form.php | 27 +++++++++++++++++++++++++++ common/modules/product/views/product-unit/_search.php | 33 +++++++++++++++++++++++++++++++++ common/modules/product/views/product-unit/create.php | 21 +++++++++++++++++++++ common/modules/product/views/product-unit/index.php | 34 ++++++++++++++++++++++++++++++++++ common/modules/product/views/product-unit/update.php | 23 +++++++++++++++++++++++ common/modules/product/views/product-unit/view.php | 38 ++++++++++++++++++++++++++++++++++++++ common/modules/product/widgets/views/brandsCarousel.php | 2 +- common/modules/product/widgets/views/submenu.php | 4 ++-- common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php | 2 +- common/modules/rubrication/models/TaxGroup.php | 4 ++-- common/modules/rubrication/models/TaxValueString.php | 2 +- common/modules/rubrication/views/tax-group/_form.php | 4 ++-- common/translation/ru/product.php | 2 +- console/config/bootstrap.php | 2 +- console/controllers/ImportController.php | 405 +++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- frontend/config/main.php | 37 ++++++++++++++++++++++++++++++------- frontend/controllers/CatalogController.php | 11 +++-------- frontend/controllers/SiteController.php | 12 +++++++++++- frontend/models/ProductFrontendSearch.php | 4 ++-- frontend/views/catalog/product.php | 370 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- frontend/views/catalog/product_item.php | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- frontend/views/catalog/products.php | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- frontend/views/layouts/main.php | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------ frontend/web/img/no_photo.png | Bin 0 -> 23954 bytes frontend/web/img/no_photo_big.png | Bin 0 -> 9430 bytes 47 files changed, 1247 insertions(+), 1340 deletions(-) create mode 100644 common/modules/product/controllers/ProductUnitController.php create mode 100644 common/modules/product/models/ProductUnitSearch.php delete mode 100755 common/modules/product/models/RemoteCategories.php delete mode 100755 common/modules/product/models/RemoteCategoriesSearch.php delete mode 100755 common/modules/product/models/RemoteProducts.php delete mode 100755 common/modules/product/models/RemoteProductsSearch.php create mode 100644 common/modules/product/views/product-unit/_form.php create mode 100644 common/modules/product/views/product-unit/_search.php create mode 100644 common/modules/product/views/product-unit/create.php create mode 100644 common/modules/product/views/product-unit/index.php create mode 100644 common/modules/product/views/product-unit/update.php create mode 100644 common/modules/product/views/product-unit/view.php create mode 100644 frontend/web/img/no_photo.png create mode 100644 frontend/web/img/no_photo_big.png diff --git a/.htaccess b/.htaccess index 809fad7..2984f4b 100644 --- a/.htaccess +++ b/.htaccess @@ -55,10 +55,12 @@ AddDefaultCharset utf-8 RewriteRule ^img/(.*)$ frontend/web/img/$1 [L] + RewriteRule ^files/(.*)$ frontend/web/files/$1 [L] + RewriteRule ^fonts/(.*)$ frontend/web/fonts/$1 [L] - RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js|images|img|fonts)/ + RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js|images|fonts|img|files)/ RewriteCond %{REQUEST_URI} !index.php diff --git a/backend/config/bootstrap.php b/backend/config/bootstrap.php index e446754..7e6294e 100755 --- a/backend/config/bootstrap.php +++ b/backend/config/bootstrap.php @@ -2,4 +2,4 @@ Yii::setAlias('@uploadDir', dirname(dirname(__DIR__)) . '/storage/sync'); Yii::setAlias('@uploadFileProducts', 'products.csv'); -Yii::setAlias('@productsDir', dirname(dirname(__DIR__)) . '/storage/products'); \ No newline at end of file +Yii::setAlias('@productsDir', 'images/products'); \ No newline at end of file diff --git a/backend/views/category/_form.php b/backend/views/category/_form.php index 55c750a..5aae4de 100755 --- a/backend/views/category/_form.php +++ b/backend/views/category/_form.php @@ -68,19 +68,6 @@ use kartik\select2\Select2; field($model, 'seo_text')->textarea(['rows' => 6]) ?> - field($model, 'remote_category')->widget(Select2::className(), [ - 'data' => \yii\helpers\ArrayHelper::map(\common\modules\product\models\RemoteCategories::find()->all(), 'ID', 'Name'), - 'language' => 'ru', - 'options' => [ - 'placeholder' => 'Select a remote category', - 'multiple' => true, - ], - 'pluginOptions' => [ - 'allowClear' => true - ], - ] - ) ?> - depth == 2) :?> field($model, 'populary')->checkbox() ?> diff --git a/backend/views/layouts/main-sidebar.php b/backend/views/layouts/main-sidebar.php index 1e6cc3a..f132d1b 100755 --- a/backend/views/layouts/main-sidebar.php +++ b/backend/views/layouts/main-sidebar.php @@ -25,14 +25,16 @@ use yii\widgets\Menu; ['label' => 'MAIN NAVIGATION', 'options'=>['class'=>'header']], ['label' => 'Заказы', 'url' => ['/orders/index'], 'template'=>' {label}'], [ - 'label' => 'Products', + 'label' => 'eCommerce', 'template'=>' {label}', 'url' => ['/product/manage'], 'items' => [ ['label' => 'Товары', 'url' => ['/product/manage']], - ['label' => 'Импорт товаров', 'url' => ['/product/manage/import']], ['label' => 'Категории', 'url' => ['/category']], ['label' => 'Бренды', 'url' => ['/brand']], + ['label' => 'Характеристики', 'url' => ['/rubrication/tax-group']], + ['label' => 'Единицы измерения', 'url' => ['/product/product-unit']], + ['label' => 'Статистика импорта', 'url' => ['/product/manage/import-stat']], ] ], [ diff --git a/common/modules/product/CatalogUrlManager.php b/common/modules/product/CatalogUrlManager.php index 9e26006..ff3967d 100755 --- a/common/modules/product/CatalogUrlManager.php +++ b/common/modules/product/CatalogUrlManager.php @@ -111,6 +111,7 @@ class CatalogUrlManager implements UrlRuleInterface { $params['word'] = [$params['word']]; } $url .= 'word:'. implode(';', $params['word']); + unset($params['word']); } $filter = []; @@ -147,6 +148,10 @@ class CatalogUrlManager implements UrlRuleInterface { $url .= 'filter:'. implode(';', $filter); } + if (!empty($params) && ($query = http_build_query($params)) !== '') { + $url .= '?' . $query; + } + return $url; break; @@ -155,6 +160,11 @@ class CatalogUrlManager implements UrlRuleInterface { $product_alias = is_object($params['product']) ? $params['product']->alias : strtolower($params['product']); } $url = 'product/'. $product_alias; + + if (!empty($params) && ($query = http_build_query($params)) !== '') { + $url .= '?' . $query; + } + return $url; break; } diff --git a/common/modules/product/controllers/ManageController.php b/common/modules/product/controllers/ManageController.php index ad70fa5..6f37b7d 100755 --- a/common/modules/product/controllers/ManageController.php +++ b/common/modules/product/controllers/ManageController.php @@ -4,6 +4,7 @@ namespace common\modules\product\controllers; use common\modules\product\helpers\ProductHelper; use common\modules\product\models\Category; +use common\modules\product\models\ProductImage; use common\modules\product\models\ProductVariant; use common\modules\product\models\RemoteProductsSearch; use Yii; @@ -12,6 +13,10 @@ use common\modules\product\models\ProductSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; +use common\modules\product\models\Brand; +use common\modules\product\models\BrandName; +use common\modules\product\models\RemoteProducts; +use yii\web\UploadedFile; /** * ManageController implements the CRUD actions for Product model. @@ -119,8 +124,25 @@ class ManageController extends Controller { $model = new Product(); - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->product_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 { return $this->render('create', [ 'model' => $model, @@ -138,8 +160,25 @@ class ManageController extends Controller { $model = $this->findModel($id); - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->product_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 { $groups = $model->category->getTaxGroups(); @@ -163,6 +202,18 @@ class ManageController extends Controller return $this->redirect(['index']); } + public function actionDelimg($id) + { + $image = ProductImage::findOne($id); + + if ($image) { + $image->delete(); + } + + print '1'; + exit; + } + public function actionImport() { $searchModel = new RemoteProductsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); @@ -173,6 +224,47 @@ class ManageController extends Controller ]); } + public function actionImportStat() { + $all_products = $new_products = $linked_products = $orpahed_products = 0; + $remoteProducts = RemoteProducts::find()->all(); + + $not_linked_cats = []; + + foreach($remoteProducts as $product) { + if (!empty($product->product->product_id)) { + $linked_products++; + } elseif (!empty($product->remoteCategory) && !empty($product->remoteCategory->category) && !empty($product->remoteCategory->category->category_id)) { + $new_products++; + } else { + if (!empty($product->remoteCategory)) { + if (empty($not_linked_cats[$product->remoteCategory->ID])) { + $not_linked_cats[$product->remoteCategory->ID] = $product->remoteCategory->Name ." (". $product->remoteCategory->ID .")"; + } + } + $orpahed_products++; + } + $all_products++; + } + + $op = []; + + $op[] = "Всего $all_products товаров, $new_products новых и $linked_products уже связанных."; + if (!empty($not_linked_cats)) { + $op[] = "$orpahed_products товаров не привязаны к категориям:"; + foreach ($not_linked_cats as $not_linked_cat) { + $op[] = "$not_linked_cat"; + } + } + + return $this->render('import-stat', [ + 'all_products' => $all_products, + 'new_products' => $new_products, + 'linked_products' => $linked_products, + 'orpahed_products' => $orpahed_products, + 'not_linked_cats' => $not_linked_cats, + ]); + } + /** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/common/modules/product/controllers/ProductUnitController.php b/common/modules/product/controllers/ProductUnitController.php new file mode 100644 index 0000000..7ee6139 --- /dev/null +++ b/common/modules/product/controllers/ProductUnitController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all ProductUnit models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ProductUnitSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single ProductUnit model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new ProductUnit model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new ProductUnit(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->product_unit_id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing ProductUnit model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->product_unit_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing ProductUnit model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the ProductUnit model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return ProductUnit the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = ProductUnit::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/common/modules/product/models/Brand.php b/common/modules/product/models/Brand.php index 79cb1e4..11d83fa 100755 --- a/common/modules/product/models/Brand.php +++ b/common/modules/product/models/Brand.php @@ -10,6 +10,7 @@ use Yii; * This is the model class for table "brand". * * @property integer $brand_id + * @property string $remote_id * @property integer $brand_name_id * @property string $alias * @property string $image @@ -24,6 +25,8 @@ use Yii; */ class Brand extends \yii\db\ActiveRecord { + public $imageUpload; + public function behaviors() { return [ @@ -39,7 +42,7 @@ class Brand extends \yii\db\ActiveRecord 'valueKeyName' => 'value', 'slugKeyName' => 'alias', 'translit' => true - ] + ], ], ]; } @@ -64,6 +67,9 @@ class Brand extends \yii\db\ActiveRecord [['alias', 'name'], 'string', 'max' => 250], [['image', 'meta_title'], 'string', 'max' => 255], [['meta_robots'], 'string', 'max' => 50], + [['remote_id'], 'string', 'max' => 25], + [['imageUpload'], 'safe'], + [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], // [['brand_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => BrandName::className(), 'targetAttribute' => ['brand_name_id' => 'brand_name_id']], ]; } @@ -79,10 +85,12 @@ class Brand extends \yii\db\ActiveRecord 'brand_name_id' => Yii::t('product', 'Brand Name ID'), 'alias' => Yii::t('product', 'Alias'), 'image' => Yii::t('product', 'Image'), + 'imageUrl' => Yii::t('product', 'Image'), 'meta_title' => Yii::t('product', 'Meta Title'), 'meta_desc' => Yii::t('product', 'Meta Desc'), 'meta_robots' => Yii::t('product', 'Meta Robots'), 'seo_text' => Yii::t('product', 'Seo Text'), + 'remote_id' => Yii::t('product', '1C brand name'), ]; } @@ -113,4 +121,12 @@ class Brand extends \yii\db\ActiveRecord public function getName() { return empty($this->brand_name_id) ? null : $this->brandName->value; } + + public function getImageFile() { + return empty($this->image) ? null : '/images/brand/'. $this->image; + } + + public function getImageUrl() { + return empty($this->image) ? null : '/images/brand/'. $this->image; + } } diff --git a/common/modules/product/models/BrandSearch.php b/common/modules/product/models/BrandSearch.php index 31cbb24..45041d4 100755 --- a/common/modules/product/models/BrandSearch.php +++ b/common/modules/product/models/BrandSearch.php @@ -12,6 +12,7 @@ use common\modules\product\models\Brand; */ class BrandSearch extends Brand { + public $brand_name; /** * @inheritdoc */ @@ -19,7 +20,7 @@ class BrandSearch extends Brand { return [ [['brand_id', 'brand_name_id'], 'integer'], - [['alias', 'image', 'meta_title', 'meta_desc', 'meta_robots', 'seo_text'], 'safe'], + [['alias', 'image', 'meta_title', 'meta_desc', 'meta_robots', 'seo_text', 'brand_name'], 'safe'], ]; } @@ -57,18 +58,28 @@ class BrandSearch extends Brand return $dataProvider; }*/ + $dataProvider->setSort([ + 'attributes' => [ + 'brand_name', + 'alias' + ] + ]); + // grid filtering conditions $query->andFilterWhere([ 'brand_id' => $this->brand_id, 'brand_name_id' => $this->brand_name_id, ]); - $query->andFilterWhere(['like', 'alias', $this->alias]) - ->andFilterWhere(['like', 'image', $this->image]) - ->andFilterWhere(['like', 'meta_title', $this->meta_title]) - ->andFilterWhere(['like', 'meta_desc', $this->meta_desc]) - ->andFilterWhere(['like', 'meta_robots', $this->meta_robots]) - ->andFilterWhere(['like', 'seo_text', $this->seo_text]); + $query->joinWith('brandName'); + + $query->andFilterWhere(['ilike', 'alias', $this->alias]) + ->andFilterWhere(['ilike', 'image', $this->image]) + ->andFilterWhere(['ilike', 'meta_title', $this->meta_title]) + ->andFilterWhere(['ilike', 'meta_desc', $this->meta_desc]) + ->andFilterWhere(['ilike', 'meta_robots', $this->meta_robots]) + ->andFilterWhere(['ilike', 'seo_text', $this->seo_text]) + ->andFilterWhere(['ilike', 'brand_name.value', $this->brand_name]); return $dataProvider; } diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index 0cb4b3f..144fee4 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -34,6 +34,8 @@ use Yii; */ class Category extends \yii\db\ActiveRecord { + public $imageUpload; + public function behaviors() { return [ @@ -89,7 +91,8 @@ class Category extends \yii\db\ActiveRecord [['populary'], 'boolean'], [['group_to_category', 'remote_category'], 'safe'], [['category_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryName::className(), 'targetAttribute' => ['category_name_id' => 'category_name_id']], - // [['image'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif'], + [['imageUpload'], 'safe'], + [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], // [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']], ]; } @@ -105,6 +108,7 @@ class Category extends \yii\db\ActiveRecord 'path' => Yii::t('product', 'Path'), 'depth' => Yii::t('product', 'Depth'), 'image' => Yii::t('product', 'Image'), + 'imageUrl' => Yii::t('product', 'Image'), 'meta_title' => Yii::t('product', 'Meta Title'), 'meta_desc' => Yii::t('product', 'Meta Desc'), 'meta_robots' => Yii::t('product', 'Meta Robots'), @@ -117,7 +121,8 @@ class Category extends \yii\db\ActiveRecord ]; } - public static function find() { + public static function find() + { return new CategoryQuery(get_called_class()); } @@ -145,28 +150,38 @@ class Category extends \yii\db\ActiveRecord return $this->hasMany(ProductCategory::className(), ['category_id' => 'category_id']); } - public function getTaxGroups() { + public function getTaxGroups() + { return $this->getRelations('tax_group_to_category'); } - public function getRemote_category() { + public function getRemote_category() + { return ArtboxTreeHelper::getArrayField($this->remote_id); } - public function setRemote_category($value) { + public function setRemote_category($value) + { if (!empty($value) && is_array($value)) { $this->remote_id = ArtboxTreeHelper::setArrayField($value, false); } } - public function getCategoryName() { + public function getCategoryName() + { return $this->hasOne(CategoryName::className(), ['category_name_id' => 'category_name_id']); } - public function getName() { + public function getName() + { return empty($this->categoryName) ? null : $this->categoryName->value; } + public function getImageUrl() + { + return empty($this->image) ? null : '/images/category/' . $this->image; + } + public function beforeSave($insert) { if (parent::beforeSave($insert)) { diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index ba99ca2..3e3b7ad 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -7,23 +7,23 @@ use common\modules\rubrication\models\TaxOption; use Yii; use common\modules\relation\relationBehavior; use yii\db\ActiveQuery; +use yii\helpers\Html; +use yii\web\UploadedFile; /** * This is the model class for table "{{%product}}". * - * @property integer $product_id * @property string $name - * @property string $alias - * @property string $video - * @property string $description * @property integer $brand_id - * @property Brand $brand + * @property integer $product_id * @property Category $category * @property array $categories + * @property array of ProductVariant $variants * @property ProductVariant $variant - * @property array $variants * @property ProductImage $image * @property array $images + * @property boolean $is_top + * @property boolean $is_new */ class Product extends \yii\db\ActiveRecord { @@ -71,9 +71,10 @@ class Product extends \yii\db\ActiveRecord [['brand_id'], 'integer'], [['name'], 'string', 'max' => 150], [['alias'], 'string', 'max' => 250], - [['categories', 'variants', 'options'], 'safe'], -// [['imagesUpload'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif'], + [['categories', 'variants', 'options', 'imagesUpload'], 'safe'], + [['imagesUpload'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif', 'maxFiles' => 50], [['description', 'video'], 'safe'], + [['is_top', 'is_new'], 'boolean'], // [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], ]; } @@ -91,6 +92,11 @@ class Product extends \yii\db\ActiveRecord 'category' => Yii::t('product', 'Category'), // relation behavior field 'image' => Yii::t('product', 'Image'), 'images' => Yii::t('product', 'Images'), + 'description' => Yii::t('product', 'Description'), + 'video' => Yii::t('product', 'Video embeded'), + 'variants' => Yii::t('product', 'Variants'), + 'is_top' => Yii::t('product', 'Is top'), + 'is_new' => Yii::t('product', 'Is new'), ]; } @@ -118,10 +124,6 @@ class Product extends \yii\db\ActiveRecord return $this->hasMany(ProductImage::className(), ['product_id' => 'product_id']); } - public function setImages($images) { - $this->_images = $images; - } - /** * @return \yii\db\ActiveQuery */ @@ -151,7 +153,8 @@ class Product extends \yii\db\ActiveRecord } public function getCategories() { - return $this->getRelations('product_categories'); + return $this->hasMany(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); +// return $this->getRelations('product_categories'); } public function getCategoriesNames() { @@ -163,12 +166,7 @@ class Product extends \yii\db\ActiveRecord } public function getCategory() { - /** @var ActiveQuery $categories */ - $categories = $this->getRelations('product_categories'); - $count = $categories->count(); - if ($count == 0) - return; - return $categories->one(); + return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); } public function getOptions() { @@ -188,8 +186,18 @@ class Product extends \yii\db\ActiveRecord { parent::afterSave($insert, $changedAttributes); -// foreach($this->imagesUpload as $image) { -// $image->saveAs('/images/items/' . $image->baseName .'_'. uniqid() . '.' . $image->extension); +// $images = UploadedFile::getInstance($this, 'imagesUpload'); +// var_dump($images);exit; + +// if (!empty($this->imagesUpload)) { +// if (!is_array($this->imagesUpload)) { +// $this->imagesUpload = [$this->imagesUpload]; +// } +// foreach($this->imagesUpload as $image) { +// $image->saveAs((Yii::getAlias('@frontend/web/storage/products/original/' . $image->baseName .'_'. uniqid() . '.' . $image->extension))); +// } +// +// // } $todel = []; @@ -214,4 +222,53 @@ class Product extends \yii\db\ActiveRecord ProductVariant::deleteAll(['product_variant_id' => $todel]); } } + + public function imagesUpload() + { + if ($this->validate()) { + $images = []; + foreach ($this->imagesUpload as $image) { + $imageName = $image->baseName .'.'. $image->extension; + $i = 0; + while(file_exists(Yii::getAlias('@frontend/web/images/products/' . $imageName))) { + $i++; + $imageName = $image->baseName .'_'. $i .'.'. $image->extension; + } + + $image->saveAs(Yii::getAlias('@frontend/web/images/products/' .$imageName)); + $images[] = $imageName; + } + return $images; + } else { + return false; + } + } + + public function getImagesHTML() { + $op = []; + if ($this->images) { + foreach ($this->images as $image) { + $op[] = Html::img($image->imageUrl); + } + } + return $op; + } + + public function getImagesConfig() { + $op = []; + if ($this->images) { + 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' => [ + 'id' => $image->product_image_id, + ], + ]; + } + } + return $op; + } } diff --git a/common/modules/product/models/ProductImage.php b/common/modules/product/models/ProductImage.php index 51eaf86..8612ff5 100755 --- a/common/modules/product/models/ProductImage.php +++ b/common/modules/product/models/ProductImage.php @@ -9,16 +9,17 @@ use yii\web\UploadedFile; * This is the model class for table "product_image". * * @property integer $product_image_id + * @property integer $product_id * @property integer $product_variant_id * @property string $image * @property string $alt * @property string $title - * * @property Product $product + * @property ProductVariant $productVariant */ class ProductImage extends \yii\db\ActiveRecord { - public $image; + public $imageUpload; /** * @inheritdoc */ @@ -33,12 +34,13 @@ class ProductImage extends \yii\db\ActiveRecord public function rules() { return [ - [['product_image_id', 'product_variant_id'], 'required'], - [['product_image_id', 'product_variant_id'], 'integer'], - [['alt', 'title'], 'string', 'max' => 255], - [['image'], 'safe'], + [['product_id'], 'required'], + [['product_image_id', 'product_id', 'product_variant_id'], 'integer'], + [['alt', 'title', 'image'], 'string', 'max' => 255], + [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], [['product_variant_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => ['product_variant_id' => 'product_variant_id']], - [['image'], 'file', 'extensions'=>'jpg, gif, png'], + [['imageUpload'], 'safe'], + [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], ]; } @@ -49,7 +51,11 @@ class ProductImage extends \yii\db\ActiveRecord { return [ 'product_image_id' => Yii::t('product', 'Product Image ID'), + 'product_id' => Yii::t('product', 'Product ID'), 'product_variant_id' => Yii::t('product', 'Product Variant ID'), + 'product' => Yii::t('product', 'Product'), + 'product' => Yii::t('product', 'Product'), + 'product_variant' => Yii::t('product', 'Product Variant'), 'image' => Yii::t('product', 'Image'), 'alt' => Yii::t('product', 'Alt'), 'title' => Yii::t('product', 'Title'), @@ -59,9 +65,21 @@ class ProductImage extends \yii\db\ActiveRecord /** * @return \yii\db\ActiveQuery */ + public function getProduct() + { + $return = $this->hasOne(Product::className(), ['product_id' => 'product_id']); + if (empty($return)) { + $return = $this->productVariant->product_id; + } + return $return; + } + + /** + * @return \yii\db\ActiveQuery + */ public function getProductVariant() { - return $this->hasOne(ProductVariant::className(), ['product_variant_id' => 'product_variant_id']); + return $this->hasOne(Product::className(), ['product_variant_id' => 'product_variant_id']); } /** @@ -79,7 +97,7 @@ class ProductImage extends \yii\db\ActiveRecord */ public function getImageFile() { - return isset($this->image) ? Yii::$app->params['uploadPath'] . $this->image : null; + return isset($this->image) ? '/images/products/' . $this->image : null; } /** @@ -89,8 +107,7 @@ class ProductImage extends \yii\db\ActiveRecord public function getImageUrl() { // return a default image placeholder if your source image is not found - $image = isset($this->image) ? $this->image : 'default.jpg'; - return Yii::$app->params['uploadUrl'] . $image; + return isset($this->image) ? '/images/products/'. $this->image : 'default.jpg'; } /** @@ -102,7 +119,7 @@ class ProductImage extends \yii\db\ActiveRecord // get the uploaded file instance. for multiple file uploads // the following data will return an array (you may need to use // getInstances method) - $image = UploadedFile::getInstance($this, 'image'); + $image = UploadedFile::getInstance($this, 'imageUpload'); // if no image was uploaded abort the upload if (empty($image)) { @@ -111,8 +128,7 @@ class ProductImage extends \yii\db\ActiveRecord // store the source file name $this->filename = $image->name; - $exploded = explode(".", $image->name); - $ext = end($exploded); + $ext = end((explode(".", $image->name))); // generate a unique file name $this->image = Yii::$app->security->generateRandomString().".{$ext}"; diff --git a/common/modules/product/models/ProductSearch.php b/common/modules/product/models/ProductSearch.php index 921d059..8bfe7a8 100755 --- a/common/modules/product/models/ProductSearch.php +++ b/common/modules/product/models/ProductSearch.php @@ -13,14 +13,18 @@ use yii\web\NotFoundHttpException; */ class ProductSearch extends Product { + public $brand_name; + public $category_name; + /** * @inheritdoc */ public function rules() { return [ - [['name'], 'safe'], + [['name', 'brand_name', 'category_name'], 'safe'], [['tax_brand_id', 'product_id'], 'integer'], + [['is_top', 'is_new'], 'boolean'], ]; } @@ -58,13 +62,27 @@ class ProductSearch extends Product return $dataProvider; } + $dataProvider->setSort([ + 'attributes' => [ + 'name', + 'brand_name', + 'category_name' + ] + ]); + + $query->joinWith(['brand', 'brand.brandNames', 'categories', 'categories.categoryNames']); + // grid filtering conditions $query->andFilterWhere([ 'tax_brand_id' => $this->tax_brand_id, 'product_id' => $this->product_id, + 'is_top' => (bool)$this->is_top, + 'is_new' => (bool)$this->is_new, ]); - $query->andFilterWhere(['like', 'name', $this->name]); + $query->andFilterWhere(['ilike', 'name', $this->name]); + $query->andFilterWhere(['ilike', 'brand_name.value', $this->brand_name]); + $query->andFilterWhere(['ilike', 'category_name.value', $this->category_name]); return $dataProvider; } diff --git a/common/modules/product/models/ProductUnitSearch.php b/common/modules/product/models/ProductUnitSearch.php new file mode 100644 index 0000000..8b0be90 --- /dev/null +++ b/common/modules/product/models/ProductUnitSearch.php @@ -0,0 +1,72 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'product_unit_id' => $this->product_unit_id, + 'is_default' => $this->is_default, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'code', $this->code]); + + return $dataProvider; + } +} diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index f6836b8..08aa5cb 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -16,12 +16,16 @@ use Yii; * @property double $price_old * @property double $stock * @property integer $product_unit_id - * @property ProductUnit $productUnit * @property integer $product_variant_type_id - * @property ProductVariantType $productVariantType + * @property ProductImage $image + * @property array $images + * + * @property ProductUnit $productUnit */ class ProductVariant extends \yii\db\ActiveRecord { + /** @var array $_images */ + public $imagesUpload = []; /** * @inheritdoc */ @@ -41,8 +45,9 @@ class ProductVariant extends \yii\db\ActiveRecord [['price', 'price_old', 'stock'], 'number'], [['name', 'sku'], 'string', 'max' => 255], [['remote_id'], 'string', 'max' => 20], + [['imagesUpload'], 'safe'], + [['imagesUpload'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif', 'maxFiles' => 50], [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']], - [['product_variant_type_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductVariantType::className(), 'targetAttribute' => ['product_variant_type_id' => 'product_variant_type_id']], ]; } @@ -59,8 +64,11 @@ class ProductVariant extends \yii\db\ActiveRecord 'price' => Yii::t('product', 'Price'), 'price_old' => Yii::t('product', 'Price Old'), 'stock' => Yii::t('product', 'Stock'), - 'product_unit_id' => Yii::t('product', 'Unit'), - 'product_variant_type_id' => 'Type of the variant', + 'product_unit_id' => Yii::t('product', 'Product Unit ID'), + 'product_variant_type_id' => Yii::t('product', 'Product Variant Type ID'), + 'stock_caption' => Yii::t('product', 'Stock'), + 'image' => Yii::t('product', 'Image'), + 'images' => Yii::t('product', 'Images'), ]; } @@ -75,30 +83,41 @@ class ProductVariant extends \yii\db\ActiveRecord /** * @return \yii\db\ActiveQuery */ - public function getProduct() + public function getProductVariantType() { - return $this->hasOne(Product::className(), ['product_id' => 'product_id']); + return $this->hasOne(ProductVariantType::className(), ['product_variant_type_id' => 'product_variant_type_id']); } /** * @return \yii\db\ActiveQuery */ - public function getProductVariantType() { - return $this->hasOne(ProductVariantType::className(), ['product_variant_type_id' => 'product_variant_type_id']); + public function getProduct() + { + return $this->hasOne(Product::className(), ['product_id' => 'product_id']); + } + + public function getEnabled() { + return $this->stock !== 0; + } + + public function getStock_caption() { + return is_null($this->stock) ? '∞' : intval($this->stock); } /** * @return \yii\db\ActiveQuery */ - public function getImages() { - return $this->hasMany(ProductImage::className(), ['product_variant_id' => 'product_variant_id']); + public function getImage() + { + return $this->hasOne(ProductImage::className(), ['product_variant_id' => 'product_variant_id']); } /** * @return \yii\db\ActiveQuery */ - public function getImage() { - return $this->hasOne(ProductImage::className(), ['product_variant_id' => 'product_variant_id']); + public function getImages() + { + return $this->hasMany(ProductImage::className(), ['product_variant_id' => 'product_variant_id']); } /** diff --git a/common/modules/product/models/RemoteCategories.php b/common/modules/product/models/RemoteCategories.php deleted file mode 100755 index b9b6ae2..0000000 --- a/common/modules/product/models/RemoteCategories.php +++ /dev/null @@ -1,63 +0,0 @@ - 100], - [['ID_chief', 'ID'], 'string', 'max' => 20], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'Name' => Yii::t('product', 'Name'), - 'ID_chief' => Yii::t('product', 'Id Chief'), - 'ID' => Yii::t('product', 'ID'), - ]; - } - - public function getCategory() { - if (empty($this->ID)) { - return null; - } - return CategorySearch::findByRemoteID($this->ID); - } - - public static function findByID($id) { - /** @var CategoryQuery $query */ - $query = RemoteCategories::find() - ->andFilterWhere(['ID' => $id]); - if (($model = $query->one()) !== null) { - return $model; - } - return null; - } -} diff --git a/common/modules/product/models/RemoteCategoriesSearch.php b/common/modules/product/models/RemoteCategoriesSearch.php deleted file mode 100755 index 6cdc2b3..0000000 --- a/common/modules/product/models/RemoteCategoriesSearch.php +++ /dev/null @@ -1,71 +0,0 @@ - $query, - ]); - - $this->load($params); - - if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); - return $dataProvider; - } - - // grid filtering conditions - $query->andFilterWhere([ - 'local_id' => $this->local_id, - ]); - - $query->andFilterWhere(['like', 'Name', $this->Name]) - ->andFilterWhere(['like', 'ID_chief', $this->ID_chief]) - ->andFilterWhere(['like', 'ID', $this->ID]); - - return $dataProvider; - } -} diff --git a/common/modules/product/models/RemoteProducts.php b/common/modules/product/models/RemoteProducts.php deleted file mode 100755 index 981f933..0000000 --- a/common/modules/product/models/RemoteProducts.php +++ /dev/null @@ -1,77 +0,0 @@ - 100], - [['ID_chief', 'Article', 'ID'], 'string', 'max' => 20], - [['Brand'], 'string', 'max' => 25], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'Name' => Yii::t('product', 'Name'), - 'Price' => Yii::t('product', 'Price'), - 'Price_old' => Yii::t('product', 'Price Old'), - 'ID_chief' => Yii::t('product', 'Id Chief'), - 'Article' => Yii::t('product', 'Article'), - 'Brand' => Yii::t('product', 'Brand'), - 'ID' => Yii::t('product', 'ID'), - 'Date_create' => Yii::t('product', 'Date Create'), - 'local_id' => Yii::t('product', 'Local ID'), - ]; - } - - public function getRemoteCategory() { - if (empty($this->ID_chief)) { - return null; - } - return RemoteCategories::findByID($this->ID_chief); - } - - public function getProduct() { - if (empty($this->ID)) { - return null; - } - return ProductVariantSearch::findByRemoteID($this->ID); - } -} diff --git a/common/modules/product/models/RemoteProductsSearch.php b/common/modules/product/models/RemoteProductsSearch.php deleted file mode 100755 index 7766eab..0000000 --- a/common/modules/product/models/RemoteProductsSearch.php +++ /dev/null @@ -1,77 +0,0 @@ - $query, - ]); - - $this->load($params); - - if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); - return $dataProvider; - } - - // grid filtering conditions - $query->andFilterWhere([ - 'Price' => $this->Price, - 'Price_old' => $this->Price_old, - 'Date_create' => $this->Date_create, - 'local_id' => $this->local_id, - ]); - - $query->andFilterWhere(['like', 'Name', $this->Name]) - ->andFilterWhere(['like', 'ID_chief', $this->ID_chief]) - ->andFilterWhere(['like', 'Article', $this->Article]) - ->andFilterWhere(['like', 'Brand', $this->Brand]) - ->andFilterWhere(['like', 'ID', $this->ID]); - - return $dataProvider; - } -} diff --git a/common/modules/product/views/manage/_form.php b/common/modules/product/views/manage/_form.php index 1baa2d3..8a782d4 100755 --- a/common/modules/product/views/manage/_form.php +++ b/common/modules/product/views/manage/_form.php @@ -17,12 +17,14 @@ use kartik\select2\Select2;
- + ['enctype' => 'multipart/form-data'] + ]); ?> field($model, 'name')->textInput(['maxlength' => true]) ?> field($model, 'description')->widget(\mihaildev\ckeditor\CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?> - field($model, 'video')->textarea()->label('Video embeded'); ?> + field($model, 'video')->textarea(); ?> field($model, 'brand_id')->dropDownList( ArrayHelper::map(ProductHelper::getBrands()->all(), 'brand_id', 'name'), @@ -35,7 +37,7 @@ use kartik\select2\Select2; 'data' => ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'category_id', 'name'), 'language' => 'ru', 'options' => [ - 'placeholder' => 'Select a state ...', + 'placeholder' => Yii::t('product', 'Select categories'), 'multiple' => true, ], 'pluginOptions' => [ @@ -44,14 +46,24 @@ use kartik\select2\Select2; ] ) ?> - - - field($model, 'imagesUpload[]')->widget(FileInput::classname(), [ + field($model, 'imagesUpload[]')->widget(\kartik\file\FileInput::classname(), [ + 'language' => 'ru', 'options' => [ 'accept' => 'image/*', 'multiple' => true, ], - ]);*/?> + 'pluginOptions' => [ + 'allowedFileExtensions' => ['jpg', 'gif', 'png'], + 'initialPreview' => !empty($model->imagesHTML) ? $model->imagesHTML : [], + 'initialPreviewConfig' => $model->imagesConfig, + 'overwriteInitial' => false, + 'showRemove' => false, + 'showUpload' => false, +// 'uploadUrl' => empty($model->product_id) ? null : \yii\helpers\Url::to(['/product/manage/uploadImage']), + 'uploadAsync' => !empty($model->product_id), + 'previewFileType' => 'image', + ], + ]); ?> field($model, 'variants')->widget(MultipleInput::className(), [ 'columns' => [ @@ -62,33 +74,33 @@ use kartik\select2\Select2; [ 'name' => 'name', 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => 'Name', + 'title' => Yii::t('product', 'Name'), ], [ 'name' => 'sku', 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => 'SKU', + 'title' => Yii::t('product', 'SKU'), ], [ 'name' => 'price', 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => 'Price', + 'title' => Yii::t('product', 'Price'), ], [ 'name' => 'price_old', 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => 'Old Price', + 'title' => Yii::t('product', 'Old Price'), ], [ 'name' => 'product_unit_id', 'type' => MultipleInputColumn::TYPE_DROPDOWN, - 'title' => 'Unit', + 'title' => Yii::t('product', 'Unit'), 'items' => ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'), ], [ 'name' => 'stock', 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => 'Stock', + 'title' => Yii::t('product', 'Stock'), 'options' => [ 'placeholder' => '∞' ], diff --git a/common/modules/product/views/manage/index.php b/common/modules/product/views/manage/index.php index 3b7b0f2..3dde594 100755 --- a/common/modules/product/views/manage/index.php +++ b/common/modules/product/views/manage/index.php @@ -22,12 +22,57 @@ $this->params['breadcrumbs'][] = $this->title; 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], - 'product_id', +// 'product_id', 'name', - 'brand.name', - 'category.name', + [ + 'label' => Yii::t('product', 'Brand'), + 'attribute' => 'brand_name', + 'value' => 'brand.name', + ], + [ + 'label' => Yii::t('product', 'Category'), + 'attribute' => 'category_name', + 'value' => 'category.name', + ], + 'variant.price', + 'variant.stock_caption', - ['class' => 'yii\grid\ActionColumn'], + + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{view} {is_top} {is_new} {update} {delete}', + 'buttons' => [ + 'is_top' => function ($url, $model) { + return Html::a('', $url, [ + 'title' => Yii::t('product', ($model->is_top ? 'Set not is top' : 'Set is top')), + ]); + }, + 'is_new' => function ($url, $model) { + return Html::a('', $url, [ + 'title' => Yii::t('product', ($model->is_new ? 'Set not is new' : 'Set is new')), + ]); + }, + ], + 'urlCreator' => function ($action, $model, $key, $index) { + switch ($action) { + case 'is_top': + return \yii\helpers\Url::to(['manage/is_top', 'id' => $model->product_id]); + break; + case 'is_new': + return \yii\helpers\Url::to(['manage/is_new', 'id' => $model->product_id]); + break; + case 'view': + return \yii\helpers\Url::to(['/catalog/product', 'id' => $model->product_id, ['target' => '_blank']]); + break; + case 'update': + return \yii\helpers\Url::to(['manage/update', 'id' => $model->product_id]); + break; + case 'delete': + return \yii\helpers\Url::to(['manage/delete', 'id' => $model->product_id]); + break; + } + } + ], ], ]); ?>
diff --git a/common/modules/product/views/manage/view.php b/common/modules/product/views/manage/view.php index 858ff57..96a750f 100755 --- a/common/modules/product/views/manage/view.php +++ b/common/modules/product/views/manage/view.php @@ -33,6 +33,7 @@ $this->params['breadcrumbs'][] = $this->title; 'fullname', 'brand.name', 'category.name', + 'image.imageUrl:image' ], ]) ?> diff --git a/common/modules/product/views/product-unit/_form.php b/common/modules/product/views/product-unit/_form.php new file mode 100644 index 0000000..f1a1206 --- /dev/null +++ b/common/modules/product/views/product-unit/_form.php @@ -0,0 +1,27 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'code')->textInput(['maxlength' => true]) ?> + + field($model, 'is_default')->checkbox() ?> + +
+ isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/common/modules/product/views/product-unit/_search.php b/common/modules/product/views/product-unit/_search.php new file mode 100644 index 0000000..5fbe4cc --- /dev/null +++ b/common/modules/product/views/product-unit/_search.php @@ -0,0 +1,33 @@ + + + diff --git a/common/modules/product/views/product-unit/create.php b/common/modules/product/views/product-unit/create.php new file mode 100644 index 0000000..5c54fcc --- /dev/null +++ b/common/modules/product/views/product-unit/create.php @@ -0,0 +1,21 @@ +title = Yii::t('product', 'Create Product Unit'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Product Units'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/common/modules/product/views/product-unit/index.php b/common/modules/product/views/product-unit/index.php new file mode 100644 index 0000000..de9aad8 --- /dev/null +++ b/common/modules/product/views/product-unit/index.php @@ -0,0 +1,34 @@ +title = Yii::t('product', 'Product Units'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'name', + 'code:html', + 'is_default:boolean', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/common/modules/product/views/product-unit/update.php b/common/modules/product/views/product-unit/update.php new file mode 100644 index 0000000..fcd5ef7 --- /dev/null +++ b/common/modules/product/views/product-unit/update.php @@ -0,0 +1,23 @@ +title = Yii::t('product', 'Update {modelClass}: ', [ + 'modelClass' => 'Product Unit', +]) . $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Product Units'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->product_unit_id]]; +$this->params['breadcrumbs'][] = Yii::t('product', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/common/modules/product/views/product-unit/view.php b/common/modules/product/views/product-unit/view.php new file mode 100644 index 0000000..a5fbf82 --- /dev/null +++ b/common/modules/product/views/product-unit/view.php @@ -0,0 +1,38 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Product Units'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->product_unit_id], ['class' => 'btn btn-primary']) ?> + $model->product_unit_id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'product_unit_id', + 'name', + 'code', + 'is_default:boolean', + ], + ]) ?> + +
diff --git a/common/modules/product/widgets/views/brandsCarousel.php b/common/modules/product/widgets/views/brandsCarousel.php index d2e97f4..abb869e 100755 --- a/common/modules/product/widgets/views/brandsCarousel.php +++ b/common/modules/product/widgets/views/brandsCarousel.php @@ -3,7 +3,7 @@ diff --git a/common/modules/product/widgets/views/submenu.php b/common/modules/product/widgets/views/submenu.php index edee86a..14520ad 100755 --- a/common/modules/product/widgets/views/submenu.php +++ b/common/modules/product/widgets/views/submenu.php @@ -12,7 +12,7 @@ image)) :?> - + imageUrl ? Yii::$app->imageCache->thumb($_item->imageUrl, 'mainmenu') : ''?>
categoryName->value?>
@@ -34,7 +34,7 @@ image)) :?> - <?= $_item['item']->categoryName->value?> + imageUrl ? Yii::$app->imageCache->thumb($_item['item']->imageUrl, 'mainmenu') : ''?>
categoryName->value?>
diff --git a/common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php b/common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php index bc4c47f..093fc15 100755 --- a/common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php +++ b/common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php @@ -114,7 +114,7 @@ class ArtboxSynonymBehavior extends Behavior { $valueModel->setAttribute($field, $this->$key); } if ($isave) { - $valueModel->setAttribute($this->valueOptionId, $this->owner->{$this->keyNameId}); + $valueModel->setAttribute($this->valueOptionId, $this->owner->getAttribute($this->keyNameId)); $valueModel->save(); if (!empty($this->slug) && empty($this->owner->{$this->slug['slugKeyName']})) { $this->owner->{$this->slug['slugKeyName']} = $this->slugify($valueModel->{$this->slug['valueKeyName']}); diff --git a/common/modules/rubrication/models/TaxGroup.php b/common/modules/rubrication/models/TaxGroup.php index 2e647c1..7db66d5 100755 --- a/common/modules/rubrication/models/TaxGroup.php +++ b/common/modules/rubrication/models/TaxGroup.php @@ -15,7 +15,7 @@ use Yii; * @property string $module * @property boolean $hierarchical * @property string $settings - * @property boolean $is_filter + * @property boolean is_filter * * @property TaxGroupToGroup[] $taxGroupToGroups * @property TaxGroupToGroup[] $taxGroupToGroups0 @@ -62,7 +62,7 @@ class TaxGroup extends \yii\db\ActiveRecord return [ [['name', 'module'], 'required'], [['description', 'settings'], 'string'], - [['hierarchical', 'is_filter'], 'boolean'], + [['hierarchical'], 'boolean'], [['alias', 'module'], 'string', 'max' => 50], [['name'], 'string', 'max' => 255], [['group_to_category'], 'safe'] diff --git a/common/modules/rubrication/models/TaxValueString.php b/common/modules/rubrication/models/TaxValueString.php index 29a8f7c..881110b 100755 --- a/common/modules/rubrication/models/TaxValueString.php +++ b/common/modules/rubrication/models/TaxValueString.php @@ -53,6 +53,6 @@ class TaxValueString extends \yii\db\ActiveRecord */ public function getTaxOption() { - return $this->hasOne(TaxOption::className(), ['tax_option_id' => 'tax_option_id'])->inverseOf('taxValueStrings'); + return $this->hasOne(TaxOption::className(), ['tax_option_id' => 'tax_option_id']); } } diff --git a/common/modules/rubrication/views/tax-group/_form.php b/common/modules/rubrication/views/tax-group/_form.php index f53e292..16482b2 100755 --- a/common/modules/rubrication/views/tax-group/_form.php +++ b/common/modules/rubrication/views/tax-group/_form.php @@ -15,10 +15,10 @@ use common\components\artboxtree\ArtboxTreeHelper; - field($model, 'alias')->textInput(['maxlength' => true]) ?> - field($model, 'name')->textInput(['maxlength' => true]) ?> + field($model, 'alias')->textInput(['maxlength' => true]) ?> + field($model, 'description')->textarea(['rows' => 6]) ?> field($model, 'module')->dropDownList(RubricationHelper::OptionTypes(), [ diff --git a/common/translation/ru/product.php b/common/translation/ru/product.php index 8b11466..c115ddc 100755 --- a/common/translation/ru/product.php +++ b/common/translation/ru/product.php @@ -1,4 +1,4 @@ -` 'Категории', 'Create Category' => 'Создать Категорию', diff --git a/console/config/bootstrap.php b/console/config/bootstrap.php index bef3d5c..6b87d4a 100755 --- a/console/config/bootstrap.php +++ b/console/config/bootstrap.php @@ -2,4 +2,4 @@ Yii::setAlias('@uploadDir', dirname(dirname(__DIR__)) . '/storage/sync'); Yii::setAlias('@uploadFileProducts', 'products.csv'); -Yii::setAlias('@productsDir', dirname(dirname(__DIR__)) . '/storage/products'); +Yii::setAlias('@productsDir', '/images/products'); diff --git a/console/controllers/ImportController.php b/console/controllers/ImportController.php index 5e941a9..06fc37a 100755 --- a/console/controllers/ImportController.php +++ b/console/controllers/ImportController.php @@ -4,6 +4,7 @@ namespace console\controllers; use common\modules\product\models\Category; use common\modules\product\models\CategoryName; +use common\modules\product\models\ProductImage; use common\modules\product\models\ProductVariantType; use common\modules\rubrication\models\TaxOption; use common\modules\rubrication\models\TaxValueString; @@ -100,7 +101,7 @@ class ImportController extends Controller { $product_cost_old = $data[9]; // 11 Цена - $produc_cost = $data[10]; + $product_cost = $data[10]; // 12 Акция $product_akciya = (bool)$data[11]; @@ -133,6 +134,8 @@ class ImportController extends Controller { $_product = new Product(); } + $is_new_product = empty($_product->product_id); + // ==== Set category ==== if ( ($category = CategoryName::find()->filterWhere(['ilike', 'value', trim($catalog_name)])->one()) !== null ) { $_product->categories = [$category->category_id]; @@ -160,9 +163,9 @@ class ImportController extends Controller { $_product->name = $product_name; $_product->video = $product_video; $_product->description = $product_body_ru; - $_product->top = $product_top; + $_product->is_top = $product_top; $_product->akciya = $product_akciya; - $_product->new = $product_new; + $_product->is_new = $product_new; $_product->save(); @@ -195,52 +198,61 @@ class ImportController extends Controller { $mod_size = $mod_arr[1]; $mod_color = $mod_arr[2]; $mod_image = $mod_arr[3]; - $mod_cost = $produc_cost; + $mod_cost = $product_cost; $mod_old_cost = $product_cost_old; // Check product variant - if ( ($_productVariant = ProductVariant::find()->andWhere(['ilike', 'sku', $mod_art])->andWhere(['product_id' => $_product->product_id])->one()) === null ) { + if ( ($_productVariant = ProductVariant::find()->andFilterWhere(['ilike', 'sku', $mod_art])->andFilterWhere(['product_id' => $_product->product_id])->one()) === null ) { $_productVariant = new ProductVariant(); $_productVariant->product_id = $_product->product_id; } + $_productVariant->product_unit_id = 1; $_productVariant->sku = $mod_art; $_productVariant->price = $mod_cost; $_productVariant->price_old = $mod_old_cost; - - $_productVariant->save(); - - $MOD_ARRAY[] = $_productVariant->product_variant_id; - - - $dir = Yii::getAlias('@productsDir').'/'; - if (is_file ($dir . $mod_image)) - { - $resizeObj = new resize ($dir . $mod_image); - $resizeObj->resizeImage (40, 40, 'crop'); - $resizeObj->saveImage ($dir.'ico/' . $mod_image, 100); - $resizeObj->resizeImage (370, 370, 'auto'); - $resizeObj->saveImage ($dir.'/big/' . $mod_image, 100); - } + $_productVariant->stock = 1; $product_variant_type_name = ''; - if (! empty ($mod_color)) + if (! empty ($mod_color)) { $product_variant_type_name = 'Цвет'; - elseif (! empty ($mod_size)) + $_productVariant->name = $mod_color; + } + elseif (! empty ($mod_size)) { $product_variant_type_name = 'Размер'; + $_productVariant->name = $mod_size; + } // ===== Set variant type ==== if ( $product_variant_type_name ) { if ( ($product_variant_type = ProductVariantType::find()->filterWhere(['ilike', 'name', $product_variant_type_name])->one()) !== null ) { $_productVariant->product_variant_type_id = $product_variant_type->product_variant_type_id; } else { - // Create brand $product_variant_type = new ProductVariantType(); $product_variant_type->name = $product_variant_type_name; $product_variant_type->save(); $_productVariant->product_variant_type_id = $product_variant_type->product_variant_type_id; } } + + $_productVariant->save(); + + $MOD_ARRAY[] = $_productVariant->product_variant_id; + + if ($mod_image) { + $url = 'http://rukzachok.com.ua/upload/mod/' . $mod_image; + $image = file_get_contents($url); + if ($image) { + if (($variantImage = ProductImage::find()->andFilterWhere(['ilike', 'image', $mod_image])->andFilterWhere(['product_variant_id' => $_productVariant->product_variant_id])->one()) === null) { + file_put_contents(Yii::getAlias('@productsDir') . "/" . $mod_image, $image); + $variantImage = new ProductImage(); + $variantImage->product_id = $_product->product_id; + $variantImage->product_variant_id = $_productVariant->product_variant_id; + $variantImage->image = $mod_image; + $variantImage->save(); + } + } + } } } @@ -282,353 +294,6 @@ class ImportController extends Controller { } }*/ - // ======================== - // ==== ХАРАКТЕРИСТИКИ ==== - // ======================== - - // есть общие характеристики, которые относятся product_id, такие как brand, gender... - // есть характеристики, которые относятся mod_id, такие как цвет, размер... - - // ==== gender ==== - - /*if (! empty ($gender)) - { - $bookGender = Book::find () - ->where ('book_alias=:book', [ - ':book' => 'gender' - ]) - ->one (); - - foreach ($gender as $filter) - { - if (! empty ($filter)) - { - $bookGenderValue = BookValue::find () - ->where (' - book_id=:book - AND book_value_title=:value - AND book_value_alias=:alias - ', [ - ':book' => $bookGender->book_id, - ':value' => $filter, - ':alias' => Translite::rusencode ($filter), - ] - ) - ->one(); - - if (! isset ($bookGenderValue->book_value_id) || empty ($bookGenderValue->book_value_id)) - { - $db->createCommand () - ->insert (BookValue::tableName (), [ - 'book_id' => $bookGender->book_id, - 'book_value_title' => $filter, - 'book_value_alias' => Translite::rusencode ($filter), - ]) - ->execute (); - - $book_value_id = Yii::$app->db->lastInsertID; - } - else - { - $book_value_id = $bookGenderValue->book_value_id; - } - - // + products_value - $db->createCommand (' - INSERT IGNORE products_value - SET - product_id = '.(int)$product_id.', - book_value_id = '.(int)$book_value_id.' - ') - ->execute (); - } - } - } - - // есть характеристики, которые относятся mod_id, такие как цвет, размер... - - // ==== destination ==== - - if (! empty ($filters)) - { - $bookDestination = Book::find () - ->where ('book_alias=:book', [ - ':book' => 'destination' - ]) - ->one (); - - foreach ($filters as $filter) - { - if (! empty ($filter)) - { - $bookDestinationValue = BookValue::find () - ->where (' - book_id=:book - AND book_value_title=:value - AND book_value_alias=:alias - ', [ - ':book' => $bookDestination->book_id, - ':value' => $filter, - ':alias' => Translite::rusencode ($filter), - ] - ) - ->one(); - - if (! isset ($bookDestinationValue->book_value_id) || empty ($bookDestinationValue->book_value_id)) - { - $db->createCommand () - ->insert (BookValue::tableName (), [ - 'book_id' => $bookDestination->book_id, - 'book_value_title' => $filter, - 'book_value_alias' => Translite::rusencode ($filter), - ]) - ->execute (); - - $book_value_id = Yii::$app->db->lastInsertID; - } - else - { - $book_value_id = $bookDestinationValue->book_value_id; - } - - if (! empty ($MOD_ARRAY)) - { - foreach ($MOD_ARRAY as $id) - { - // + products_value - $db->createCommand (' - INSERT IGNORE mod_value - SET - mod_id = '.(int)$id.', - book_value_id = '.(int)$book_value_id.' - ') - ->execute (); - } - } - } - } - } - - // ==== special ==== - - if (! empty ($filters_extra)) - { - $bookSpecial = Book::find () - ->where ('book_alias=:book', [ - ':book' => 'special' - ]) - ->one (); - - foreach ($filters_extra as $filter) - { - if (! empty ($filter)) - { - $bookSpecialValue = BookValue::find () - ->where (' - book_id=:book - AND book_value_title=:value - AND book_value_alias=:alias - ', [ - ':book' => $bookSpecial->book_id, - ':value' => $filter, - ':alias' => Translite::rusencode ($filter), - ] - ) - ->one(); - - if (! isset ($bookSpecialValue->book_value_id) || empty ($bookSpecialValue->book_value_id)) - { - $db->createCommand () - ->insert (BookValue::tableName (), [ - 'book_id' => $bookSpecial->book_id, - 'book_value_title' => $filter, - 'book_value_alias' => Translite::rusencode ($filter), - ]) - ->execute (); - - $book_value_id = Yii::$app->db->lastInsertID; - } - else - { - $book_value_id = $bookSpecialValue->book_value_id; - } - - if (! empty ($MOD_ARRAY)) - { - foreach ($MOD_ARRAY as $id) - { - // + products_value - $db->createCommand (' - INSERT IGNORE mod_value - SET - mod_id = '.(int)$id.', - book_value_id = '.(int)$book_value_id.' - ') - ->execute (); - } - } - } - } - } - - // ==== year ==== - - if (! empty ($years)) - { - $bookYear = Book::find () - ->where ('book_alias=:book', [ - ':book' => 'year' - ]) - ->one (); - - foreach ($years as $filter) - { - if (! empty ($filter)) - { - $bookYearValue = BookValue::find () - ->where (' - book_id=:book - AND book_value_title=:value - AND book_value_alias=:alias - ', [ - ':book' => $bookYear->book_id, - ':value' => $filter, - ':alias' => Translite::rusencode ($filter), - ] - ) - ->one(); - - if (! isset ($bookYearValue->book_value_id) || empty ($bookYearValue->book_value_id)) - { - $db->createCommand () - ->insert (BookValue::tableName (), [ - 'book_id' => $bookYear->book_id, - 'book_value_title' => $filter, - 'book_value_alias' => Translite::rusencode ($filter), - ]) - ->execute (); - - $book_value_id = Yii::$app->db->lastInsertID; - } - else - { - $book_value_id = $bookYearValue->book_value_id; - } - - if (! empty ($MOD_ARRAY)) - { - foreach ($MOD_ARRAY as $id) - { - // + products_value - $db->createCommand (' - INSERT IGNORE mod_value - SET - mod_id = '.(int)$id.', - book_value_id = '.(int)$book_value_id.' - ') - ->execute (); - } - } - } - } - } - - // ==== $feature ==== - - if (! empty ($feature)) - { - foreach ($feature as $string) - { - $string = str_replace([':', '.'], '', $string); - - if (! empty ($string)) - { - list ($book_title, $value_title) = explode ('*', $string); - - $book_title = trim ($book_title); - $value_title = trim ($value_title); - - if (empty ($book_title) || empty ($value_title)) - { - CONTINUE; - } - - $bookFeature = Book::find () - ->where ('book_title=:book', [ - ':book' => $book_title - ]) - ->one (); - - if (! isset ($bookFeature->book_id) || empty ($bookFeature->book_id)) - { - $db->createCommand () - ->insert (Book::tableName (), [ - 'book_title' => $book_title, - 'book_alias' => Translite::rusencode ($book_title), - ]) - ->execute (); - - $book_id = Yii::$app->db->lastInsertID; - } - else - { - $book_id = $bookFeature->book_id; - } - - $bookFeatureValue = BookValue::find () - ->where (' - book_id=:book - AND book_value_title=:value - AND book_value_alias=:alias - ', [ - ':book' => $book_id, - ':value' => $value_title, - ':alias' => Translite::rusencode ($value_title), - ] - ) - ->one(); - - if (! isset ($bookFeatureValue->book_value_id) || empty ($bookFeatureValue->book_value_id)) - { - $db->createCommand () - ->insert (BookValue::tableName (), [ - 'book_id' => $book_id, - 'book_value_title' => $value_title, - 'book_value_alias' => Translite::rusencode ($value_title), - ]) - ->execute (); - - $book_value_id = Yii::$app->db->lastInsertID; - } - else - { - $book_value_id = $bookFeatureValue->book_value_id; - } - - if (! empty ($MOD_ARRAY)) - { - foreach ($MOD_ARRAY as $id) - { - // + products_value - $db->createCommand (' - INSERT IGNORE mod_value - SET - mod_id = '.(int)$id.', - book_value_id = '.(int)$book_value_id.' - ') - ->execute (); - } - } - } - } - }*/ - - // ==== IMPORTANT ==== - - // записуем ID обработанной записи - - $is_new_product = empty($_product->product_id); - $options = []; if (! empty ($filters)) { diff --git a/frontend/config/main.php b/frontend/config/main.php index 046fb00..0485891 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -38,7 +38,22 @@ return [ 'errorHandler' => [ 'errorAction' => 'site/error', ], - + 'imageCache' => [ + 'class' => 'iutbay\yii2imagecache\ImageCache', + 'sourcePath' => '@app/web/images', + 'sourceUrl' => '@web/images', + 'sizes' => [ + 'brandlist' => [128, 128], + 'product' => [300, 300], + 'product_trumb' => [80, 80], + 'product_trumb2' => [100, 100], + 'product_list' => [130, 70], + 'product_list2' => [130, 70], + 'product_variant' => [40, 40], + 'mainmenu' => [160, 170], + 'large' => [600, 600], + ], + ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, @@ -48,12 +63,20 @@ return [ 'iam' => 'iam/index', 'text/' => 'text/index', '/text/' => 'text/index', - 'catalog' => 'catalog/all', - 'catalog/' => 'catalog/index', - 'products/search' => 'products/search', - 'products/compare' => 'products/compare', - 'products/' => 'products/index', - 'products//-' => 'products/show', + [ + 'class' => '\common\modules\product\CatalogUrlManager', + 'route_map' => [ + 'catalog' => 'catalog/category', + 'product' => 'catalog/product', + 'brand' => 'catalog/brand', + ] + ], +// 'catalog' => 'catalog/all', +// 'catalog/' => 'catalog/index', +// 'products/search' => 'products/search', +// 'products/compare' => 'products/compare', +// 'products/' => 'products/index', +// 'products//-' => 'products/show', 'news/-' => 'news/show', 'brends/' => 'brends/show', 'brends' => 'brends/index', diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index 944e682..4550047 100755 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -78,14 +78,6 @@ class CatalogController extends \yii\web\Controller ] ); - } elseif ($category->depth < 2) { - return $this->render( - 'categories', - [ - 'category' => $category, - 'last_products' => $last_products, - ] - ); } else { $params = []; @@ -161,6 +153,7 @@ class CatalogController extends \yii\web\Controller public function actionProduct() { + /** @var Product $product */ $product = Yii::$app->request->get('product'); $groups = []; @@ -174,12 +167,14 @@ class CatalogController extends \yii\web\Controller if (empty($group->_options)) unset($groups[$i]); } + $category = $product->category; $last_products = ProductHelper::getLastProducts(true); ProductHelper::addLastProsucts($product->product_id); return $this->render('product', [ 'product' => $product, + 'category' => $category, 'properties' => $groups, 'last_products' => $last_products ]); diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index aba9574..ab45916 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -11,7 +11,15 @@ use common\models\Products; class SiteController extends Controller { - + /** + * @inheritdoc + */ + public function actions() + { + return [ + 'thumb' => 'iutbay\yii2imagecache\ThumbAction', + ]; + } public function actionIndex() { @@ -43,4 +51,6 @@ class SiteController extends Controller ]); } + + } \ No newline at end of file diff --git a/frontend/models/ProductFrontendSearch.php b/frontend/models/ProductFrontendSearch.php index f01003a..42b9c05 100755 --- a/frontend/models/ProductFrontendSearch.php +++ b/frontend/models/ProductFrontendSearch.php @@ -51,7 +51,7 @@ class ProductFrontendSearch extends Product { } else { $query = Product::find(); } - $query->joinWith('variant'); +// $query->joinWith('variant'); $query->joinWith('brand'); $query->joinWith('image'); $query->joinWith('categories'); @@ -59,7 +59,7 @@ class ProductFrontendSearch extends Product { $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ - 'pageSize' => 24, + 'pageSize' => 15, ], 'sort' => [ 'attributes' => [ diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php index 4bb4db7..d87bfce 100644 --- a/frontend/views/catalog/product.php +++ b/frontend/views/catalog/product.php @@ -1,248 +1,180 @@ title = $product->name; +//$this->title = (! empty($product->meta_title)) ? $product->meta_title : $product->name; +//$this->registerMetaTag (['name' => 'description', 'content' => ((! empty($product->meta_description)) ? $product->meta_description : $product->name)]); +//$this->registerMetaTag (['name' => 'keywords', 'content' => $product->meta_keywords]); + 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?> -
- - - -
- +$this->registerJs (' -
+ var checkData = function($index) + { + var $source = $(".productLeftBar .product_mod > li").eq($index).find("a"); + var $target = $(".productLeftBar .cost_box"); + $("#cost").text($source.data("cost")); + $("#old_cost").text($source.data("old_cost")); -
-
- Код: variant->sku?> - stock !== 0 && $product->variant->price > 0 ? ' есть в наличии' : ' нет в наличии'?> -
+ if (parseInt ($source.data("old_cost")) == 0) + { + $target.find("strike").hide(); + } + else + { + $target.find("strike").show(); + } -
-
- variant->price > 0) :?> -
- variant->price?> -
-
грн.
- -
- - -
- -
-
+
-
-
-
-
-
+ $("#product_id").val($source.data("id")); + $("#art").text($source.data("art")); + $("#color").text($source.data("color")); + $("#pic").attr("src",$source.data("image")); + $("#picoriginal").attr("href",$source.data("imageoriginal")); + } - + $(".product_mod > li").click(function() + { + checkData($(this).index()); - -
-
-
- БЫСТРЫЙ ЗАКАЗ - - -
-
+ Shadowbox.setup($("#picoriginal")); -
-

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

- Подробно о доставке -
+ return false; + }); -
- -
- -

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

- +
-
-
- - -
-
-

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

- +
+
+ \ No newline at end of file diff --git a/frontend/views/catalog/product_item.php b/frontend/views/catalog/product_item.php index 5509bcc..d24518e 100644 --- a/frontend/views/catalog/product_item.php +++ b/frontend/views/catalog/product_item.php @@ -1,27 +1,62 @@ -
- - -
- image)) :?> - - - <?= $product->image->alt ? $product->image->alt : $product->name?> - +
  • variant) ? ' style="opacity: 0.5"' : '')?>> +
    + -
    name?>
    - brand)) :?> -
    Бренд: brand->name?>
    - -
    categoriesNames)?>
    - variant) :?> -
    variant->price?> грн.
    - - - добавить к сравнению - -
    \ No newline at end of file + name ?> + + + '; + + // есть скидка + if ($product->variant->price_old != 0 && $product->variant->price_old != $product->variant->price) + { + echo ''.$product->variant->price_old.' грн.'; + } + + echo '

    '.$product->variant->price.' грн.

    '; + + echo '
  • '; + + ?> +
    + Купить + +
    + +
    + \ No newline at end of file diff --git a/frontend/views/catalog/products.php b/frontend/views/catalog/products.php index 5b5aa45..86a5f93 100644 --- a/frontend/views/catalog/products.php +++ b/frontend/views/catalog/products.php @@ -5,6 +5,7 @@ use yii\helpers\Url; +use yii\widgets\Breadcrumbs; use common\modules\product\helpers\ProductHelper; $this->title = $category->categoryName->value; @@ -46,52 +47,32 @@ $filterWhitoutPrice['prices'] = [ }); }); - $category->alias, 'filter' => '+ filter .'])?>'; - window.location.href = request; - } - }); - }); - }); -*/?> -
    - -
    -
    ФИЛЬТРЫ
    -
    -
    - + + + +
    +
    +
    + + + + - -
      - + + +
    • Цена:
      @@ -100,142 +81,65 @@ $filterWhitoutPrice['prices'] = [
    - - - totalCount > 0) :?> -
  • Бренд -
    -
    - models as $brand) : - $checked = !empty($filter['brands']) && in_array($brand->alias, $filter['brands']); - $option_url = Url::to(['catalog/category', 'category' => $category, 'filter' => ProductHelper::getFilterForOption($filter, 'brands', $brand->alias, $checked)]); - ?> -
    - - name?> (getProducts()->count()?>) -
    - -
    -
  • - - - -
    ПОДБОР ПО ПАРАМЕТРАМ
    - - -
  • name?> -
    -
    - _options as $option) : - $checked = (isset($filter['options'][$group->alias]) && in_array($option->alias, $filter['options'][$group->alias])); - $option_url = Url::to(['catalog/category', 'category' => $category, 'filter' => ProductHelper::getFilterForOption($filter, 'options', [$option->group->alias => [$option->alias]], $checked)]); - ?> - - -
    -
  • - - - - -
    -
    - - -
    -
    categoryName->value?> (totalCount?>)
    - count) :?> -

    По данному запросу товары не найдены.


    - -

    Показать все товары из категории "categoryName->value?>"

    - - - -
    - -
    - Сортировка: - $productProvider->sort, - 'attributes' => [ - 'name', - 'price', - ] - ]); - ?> - -
    - -
    - -
    - - totalCount > $productProvider->pagination->pageSize) :?> -
    - Страница: - $productProvider->pagination, - 'options' => ['class' => 'pagination pull-right'], - ]); - ?> - -
    - -
    - -
    -
    -
    -
    - models as $product) :?> - - -
    - - totalCount > $productProvider->pagination->pageSize) :?> - - - -
    - Страница: - $productProvider->pagination, - 'options' => ['class' => 'pagination pull-right'], - ]); + totalCount > 0) :?> +
    +
    Бренды
    +
      + models as $brand) : + $checked = !empty($filter['brands']) && in_array($brand->alias, $filter['brands']); + $option_url = Url::to(['catalog/category', 'category' => $category, 'filter' => ProductHelper::getFilterForOption($filter, 'brands', $brand->alias, $checked)]); ?> - -
    - -
    - - description)) :?> -
    - description?> +
  • + onchange="document.location=''" /> + name?> (getProducts()->count()?>) +
  • + + +
    + -
    -
    - + + +
    +
    name?>
    +
      + _options as $option) : + $checked = (isset($filter['options'][$group->alias]) && in_array($option->alias, $filter['options'][$group->alias])); + $option_url = Url::to(['catalog/category', 'category' => $category, 'filter' => ProductHelper::getFilterForOption($filter, 'options', [$option->group->alias => [$option->alias]], $checked)]); + ?> +
    • + /> + ValueRenderHTML?> (_items_count?>) +
    • + +
    -
    -
    + + + +
    +
    +

    name ?>

    +
    +
      + models as $product) :?> + + +
    +
    +
    + totalCount > $productProvider->pagination->pageSize) :?> + $productProvider->pagination, + 'options' => ['class' => 'pagination pull-right'], + ]); + ?> +
    +

    diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 70eea27..30664eb 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -1,38 +1,32 @@ registerJs (" + use yii\helpers\Html; + use yii\helpers\Url; + use frontend\assets\AppAsset; + use yii\web\View; + use frontend\components\Text; + use frontend\components\BgWidget; +// use frontend\components\CompareWidget; + use frontend\components\HreflangWidget; + use common\models\Subscribe; + use yii\widgets\ActiveForm; + use common\modules\product\models\Category; + + AppAsset::register ($this); + $this->registerJs (" $('.phone .more').bind('click',function(){ $('.phone .more_block').toggle(); }); ", View::POS_READY, 'phone'); //$this->registerCssFile(Yii::$app->request->BaseUrl.'/css/style.css'); -$this->registerJsFile (Yii::$app->request->baseUrl . '/js/basket.js', ['position' => View::POS_HEAD, 'depends' => ['yii\web\JqueryAsset']]); -$this->registerJs (" + $this->registerJsFile (Yii::$app->request->baseUrl . '/js/basket.js', ['position' => View::POS_HEAD, 'depends' => ['yii\web\JqueryAsset']]); + $this->registerJs (" $('#basket').basket(); ", View::POS_READY, 'basket'); -$this->registerJsFile (Yii::$app->request->baseUrl . '/js/call.js', ['position' => View::POS_HEAD, 'depends' => ['yii\web\JqueryAsset']]); -$this->registerJs (" + $this->registerJsFile (Yii::$app->request->baseUrl . '/js/call.js', ['position' => View::POS_HEAD, 'depends' => ['yii\web\JqueryAsset']]); + $this->registerJs (" $('#call').call({token:'" . Yii::$app->request->getCsrfToken () . "'}); ", View::POS_READY, 'call'); -$this->registerJs (" + $this->registerJs (" var activeTab = $('.social li:first a').attr('id'); $('.'+activeTab+'_box').show(); $('.social li').click(function(){ @@ -46,20 +40,20 @@ $this->registerJs (" // AssetBundle jcarousel :D -// jquery-migrate -$this->registerJsFile('http://code.jquery.com/jquery-migrate-1.3.0.js',[ - 'position' => View::POS_HEAD, - 'depends' => ['yii\web\JqueryAsset'] -]); + // jquery-migrate + $this->registerJsFile('http://code.jquery.com/jquery-migrate-1.3.0.js',[ + 'position' => View::POS_HEAD, + 'depends' => ['yii\web\JqueryAsset'] + ]); -// jcarousel -$this->registerCssFile(Yii::$app->request->BaseUrl.'/js/jsor-jcarousel-7bb2e0a/skins/tango/skin.css'); -$this->registerJsFile(Yii::$app->request->baseUrl.'/js/jsor-jcarousel-7bb2e0a/lib/jquery.jcarousel.min.js',[ - 'position' => View::POS_HEAD, - 'depends' => ['yii\web\JqueryAsset'] -]); + // jcarousel + $this->registerCssFile(Yii::$app->request->BaseUrl.'/js/jsor-jcarousel-7bb2e0a/skins/tango/skin.css'); + $this->registerJsFile(Yii::$app->request->baseUrl.'/js/jsor-jcarousel-7bb2e0a/lib/jquery.jcarousel.min.js',[ + 'position' => View::POS_HEAD, + 'depends' => ['yii\web\JqueryAsset'] + ]); -$this->registerJs(" + $this->registerJs(" $('.jcarousel').jcarousel({ vertical: true, scroll: 2 @@ -81,15 +75,6 @@ $this->registerJs(" head () ?> - - - - beginBody () ?> @@ -118,13 +103,12 @@ $this->registerJs("
    - user->isGuest): ?> + user->isGuest): ?> Личный кабинет - - + user->identity->username, 20) ?> Выход - +
    @@ -149,7 +133,7 @@ $this->registerJs("
    Корзина 0
    -
    +
    @@ -170,30 +154,34 @@ $this->registerJs(" + + *
      + * parent_id>0)$items->where(['parent_id'=>$row->parent_id]); + * else $items->where(['parent_id'=>$row->id]); + * foreach($items->orderBy('sort')->all() as $key=>$item):?> + *
    • name?>
    • + * + *
    + *
    + **/ ?> @@ -280,47 +268,47 @@ $this->registerJs("
    '; - - $ids = ViewProduct::listView (); - if (! empty($ids)) - { - $products = Products::find ()->where (['id' => ViewProduct::listView ()])->all (); - echo 'Вы просматривали'; - } - else + /* + echo '

    '; + + $ids = ViewProduct::listView (); + if (! empty($ids)) + { + $products = Products::find ()->where (['id' => ViewProduct::listView ()])->all (); + echo 'Вы просматривали'; + } + else + { + $products = Products::find ()->where (['new' => '1'])->orderBy ('id DESC')->innerJoinWith (['cost'])->groupBy ('id')->limit (4)->all (); + echo 'Товары со скидкой'; + } + echo '

    '; + + echo ' + '; + */ ?>
    @@ -345,8 +333,8 @@ $this->registerJs("

    Подписаться на акции

    '/subscribe']); + $subscribe = new Subscribe; + $form = ActiveForm::begin (['action' => '/subscribe']); ?> field ($subscribe, 'email')->textInput (['placeholder' => 'E-mail'])->label (false); ?> field ($subscribe, 'sale')->dropDownList (['10' => '10%', '20' => '20%'], ['prompt' => 'Скидка'])->label (false); ?> @@ -364,29 +352,7 @@ $this->registerJs("
    - - - - - +
    @@ -407,16 +373,6 @@ $this->registerJs(" endBody () ?> - endPage () ?> \ No newline at end of file diff --git a/frontend/web/img/no_photo.png b/frontend/web/img/no_photo.png new file mode 100644 index 0000000..aef9e08 Binary files /dev/null and b/frontend/web/img/no_photo.png differ diff --git a/frontend/web/img/no_photo_big.png b/frontend/web/img/no_photo_big.png new file mode 100644 index 0000000..fc71420 Binary files /dev/null and b/frontend/web/img/no_photo_big.png differ -- libgit2 0.21.4