Commit ba008812ee129cf65c94c940a7e1b4813d6dd9be
1 parent
290fae5b
31.03.16 finish 1
Showing
13 changed files
with
322 additions
and
14 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | +namespace common\behaviors; | |
4 | + | |
5 | +use yii; | |
6 | +use yii\base\Behavior; | |
7 | +use yii\db\ActiveRecord; | |
8 | +use dosamigos\transliterator\TransliteratorHelper; | |
9 | +class RuSlug extends Behavior | |
10 | +{ | |
11 | + public $in_attribute = 'name'; | |
12 | + public $out_attribute = 'slug'; | |
13 | + public $translit = true; | |
14 | + | |
15 | + public function events() | |
16 | + { | |
17 | + return [ | |
18 | + ActiveRecord::EVENT_BEFORE_VALIDATE => 'getSlug' | |
19 | + ]; | |
20 | + } | |
21 | + | |
22 | + public function getSlug( $event ) | |
23 | + { | |
24 | + if ( empty( $this->owner->{$this->out_attribute} ) ) { | |
25 | + $this->owner->{$this->out_attribute} = $this->generateSlug( $this->owner->{$this->in_attribute} ); | |
26 | + } else { | |
27 | + $this->owner->{$this->out_attribute} = $this->generateSlug( $this->owner->{$this->out_attribute} ); | |
28 | + } | |
29 | + } | |
30 | + | |
31 | + private function generateSlug( $slug ) | |
32 | + { | |
33 | + $slug = $this->translit( $slug ); | |
34 | + if ( $this->checkUniqueSlug( $slug ) ) { | |
35 | + return $slug; | |
36 | + } else { | |
37 | + for ( $suffix = 2; !$this->checkUniqueSlug( $new_slug = $slug . '-' . $suffix ); $suffix++ ) {} | |
38 | + return $new_slug; | |
39 | + } | |
40 | + } | |
41 | + | |
42 | + private function slugify( $slug ) | |
43 | + { | |
44 | + if ( $this->translit ) { | |
45 | + return yii\helpers\Inflector::slug( TransliteratorHelper::process( $slug ), '-', true ); | |
46 | + } else { | |
47 | + return $this->slug( $slug, '-', true ); | |
48 | + } | |
49 | + } | |
50 | + | |
51 | + private function slug( $string, $replacement = '-', $lowercase = true ) | |
52 | + { | |
53 | + $string = preg_replace( '/[^\p{L}\p{Nd}]+/u', $replacement, $string ); | |
54 | + $string = trim( $string, $replacement ); | |
55 | + return $lowercase ? strtolower( $string ) : $string; | |
56 | + } | |
57 | + | |
58 | + private function checkUniqueSlug( $slug ) | |
59 | + { | |
60 | + $pk = $this->owner->primaryKey(); | |
61 | + $pk = $pk[0]; | |
62 | + | |
63 | + $condition = $this->out_attribute . ' = :out_attribute'; | |
64 | + $params = [ ':out_attribute' => $slug ]; | |
65 | + if ( !$this->owner->isNewRecord ) { | |
66 | + $condition .= ' and ' . $pk . ' != :pk'; | |
67 | + $params[':pk'] = $this->owner->{$pk}; | |
68 | + } | |
69 | + | |
70 | + return !$this->owner->find() | |
71 | + ->where( $condition, $params ) | |
72 | + ->one(); | |
73 | + } | |
74 | + | |
75 | + static function translit ($string, $setting = 'all') | |
76 | + { | |
77 | + $letter = array ( | |
78 | + | |
79 | + 'а' => 'a', 'б' => 'b', 'в' => 'v', | |
80 | + 'г' => 'g', 'д' => 'd', 'е' => 'e', | |
81 | + 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', | |
82 | + 'и' => 'i', 'й' => 'y', 'к' => 'k', | |
83 | + 'л' => 'l', 'м' => 'm', 'н' => 'n', | |
84 | + 'о' => 'o', 'п' => 'p', 'р' => 'r', | |
85 | + 'с' => 's', 'т' => 't', 'у' => 'u', | |
86 | + 'ф' => 'f', 'х' => 'h', 'ц' => 'c', | |
87 | + 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch', | |
88 | + 'ь' => "", 'ы' => 'y', 'ъ' => "", | |
89 | + 'э' => 'e', 'ю' => 'yu', 'я' => 'ya', | |
90 | + 'ї' => 'yi', 'є' => 'ye', 'і' => 'ee', | |
91 | + | |
92 | + 'А' => 'A', 'Б' => 'B', 'В' => 'V', | |
93 | + 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', | |
94 | + 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z', | |
95 | + 'И' => 'I', 'Й' => 'Y', 'К' => 'K', | |
96 | + 'Л' => 'L', 'М' => 'M', 'Н' => 'N', | |
97 | + 'О' => 'O', 'П' => 'P', 'Р' => 'R', | |
98 | + 'С' => 'S', 'Т' => 'T', 'У' => 'U', | |
99 | + 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', | |
100 | + 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch', | |
101 | + 'Ь' => "", 'Ы' => 'Y', 'Ъ' => "", | |
102 | + 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya', | |
103 | + 'Ї' => 'Yi', 'Є' => 'Ye', 'І' => 'Ee' | |
104 | + ); | |
105 | + | |
106 | + $symbol = array ( | |
107 | + ' ' => '-', "'" => '', '"' => '', | |
108 | + '!' => '', "@" => '', '#' => '', | |
109 | + '$' => '', "%" => '', '^' => '', | |
110 | + ';' => '', "*" => '', '(' => '', | |
111 | + ')' => '', "+" => '', '~' => '', | |
112 | + '.' => '', ',' => '-', '?' => '', | |
113 | + '…' => '', '№' => 'N', '°' => '', | |
114 | + '`' => '', '|' => '', '&' => '-and-', | |
115 | + '<' => '', '>' => '' | |
116 | + ); | |
117 | + | |
118 | + if ($setting == 'all') | |
119 | + { | |
120 | + $converter = $letter + $symbol; | |
121 | + } | |
122 | + else if ($setting == 'letter') | |
123 | + { | |
124 | + $converter = $letter; | |
125 | + } | |
126 | + else if ($setting == 'symbol') | |
127 | + { | |
128 | + $converter = $symbol; | |
129 | + } | |
130 | + | |
131 | + $url = strtr ($string, $converter); | |
132 | + | |
133 | + $url = str_replace ("---", '-', $url); | |
134 | + $url = str_replace ("--", '-', $url); | |
135 | + | |
136 | + return $url; | |
137 | + } | |
138 | + | |
139 | +} | |
0 | 140 | \ No newline at end of file | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace app\models; | |
4 | + | |
5 | +class TemplateLocation extends \yii\db\ActiveRecord | |
6 | +{ | |
7 | + public static function tableName() | |
8 | + { | |
9 | + return 'template_location'; | |
10 | + } | |
11 | + | |
12 | + public function findFreeLocationForBanner ($template_location_id = false) | |
13 | + { | |
14 | + return TemplateLocation::find() | |
15 | + ->where(' | |
16 | + template_location_id NOT IN | |
17 | + ( | |
18 | + SELECT template_location_id | |
19 | + FROM banner | |
20 | + '.($template_location_id ? 'WHERE template_location_id != '.$template_location_id : '').' | |
21 | + ) | |
22 | + AND is_banner = 1 | |
23 | + ') | |
24 | + ->all(); | |
25 | + } | |
26 | + | |
27 | + public function findFreeLocationForSlider () | |
28 | + { | |
29 | + return TemplateLocation::find() | |
30 | + ->where(' | |
31 | + template_location_id NOT IN | |
32 | + ( | |
33 | + SELECT template_location_id | |
34 | + FROM slider | |
35 | + ) | |
36 | + AND is_slider = 1 | |
37 | + ') | |
38 | + ->all(); | |
39 | + } | |
40 | +} | |
0 | 41 | \ No newline at end of file | ... | ... |
common/modules/product/models/Category.php
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | namespace common\modules\product\models; |
4 | 4 | |
5 | -use common\behaviors\Slug; | |
5 | +use common\behaviors\RuSlug; | |
6 | 6 | use common\components\artboxtree\ArtboxTreeBehavior; |
7 | 7 | use common\modules\relation\relationBehavior; |
8 | 8 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; |
... | ... | @@ -41,7 +41,7 @@ class Category extends \yii\db\ActiveRecord |
41 | 41 | 'keyNamePath' => 'path', |
42 | 42 | ], |
43 | 43 | 'slug' => [ |
44 | - 'class' => Slug::className(), | |
44 | + 'class' => RuSlug::className(), | |
45 | 45 | 'in_attribute' => 'name', |
46 | 46 | 'out_attribute' => 'alias', |
47 | 47 | 'translit' => true | ... | ... |
common/translation/ru/app.php
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: vitaliy | |
5 | + * Date: 31.03.16 | |
6 | + * Time: 12:20 | |
7 | + */ | |
8 | + | |
9 | +namespace common\widgets; | |
10 | +use common\modules\product\models\ProductVariant; | |
11 | +use yii\base\Widget; | |
12 | + | |
13 | + | |
14 | +class BasketHead extends Widget | |
15 | +{ | |
16 | + | |
17 | + public function init(){ | |
18 | + | |
19 | + parent::init(); | |
20 | + | |
21 | + } | |
22 | + | |
23 | + | |
24 | + public function run() | |
25 | + { | |
26 | + $sessionData = \Yii::$app->session->get('order'); | |
27 | + unset($sessionData['order_id']); | |
28 | + $count = count($sessionData); | |
29 | + $price = 0; | |
30 | + if(is_array($sessionData) && !empty($sessionData)){ | |
31 | + | |
32 | + $variant = ProductVariant::find()->where(['product_variant_id'=>array_keys($sessionData)])->indexBy('product_variant_id')->all(); | |
33 | + | |
34 | + | |
35 | + foreach ($sessionData as $k => $item) { | |
36 | + $sessionData[$k]['item'] = $variant[$k]; | |
37 | + $price += $variant[$k]->price * $sessionData[$k]['num']; | |
38 | + } | |
39 | + | |
40 | + | |
41 | + return $this->render('basket_head',[ | |
42 | + 'items'=>$sessionData, | |
43 | + 'count' => $count, | |
44 | + 'price' => $price | |
45 | + ]); | |
46 | + | |
47 | + } | |
48 | + | |
49 | + } | |
50 | +} | |
0 | 51 | \ No newline at end of file | ... | ... |
common/widgets/BasketModal.php
1 | +<?php | |
2 | +use yii\bootstrap\Html; | |
3 | +?> | |
4 | +<div class="basket_head"> | |
5 | + <img src="/images/ico_basket.png" class="bh_cell img"> | |
6 | + <div class="bh_cell text"> | |
7 | + <div class="basket_head_title"><?= Yii::t('app','basket');?> <?= $count? Html::tag('span',$count,['class'=>'head_basket_count']) :'' ?></div> | |
8 | + </div> | |
9 | + <i class="head-down bh_cell"></i> | |
10 | +</div> | ... | ... |
common/widgets/views/busket_modal.php renamed to common/widgets/views/basket_modal.php
console/migrations/m160331_122305_template_location.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +use yii\db\Migration; | |
4 | + | |
5 | +class m160331_122305_template_location extends Migration | |
6 | +{ | |
7 | + public function up() | |
8 | + { | |
9 | + $this->createTable('{{%template_location}}', [ | |
10 | + 'template_location_id' => $this->primaryKey(), | |
11 | + 'template_location_name' => $this->string(255)->notNull(), | |
12 | + 'template_location_title' => $this->string(255), | |
13 | + 'width' => $this->integer(4)->notNull(), | |
14 | + 'height' => $this->integer(4)->notNull(), | |
15 | + 'sort' => $this->integer(6)->notNull(), | |
16 | + 'is_slider' => $this->smallInteger(1), | |
17 | + 'is_banner' => $this->smallInteger(1), | |
18 | + ]); | |
19 | + } | |
20 | + | |
21 | + public function down() | |
22 | + { | |
23 | + $this->dropTable('{{%template_location}}'); | |
24 | + } | |
25 | + | |
26 | + | |
27 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\db\Migration; | |
4 | + | |
5 | +class m160331_132149_slider extends Migration | |
6 | +{ | |
7 | + public function up() | |
8 | + { | |
9 | + $this->createTable('{{%slider}}', [ | |
10 | + 'slider_id' => $this->primaryKey(), | |
11 | + 'template_location_id' => $this->integer(4)->notNull(), | |
12 | + 'speed' => $this->integer(4), | |
13 | + 'duration' => $this->integer(4), | |
14 | + 'title' => $this->string(200), | |
15 | + 'status' => $this->smallInteger(1), | |
16 | + ]); | |
17 | + $this->addForeignKey('template_location_slider_fk', 'template_location', 'template_location_id', 'slider', 'template_location_id', 'CASCADE', 'CASCADE'); | |
18 | + } | |
19 | + | |
20 | + public function down() | |
21 | + { | |
22 | + //$this->dropForeignKey('template_location_slider_fk', '{{%template_location}}'); | |
23 | + $this->dropTable('{{%slider}}'); | |
24 | + } | |
25 | + | |
26 | + | |
27 | +} | ... | ... |
frontend/views/layouts/main.php
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | /* @var $content string */ |
5 | 5 | |
6 | 6 | |
7 | +use common\widgets\BasketHead; | |
7 | 8 | use common\widgets\BasketModal; |
8 | 9 | use frontend\assets\AppAsset; |
9 | 10 | use yii\helpers\Html; |
... | ... | @@ -68,14 +69,7 @@ AppAsset::register($this); |
68 | 69 | <div class="phone_desc">Звоните с 9.00 до 18.00 по будням</div> |
69 | 70 | </div> |
70 | 71 | </div> |
71 | - | |
72 | - <div class="basket_head"> | |
73 | - <img src="/images/ico_basket.png" class="bh_cell img"> | |
74 | - <div class="bh_cell text"> | |
75 | - <div class="basket_head_title">Корзина</div> | |
76 | - </div> | |
77 | - <i class="head-down bh_cell"></i> | |
78 | - </div> | |
72 | + <?= BasketHead::widget([]); ?> | |
79 | 73 | |
80 | 74 | </div> |
81 | 75 | ... | ... |
frontend/web/css/concat_all.css
... | ... | @@ -5,6 +5,8 @@ |
5 | 5 | .w_960 { |
6 | 6 | width: 960px; |
7 | 7 | margin: auto; |
8 | + overflow: hidden; | |
9 | + | |
8 | 10 | } |
9 | 11 | |
10 | 12 | .cat_p_bradcrump { |
... | ... | @@ -1013,7 +1015,7 @@ hr { |
1013 | 1015 | .item_3_blocks_wrap .busket_block .quick_order form .quick_order_phone { |
1014 | 1016 | font-size: 12px; |
1015 | 1017 | color: #333333; |
1016 | - padding: 9px; | |
1018 | + padding: 10px; | |
1017 | 1019 | border: 1px solid #C6C7C9; |
1018 | 1020 | -webkit-border-radius: 2px; |
1019 | 1021 | border-radius: 2px; |
... | ... | @@ -3227,4 +3229,8 @@ span.red { |
3227 | 3229 | .product_service ul li.item3 { |
3228 | 3230 | background: url('/images/li3.png') left no-repeat; |
3229 | 3231 | padding: 3px 23px; |
3232 | +} | |
3233 | + | |
3234 | +.head_basket_count{ | |
3235 | + color:#6aa033; | |
3230 | 3236 | } |
3231 | 3237 | \ No newline at end of file | ... | ... |
frontend/web/js/basket.js
... | ... | @@ -3,6 +3,18 @@ $(document).ready(function(){ |
3 | 3 | var result_block = $('.basket_result'); |
4 | 4 | var one_item_block = $('.busket_block'); |
5 | 5 | |
6 | + function countItems(){ | |
7 | + var length = $('.busket_modal_01').find('.order_list_li').length; | |
8 | + if(length >= 1){ | |
9 | + $('.head_basket_count').html(length); | |
10 | + $('.all_count').html(length); | |
11 | + } else { | |
12 | + $('.head_basket_count').html(''); | |
13 | + $('.all_count').html(''); | |
14 | + } | |
15 | + } | |
16 | + | |
17 | + | |
6 | 18 | |
7 | 19 | function changeAjaxPrice(id, num){ |
8 | 20 | $.post( "/orders/buy-items", {id: id, num:num}, function( data ) { |
... | ... | @@ -23,8 +35,10 @@ $(document).ready(function(){ |
23 | 35 | var id = $(this).data('id'); |
24 | 36 | $.post( "/orders/buy-items", {id: id, num:1}, function( data ) { |
25 | 37 | $('.basket_result').each(function(){ |
26 | - $(this).html(data) | |
38 | + $(this).html(data); | |
39 | + countItems(); | |
27 | 40 | }); |
41 | + | |
28 | 42 | }); |
29 | 43 | |
30 | 44 | }); |
... | ... | @@ -54,7 +68,7 @@ $(document).ready(function(){ |
54 | 68 | block.remove(); |
55 | 69 | }); |
56 | 70 | countPrise(forCount); |
57 | - | |
71 | + countItems(); | |
58 | 72 | |
59 | 73 | |
60 | 74 | ... | ... |