Commit e9f8a5ec895e41d909bc19046ece67a1e3f9f41e

Authored by Yarik
1 parent 98780140

Detail page

frontend/controllers/CategoryController.php
... ... @@ -4,7 +4,6 @@
4 4 use artbox\catalog\helpers\FilterHelper;
5 5 use artbox\catalog\models\Category;
6 6 use artbox\core\components\SeoComponent;
7   - use artbox\core\models\Page;
8 7 use yii\data\ActiveDataProvider;
9 8 use yii\db\ActiveQuery;
10 9 use yii\web\Controller;
... ... @@ -38,7 +37,10 @@
38 37 $seo->setModel($model->lang);
39 38 $filterHelper = \Yii::$app->get('filter');
40 39 $filterHelper->setFilter($filter);
41   - $query = $filterHelper->buildQuery();
  40 + $query = $filterHelper->buildQuery()
  41 + ->innerJoinWith('category', false)
  42 + ->andWhere([ 'product_to_category.category_id' => $model->id ])
  43 + ->with('images', 'variants', 'lang');
42 44 $dataProvider = new ActiveDataProvider(
43 45 [
44 46 'query' => $query,
... ... @@ -62,7 +64,7 @@
62 64 *
63 65 * @param $id
64 66 *
65   - * @return \artbox\core\models\Page
  67 + * @return Category
66 68 * @throws \yii\web\NotFoundHttpException
67 69 */
68 70 protected function findModel($id)
... ... @@ -72,7 +74,7 @@
72 74 */
73 75 $seo = Yii::$app->get('seo');
74 76 /**
75   - * @var Page $model
  77 + * @var Category $model
76 78 */
77 79 $model = Category::findWithFilters($id)
78 80 ->with('lang.alias')
... ...
frontend/controllers/ProductController.php 0 → 100755
  1 +<?php
  2 + namespace frontend\controllers;
  3 +
  4 + use artbox\catalog\models\Product;
  5 + use artbox\core\components\SeoComponent;
  6 + use yii\db\ActiveQuery;
  7 + use yii\web\Controller;
  8 + use yii\web\NotFoundHttpException;
  9 + use Yii;
  10 +
  11 + /**
  12 + * Class ProductController
  13 + *
  14 + * @package frontend\controllers
  15 + */
  16 + class ProductController extends Controller
  17 + {
  18 + /**
  19 + * Show product by ID
  20 + *
  21 + * @param int $id
  22 + *
  23 + * @return string
  24 + */
  25 + public function actionView($id)
  26 + {
  27 + $model = $this->findModel($id);
  28 + /**
  29 + * @var SeoComponent $seo
  30 + */
  31 + $seo = Yii::$app->get('seo');
  32 + $seo->setModel($model->lang);
  33 + $variant = $model->variants[ 0 ];
  34 + $groups = $variant->getSortedGroups();
  35 + $similar = $model->getSimilarProducts(8);
  36 +
  37 + return $this->render(
  38 + 'view',
  39 + [
  40 + 'model' => $model,
  41 + 'variant' => $variant,
  42 + 'groups' => $groups,
  43 + 'similar' => $similar,
  44 + ]
  45 + );
  46 + }
  47 +
  48 + /**
  49 + * Find product by ID
  50 + *
  51 + * @param $id
  52 + *
  53 + * @return Product
  54 + * @throws \yii\web\NotFoundHttpException
  55 + */
  56 + protected function findModel($id)
  57 + {
  58 + /**
  59 + * @var SeoComponent $seo
  60 + */
  61 + $seo = \Yii::$app->get('seo');
  62 + /**
  63 + * @var Product $model
  64 + */
  65 + $model = Product::findWithFilters()
  66 + ->with('lang', 'images')
  67 + ->with(
  68 + [
  69 + 'category' => function ($query) {
  70 + /**
  71 + * @var ActiveQuery $query
  72 + */
  73 + $query->with('lang')
  74 + ->with('parent.lang');
  75 + },
  76 + ]
  77 + )
  78 + ->where([ 'id' => $id ])
  79 + ->one();
  80 + if (!empty( $model )) {
  81 + if ($model->lang->alias_id !== $seo->aliasId) {
  82 + throw new NotFoundHttpException('Wrong language');
  83 + }
  84 + return $model;
  85 + } else {
  86 + throw new NotFoundHttpException('Model not found');
  87 + }
  88 + }
  89 + }
0 90 \ No newline at end of file
... ...
frontend/views/category/_product_item.php
1 1 <?php
2 2 use artbox\catalog\models\Product;
3   - use noam148\imagemanager\components\ImageManagerGetPath;
4 3 use yii\helpers\Html;
5 4 use yii\web\View;
6 5  
7 6 /**
8 7 * @var View $this
9 8 * @var Product $product
10   - * @var ImageManagerGetPath $imageManager
11 9 */
12   - $imageManager = \Yii::$app->get('imagemanager');
13 10 ?>
14 11 <div class="col-md-4 col-sm-6">
15 12 <div class="product">
16 13 <div class="image">
17 14 <?php
18 15 if (!empty( $product->images )) {
19   - $image = $product->images[ 0 ]->id;
  16 + $image = $product->images[ 0 ];
20 17 } else {
21 18 $image = null;
22 19 }
23 20 echo Html::a(
24 21 Html::img(
25   - $image ? $imageManager->getImagePath($image) : '/img/no-image.png',
  22 + $image ? $image->getUrl() : '/img/no-image.png',
26 23 [
27 24 'class' => 'img-responsive-image1',
28 25 ]
... ...
frontend/views/product/view.php 0 → 100755
  1 +<?php
  2 + use artbox\catalog\models\OptionGroup;
  3 + use artbox\catalog\models\Product;
  4 + use artbox\catalog\models\Variant;
  5 + use artbox\core\components\SeoComponent;
  6 + use artbox\core\helpers\ImageHelper;
  7 + use yii\bootstrap\Html;
  8 + use yii\helpers\ArrayHelper;
  9 + use yii\web\View;
  10 +
  11 + /**
  12 + * @var View $this
  13 + * @var Product $model
  14 + * @var Variant $variant
  15 + * @var SeoComponent $seo
  16 + * @var array $groups
  17 + * @var Product[] $similar
  18 + */
  19 + $seo = \Yii::$app->get('seo');
  20 + if (!empty( $model->category )) {
  21 + if (!empty( $model->category->parent )) {
  22 + $this->params[ 'breadcrumbs' ][] = [
  23 + 'label' => $model->category->parent->lang->title,
  24 + 'url' => [
  25 + '/category/view',
  26 + 'id' => $model->category->parent->id,
  27 + ],
  28 + ];
  29 + }
  30 + $this->params[ 'breadcrumbs' ][] = [
  31 + 'label' => $model->category->lang->title,
  32 + 'url' => [
  33 + '/category/view',
  34 + 'id' => $model->category->id,
  35 + ],
  36 + ];
  37 + }
  38 + $this->params[ 'breadcrumbs' ][] = $seo->title;
  39 +?>
  40 +<div id="content">
  41 + <div class="container">
  42 + <div class="row">
  43 + <div class="col-md-12">
  44 +
  45 + <div class="row" id="productMain">
  46 + <div class="col-sm-6">
  47 + <div id="mainImage">
  48 + <?php
  49 + if (!empty( $model->images )) {
  50 + echo ImageHelper::set($model->images[ 0 ]->getPath())
  51 + ->fillResize(555, 555)
  52 + ->renderImage(
  53 + [
  54 + 'class' => 'img-responsive',
  55 + 'alt' => $model->lang->title,
  56 + 'title' => $model->lang->title,
  57 + ]
  58 + );
  59 + } else {
  60 + echo ImageHelper::set('@frontend/web/img/no-image.png')
  61 + ->fillResize(555, 555)
  62 + ->renderImage(
  63 + [
  64 + 'class' => 'img-responsive',
  65 + 'alt' => $model->lang->title,
  66 + 'title' => $model->lang->title,
  67 + ]
  68 + );
  69 + }
  70 + ?>
  71 + </div>
  72 +
  73 + <?php
  74 + if ($model->is(2)) {
  75 + ?>
  76 + <div class="ribbon sale">
  77 + <div class="theribbon">SALE</div>
  78 + <div class="ribbon-background"></div>
  79 + </div>
  80 + <!-- /.ribbon -->
  81 + <?php
  82 + }
  83 + if ($model->is(1)) {
  84 + ?>
  85 + <div class="ribbon new">
  86 + <div class="theribbon">NEW</div>
  87 + <div class="ribbon-background"></div>
  88 + </div>
  89 + <!-- /.ribbon -->
  90 + <?php
  91 + }
  92 + ?>
  93 +
  94 + <div class="row" id="thumbs">
  95 + <?php
  96 + if (!empty( $model->images )) {
  97 + foreach ($model->images as $image) {
  98 + echo Html::tag(
  99 + 'div',
  100 + Html::a(
  101 + ImageHelper::set($image->getPath())
  102 + ->fillResize(70, 60)
  103 + ->renderImage(
  104 + [
  105 + 'class' => 'img-responsive',
  106 + 'alt' => $model->lang->title,
  107 + 'title' => $model->lang->title,
  108 + ]
  109 + ),
  110 + ImageHelper::set($image->getPath())
  111 + ->fillResize(555, 555)
  112 + ->render(),
  113 + [
  114 + 'class' => 'thumb',
  115 + ]
  116 + ),
  117 + [
  118 + 'class' => 'col-xs-2',
  119 + ]
  120 + );
  121 + }
  122 + } else {
  123 + echo Html::tag(
  124 + 'div',
  125 + Html::a(
  126 + ImageHelper::set('@frontend/web/img/no-image.png')
  127 + ->fillResize(70, 60)
  128 + ->renderImage(
  129 + [
  130 + 'class' => 'img-responsive',
  131 + 'alt' => $model->lang->title,
  132 + 'title' => $model->lang->title,
  133 + ]
  134 + ),
  135 + ImageHelper::set('@frontend/web/img/no-image.png')
  136 + ->fillResize(555, 555)
  137 + ->render(),
  138 + [
  139 + 'class' => 'thumb',
  140 + ]
  141 + ),
  142 + [
  143 + 'class' => 'col-xs-2',
  144 + ]
  145 + );
  146 + }
  147 + ?>
  148 + </div>
  149 + <?php
  150 + if (!empty( $model->video )) {
  151 + ?>
  152 + <div class="product-video">
  153 + <div class="h3">
  154 + <?php echo \Yii::t('app', 'Видеообзор продукта'); ?>
  155 + </div>
  156 + <div class="video-box">
  157 + <?php echo $model->video; ?>
  158 + </div>
  159 + </div>
  160 + <?php
  161 + }
  162 + ?>
  163 + </div>
  164 + <div class="col-sm-6">
  165 + <div class="box">
  166 + <h1><?php echo $model->lang->title; ?></h1>
  167 + <p class="no-margin"><?php echo $variant->sku; ?></p>
  168 + <p class="price">
  169 + <span class="price-title">Цена:</span><?php echo $variant->price ? : 0; ?> грн&ensp;
  170 + <button class="btn btn-success">
  171 + <i class="fa fa-shopping-cart"></i> Добавить в корзину
  172 + </button>
  173 + <button class="btn btn-default pull-right" data-toggle="tooltip" data-placement="top" title="Добавить в избранное">
  174 + <i class="fa fa-heart-o"></i>
  175 + </button>
  176 + </p>
  177 + <hr>
  178 +
  179 + <button class="btn btn-template-main">
  180 + <i class="fa fa-phone"></i> Купить в один клик
  181 + </button>
  182 + &emsp;<button class="btn btn-template-main">
  183 + <i class="fa fa-tags"></i> Купить в кредит
  184 + </button>
  185 + </div>
  186 + <div class="box" id="details">
  187 + <h2><?php echo \Yii::t('app', 'Описание товара'); ?></h2>
  188 + <?php echo $model->lang->description ? : \Yii::t('app', 'Нет описания'); ?>
  189 + </div>
  190 +
  191 + <div class="box" id="details">
  192 + <h2><?php echo \Yii::t('app', 'Характеристики'); ?></h2>
  193 + <table class="table">
  194 + <tbody>
  195 + <?php
  196 + foreach ($groups as $group) {
  197 + foreach ($group as $optionGroup) {
  198 + /**
  199 + * @var OptionGroup $optionGroup
  200 + */
  201 + echo Html::tag(
  202 + 'tr',
  203 + Html::tag(
  204 + 'td',
  205 + $optionGroup->lang->title,
  206 + [ 'class' => 'td-title' ]
  207 + ) . Html::tag(
  208 + 'td',
  209 + implode(
  210 + ', ',
  211 + ArrayHelper::getColumn(
  212 + $optionGroup->currentOptions,
  213 + 'lang.value'
  214 + )
  215 + )
  216 + )
  217 + );
  218 + }
  219 + }
  220 + ?>
  221 + </tbody>
  222 + </table>
  223 + </div>
  224 + </div>
  225 +
  226 + </div>
  227 +
  228 + <?php
  229 + if (!empty( $similar )) {
  230 + ?>
  231 + <div class="heading text-center">
  232 + <h2><?php echo \Yii::t('app', 'Похожие товары'); ?></h2>
  233 + </div>
  234 +
  235 + <div class="product-carousel">
  236 + <div class="homepage owl-carousel">
  237 + <?php
  238 + $newItemsArrays = array_chunk($similar, 4);
  239 + foreach ($newItemsArrays as $newItemsArray) {
  240 + ?>
  241 + <div class="products">
  242 + <?php
  243 + foreach ($newItemsArray as $product) {
  244 + echo $this->render(
  245 + '@frontend/views/site/_slider_product',
  246 + [
  247 + 'product' => $product,
  248 + ]
  249 + );
  250 + }
  251 + ?>
  252 + </div>
  253 + <?php
  254 + }
  255 + ?>
  256 + </div>
  257 + </div>
  258 + <?php
  259 + }
  260 + ?>
  261 + </div>
  262 + <!-- /.col-md-9 -->
  263 + </div>
  264 + <!-- /.row -->
  265 + </div>
  266 + <!-- /.container -->
  267 +</div>
  268 +<!-- /#content -->
... ...
frontend/web/css/style.css
... ... @@ -2806,10 +2806,6 @@ p.no-margin {
2806 2806 .products {
2807 2807 content: " ";
2808 2808 display: table;
2809   -
2810   -}
2811   -
2812   -.row.products {
2813 2809 width: 100%;
2814 2810 }
2815 2811  
... ...