From 38828295b07deef496f4d4c74e74a890d4fcb6ca Mon Sep 17 00:00:00 2001 From: Karnovsky A Date: Mon, 23 May 2016 15:06:10 +0300 Subject: [PATCH] - --- backend/views/brand/index.php | 7 +++++++ common/config/main.php | 26 ++++++++++++++++++++++++++ common/modules/product/CatalogUrlManager.php | 27 +++++++++++++++++++++++++-- common/modules/product/models/BrandSearch.php | 14 ++++++++++++++ common/modules/product/models/Category.php | 4 ++-- common/modules/product/models/CategorySearch.php | 2 +- common/modules/product/models/Product.php | 2 +- common/modules/product/models/ProductSearch.php | 19 ++++++++++++++----- common/modules/product/models/ProductVariant.php | 4 ++++ common/modules/product/models/ProductVariantSearch.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- common/modules/product/views/manage/index.php | 5 +++++ common/modules/rubrication/models/TaxGroup.php | 4 ++-- common/modules/rubrication/views/tax-group/index.php | 1 + common/modules/rubrication/views/tax-group/view.php | 1 + common/translation/ru/product.php | 3 ++- frontend/config/main.php | 2 +- frontend/controllers/CatalogController.php | 11 ++++++++++- frontend/views/basket/ajax_items.php | 4 +++- frontend/views/basket/index.php | 4 +++- frontend/views/catalog/brands.php | 34 ++++++++++++++++++++++++++++++++++ frontend/views/iam/share.php | 4 +++- frontend/views/layouts/main-menu.php | 2 +- frontend/web/css/style.css | 4 +++- 23 files changed, 214 insertions(+), 25 deletions(-) create mode 100644 frontend/views/catalog/brands.php diff --git a/backend/views/brand/index.php b/backend/views/brand/index.php index 7c54d0f..d1295f1 100755 --- a/backend/views/brand/index.php +++ b/backend/views/brand/index.php @@ -26,6 +26,13 @@ $this->params['breadcrumbs'][] = $this->title; 'name', 'alias', + [ + 'attribute' => 'title', + 'format' => 'html', + 'value' => function($data) { + return Html::img($data->imageUrl, ['width'=>'100']); + }, + ], ['class' => 'yii\grid\ActionColumn'], ], diff --git a/common/config/main.php b/common/config/main.php index 91bcbce..0443cf5 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -90,6 +90,20 @@ return [ 'master' => null ], ], + 'product_basket' => [ + 'resize' => [ + 'width' => 100, + 'height' => 200, + 'master' => null + ], + ], + 'iam' => [ + 'resize' => [ + 'width' => 120, + 'height' => 240, + 'master' => null + ], + ], 'slider' => [ 'resize' => [ 'width' => 720, @@ -104,6 +118,18 @@ return [ 'master' => null ], ], + 'brand_item' => [ + 'resize' => [ + 'width' => 150, + 'height' => 150, + 'master' => null + ], + 'crop' => [ + 'width' => 150, + 'height' => 150, + 'master' => null + ], + ], 'mainmenu' => [ 'resize' => [ 'width' => 160, diff --git a/common/modules/product/CatalogUrlManager.php b/common/modules/product/CatalogUrlManager.php index e719c82..6e194a6 100755 --- a/common/modules/product/CatalogUrlManager.php +++ b/common/modules/product/CatalogUrlManager.php @@ -3,6 +3,7 @@ namespace common\modules\product; use common\modules\product\models\Brand; +use common\modules\product\models\BrandSearch; use common\modules\product\models\CategorySearch; use common\modules\product\models\ProductSearch; use common\modules\rubrication\models\TaxOption; @@ -78,8 +79,15 @@ class CatalogUrlManager implements UrlRuleInterface { $params = [ 'product' => $product, ]; - } elseif ($paths[0] == 'brand') { - + } elseif ($paths[0] == 'brands') { + if (empty($paths[1]) || $paths[1] == 'index') { + $route = 'catalog/brands'; + } elseif (($brand = BrandSearch::findByAlias($paths[1]))) { + $route = 'catalog/brands'; + $params['brand'] = $brand; + } else { + // @todo redirect or return FALSE + } } return [$route, $params]; @@ -169,6 +177,21 @@ class CatalogUrlManager implements UrlRuleInterface { return $url; break; + + case 'catalog/brands': + if (empty($params['brand'])) { + return 'brands'; + } else { + $brand_alias = is_object($params['brand']) ? $params['brand']->alias : strtolower($params['brand']); + } + $url = 'brands/'. $brand_alias; + + if (!empty($params) && ($query = http_build_query($params)) !== '') { + $url .= '?' . $query; + } + + return $url; + break; } } diff --git a/common/modules/product/models/BrandSearch.php b/common/modules/product/models/BrandSearch.php index 45041d4..f2e8f63 100755 --- a/common/modules/product/models/BrandSearch.php +++ b/common/modules/product/models/BrandSearch.php @@ -81,6 +81,8 @@ class BrandSearch extends Brand ->andFilterWhere(['ilike', 'seo_text', $this->seo_text]) ->andFilterWhere(['ilike', 'brand_name.value', $this->brand_name]); + $query->orderBy('brand_id', 'asc'); + return $dataProvider; } @@ -121,4 +123,16 @@ class BrandSearch extends Brand return $dataProvider; } + + public static function findByAlias($alias) { + /** @var CategoryQuery $query */ + $query = Brand::find() + ->with('brandName') + ->andFilterWhere(['alias' => $alias]); + if (($model = $query->one()) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } } diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index 8d70776..bbceea9 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -176,12 +176,12 @@ class Category extends \yii\db\ActiveRecord } public function getImageFile() { - return empty($this->image) ? null : Yii::getAlias('@imagesDir/categories/'. $this->image); + return empty($this->image) ? '/images/no_photo.png' : Yii::getAlias('@imagesDir/categories/'. $this->image); } public function getImageUrl() { - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/categories/' . $this->image); + return empty($this->image) ? '/images/no_photo.png' : Yii::getAlias('@imagesUrl/categories/' . $this->image); } public function beforeSave($insert) diff --git a/common/modules/product/models/CategorySearch.php b/common/modules/product/models/CategorySearch.php index 8a3f2dd..c88758e 100755 --- a/common/modules/product/models/CategorySearch.php +++ b/common/modules/product/models/CategorySearch.php @@ -82,7 +82,7 @@ class CategorySearch extends Category $query->andFilterWhere(['like', 'alias', $this->alias]); - $query->orderBy(['path' => SORT_ASC, 'depth' => SORT_ASC]); + $query->orderBy(['path' => SORT_ASC, 'depth' => SORT_ASC, 'category_id' => SORT_ASC]); return $dataProvider; } diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index d87ffdf..591bd04 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -221,7 +221,7 @@ class Product extends \yii\db\ActiveRecord if (!is_array($_variant)) { return; } - if (!empty($_variant['product_variant_id'])) { + if (!empty($_variant['product_variant_id'])) { unset($todel[$_variant['product_variant_id']]); $model = ProductVariant::findOne($_variant['product_variant_id']); } else { diff --git a/common/modules/product/models/ProductSearch.php b/common/modules/product/models/ProductSearch.php index e464f72..44a49e6 100755 --- a/common/modules/product/models/ProductSearch.php +++ b/common/modules/product/models/ProductSearch.php @@ -15,6 +15,7 @@ class ProductSearch extends Product { public $brand_name; public $category_name; + public $variant_sku; /** * @inheritdoc @@ -22,9 +23,9 @@ class ProductSearch extends Product public function rules() { return [ - [['name', 'brand_name', 'category_name'], 'safe'], + [['name', 'brand_name', 'category_name', 'variant_sku'], 'safe'], [['tax_brand_id', 'product_id'], 'integer'], - [['is_top', 'is_new'], 'boolean'], + [['is_top', 'is_new', 'akciya'], 'boolean'], ]; } @@ -65,12 +66,18 @@ class ProductSearch extends Product $dataProvider->setSort([ 'attributes' => [ 'name', - 'brand_name', - 'category_name' + 'brand_name' => [ + 'asc' => ['brand_name.value' => SORT_ASC], + 'desc' => ['brand_name.value' => SORT_DESC], + 'default' => SORT_DESC, + 'label' => 'Brand name', + ], + 'category_name', + 'variant_sku', ] ]); - $query->joinWith(['brand', 'brand.brandNames', 'categories', 'categories.categoryNames']); + $query->joinWith(['brand', 'brand.brandNames', 'categories', 'categories.categoryNames', 'variant']); if (isset($this->is_top)) { $query->andFilterWhere([ @@ -95,7 +102,9 @@ class ProductSearch extends Product $query->andFilterWhere(['ilike', 'name', $this->name]); $query->andFilterWhere(['ilike', 'brand_name.value', $this->brand_name]); $query->andFilterWhere(['ilike', 'category_name.value', $this->category_name]); + $query->andFilterWhere(['ilike', 'product_variant.sku', $this->variant_sku]); + $query->groupBy(['product.product_id']); $query->orderBy('product.product_id', 'DESC'); return $dataProvider; diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index beaca7d..afff898 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -132,6 +132,10 @@ class ProductVariant extends \yii\db\ActiveRecord return !empty($this->image) ? $this->image->imageUrl : '/images/no_photo.png'; } + public function getFullname() { + return empty($this->product) ? null : ($this->product->name . (empty($this->name) ? '' : ' '. $this->name)); + } + /** * @return \yii\db\ActiveQuery */ diff --git a/common/modules/product/models/ProductVariantSearch.php b/common/modules/product/models/ProductVariantSearch.php index 98badc9..bfb1f25 100755 --- a/common/modules/product/models/ProductVariantSearch.php +++ b/common/modules/product/models/ProductVariantSearch.php @@ -12,14 +12,21 @@ use yii\web\NotFoundHttpException; */ class ProductVariantSearch extends ProductVariant { + public $brand_name; + public $category_name; + public $tax_group_id; + public $is_top; + public $is_new; + public $akciya; /** * @inheritdoc */ public function rules() { return [ - [['name', 'sku', 'price', 'price_old', 'stock'], 'safe'], + [['name', 'fullname', 'sku', 'price', 'price_old', 'stock', 'fullname', 'brand_name', 'category_name'], 'safe'], [['product_variant_id', 'product_id'], 'integer'], + [['is_top', 'is_new', 'akciya'], 'boolean'], ]; } @@ -57,14 +64,54 @@ class ProductVariantSearch extends ProductVariant return $dataProvider; } + $dataProvider->setSort([ + 'attributes' => [ + 'name', + 'brand_name' => [ + 'asc' => ['brand_name.value' => SORT_ASC], + 'desc' => ['brand_name.value' => SORT_DESC], + 'default' => SORT_DESC, + 'label' => 'Brand name', + ], + 'category_name', + 'sku', + ] + ]); + + $query->joinWith(['product', 'product.brand.brandNames', 'product.categories', 'product.categories.categoryNames']); + + if (isset($this->is_top)) { + $query->andFilterWhere([ + 'product.is_top' => (bool)$this->is_top, + ]); + } + if (isset($this->is_new)) { + $query->andFilterWhere([ + 'product.is_new' => (bool)$this->is_new, + ]); + } + if (isset($this->akciya)) { + $query->andFilterWhere([ + 'product.akciya' => (bool)$this->akciya, + ]); + } + // grid filtering conditions $query->andFilterWhere([ + 'product.product_id' => $this->product_id, 'product_variant_id' => $this->product_variant_id, - 'product_id' => $this->product_id, ]); - $query->andFilterWhere(['like', 'name', $this->name]) - ->andFilterWhere(['like', 'sku', $this->sku]); + if (!empty($this->fullname)) { + $query->orFilterWhere(['like', 'name', $this->fullname]); + $query->orFilterWhere(['ilike', 'product.name', $this->fullname]); + } + $query->andFilterWhere(['ilike', 'product.brand_name.value', $this->brand_name]); + $query->andFilterWhere(['ilike', 'product.category_name.value', $this->category_name]); + $query->andFilterWhere(['ilike', 'sku', $this->sku]); + + $query->groupBy(['product_variant_id']); + $query->orderBy('product.product_id', 'DESC'); return $dataProvider; } diff --git a/common/modules/product/views/manage/index.php b/common/modules/product/views/manage/index.php index 35456dc..b21de4a 100755 --- a/common/modules/product/views/manage/index.php +++ b/common/modules/product/views/manage/index.php @@ -34,6 +34,11 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'category_name', 'value' => 'category.name', ], + [ + 'label' => Yii::t('product', 'SKU'), + 'attribute' => 'variant_sku', + 'value' => 'variant.sku', + ], 'variant.price', 'variant.stock_caption', diff --git a/common/modules/rubrication/models/TaxGroup.php b/common/modules/rubrication/models/TaxGroup.php index 7db66d5..2e647c1 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'], 'boolean'], + [['hierarchical', 'is_filter'], 'boolean'], [['alias', 'module'], 'string', 'max' => 50], [['name'], 'string', 'max' => 255], [['group_to_category'], 'safe'] diff --git a/common/modules/rubrication/views/tax-group/index.php b/common/modules/rubrication/views/tax-group/index.php index 57bc84d..cc3605a 100755 --- a/common/modules/rubrication/views/tax-group/index.php +++ b/common/modules/rubrication/views/tax-group/index.php @@ -25,6 +25,7 @@ $this->params['breadcrumbs'][] = $this->title; 'description:ntext', 'module', 'hierarchical:boolean', + 'is_filter:boolean', // 'settings:ntext', [ diff --git a/common/modules/rubrication/views/tax-group/view.php b/common/modules/rubrication/views/tax-group/view.php index b0c4d87..44e1691 100755 --- a/common/modules/rubrication/views/tax-group/view.php +++ b/common/modules/rubrication/views/tax-group/view.php @@ -35,6 +35,7 @@ $this->params['breadcrumbs'][] = $this->title; 'description:ntext', 'module', 'hierarchical:boolean', + 'is_filter:boolean', 'settings:ntext', ], ]) ?> diff --git a/common/translation/ru/product.php b/common/translation/ru/product.php index 4ece346..b786b0e 100755 --- a/common/translation/ru/product.php +++ b/common/translation/ru/product.php @@ -11,5 +11,6 @@ return [ 'Promo products' => 'Акционные товары', 'New products' => 'Новинки', 'Top products' => 'Популярные', - '' => '', + 'Brands' => 'Бренды', + 'Brand' => 'Бренд', ]; \ No newline at end of file diff --git a/frontend/config/main.php b/frontend/config/main.php index 01e3ca9..36e88e7 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -71,7 +71,7 @@ return [ 'route_map' => [ 'catalog' => 'catalog/category', 'product' => 'catalog/product', - 'brand' => 'catalog/brand', + 'brands' => 'catalog/brands', ] ], // 'catalog' => 'catalog/all', diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index 8b72ff1..b2c7e56 100755 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -191,7 +191,16 @@ class CatalogController extends \yii\web\Controller public function actionBrands() { - return 'actionBrands'; + $dataProvider = new ActiveDataProvider([ + 'query' => Brand::find()->joinWith('brandName')->orderBy('brand_name.value'), + 'pagination' => [ + 'pageSize' => -1, + ] + ]); + + return $this->render('brands', [ + 'dataProvider' => $dataProvider, + ]); } public function actionBrand($alias) diff --git a/frontend/views/basket/ajax_items.php b/frontend/views/basket/ajax_items.php index e54b605..d9e4eb9 100755 --- a/frontend/views/basket/ajax_items.php +++ b/frontend/views/basket/ajax_items.php @@ -7,7 +7,9 @@ use yii\helpers\Html;
field($item,'['.$i.']id')->hiddenInput()->label(false); ?>
-
+
+ imageUrl, 'product_basket')?> +
product_name?>
diff --git a/frontend/views/basket/index.php b/frontend/views/basket/index.php index 7bd4e84..5731aa4 100755 --- a/frontend/views/basket/index.php +++ b/frontend/views/basket/index.php @@ -77,7 +77,9 @@ $('#order-delivery input[type=\"radio\"]').click(function(){ $item):?>
- + + imageUrl, 'product_basket')?> +
product_name?>

Код: sku?>, цвет: name?>

diff --git a/frontend/views/catalog/brands.php b/frontend/views/catalog/brands.php new file mode 100644 index 0000000..a673af1 --- /dev/null +++ b/frontend/views/catalog/brands.php @@ -0,0 +1,34 @@ +params['breadcrumbs'][] = Yii::t('product', 'Brands'); + +$this->params['seo']['seo_text'] = 'Brands SEO-text'; +$this->params['seo']['h1'] = Yii::t('product', 'Brands'); +$this->params['seo']['description'] = 'Brands DESCRIPTION'; +$this->params['seo']['fields']['name'] = 'Brands NAME FROM FIELD'; +$this->params['seo']['key']= 'brands'; +?> + + + +
+

params['seo']['h1']?>

+ +
+
\ No newline at end of file diff --git a/frontend/views/iam/share.php b/frontend/views/iam/share.php index f4729e1..3320908 100755 --- a/frontend/views/iam/share.php +++ b/frontend/views/iam/share.php @@ -55,7 +55,9 @@ $this->registerJs(" shareList as $item_p):if(!empty($item_p->product)):?>
-
+ product->cost->cost)):?>
product->cost->cost?> грн.

diff --git a/frontend/views/layouts/main-menu.php b/frontend/views/layouts/main-menu.php index 0dd0761..375fd55 100755 --- a/frontend/views/layouts/main-menu.php +++ b/frontend/views/layouts/main-menu.php @@ -7,6 +7,6 @@ use yii\helpers\Url; diff --git a/frontend/web/css/style.css b/frontend/web/css/style.css index f83409c..6a2cb68 100755 --- a/frontend/web/css/style.css +++ b/frontend/web/css/style.css @@ -244,11 +244,13 @@ ul.product_colors li img{border:1px solid #d2d2d2;} } .help-block{color:red;font-size:12px;margin-bottom:5px;} -.basket_item{padding:10px 0px;border-bottom:1px solid #b7b7b7;} +.basket_item{padding:10px 0px;border-bottom:1px solid #b7b7b7;clear: both} .basket_item img{margin-right:20px;} .basket_item .count{margin:20px 0px;} .basket_item .fr{margin-top:5px;} .basket_item .info{overflow:hidden;} +.basket_item > a{display: block; + float: left;} a.del:visited,a.del:link{background:url('../img/del.png') left center no-repeat;padding:2px 25px;font-size:12px;font-weight:normal;color:#787878;text-decoration: underline;} a.del:hover{color:#a52828;text-decoration: underline;} -- libgit2 0.21.4