From ba008812ee129cf65c94c940a7e1b4813d6dd9be Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 31 Mar 2016 17:13:27 +0300 Subject: [PATCH] 31.03.16 finish 1 --- common/behaviors/RuSlug.php | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/TemplateLocation.php | 40 ++++++++++++++++++++++++++++++++++++++++ common/modules/product/models/Category.php | 4 ++-- common/translation/ru/app.php | 1 + common/widgets/BasketHead.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ common/widgets/BasketModal.php | 2 +- common/widgets/views/basket_head.php | 10 ++++++++++ common/widgets/views/basket_modal.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ common/widgets/views/busket_modal.php | 53 ----------------------------------------------------- console/migrations/m160331_122305_template_location.php | 27 +++++++++++++++++++++++++++ console/migrations/m160331_132149_slider.php | 27 +++++++++++++++++++++++++++ frontend/views/layouts/main.php | 10 ++-------- frontend/web/css/concat_all.css | 8 +++++++- frontend/web/js/basket.js | 18 ++++++++++++++++-- 14 files changed, 375 insertions(+), 67 deletions(-) create mode 100644 common/behaviors/RuSlug.php create mode 100644 common/models/TemplateLocation.php create mode 100644 common/widgets/BasketHead.php create mode 100644 common/widgets/views/basket_head.php create mode 100644 common/widgets/views/basket_modal.php delete mode 100644 common/widgets/views/busket_modal.php create mode 100644 console/migrations/m160331_122305_template_location.php create mode 100644 console/migrations/m160331_132149_slider.php diff --git a/common/behaviors/RuSlug.php b/common/behaviors/RuSlug.php new file mode 100644 index 0000000..d2b8f73 --- /dev/null +++ b/common/behaviors/RuSlug.php @@ -0,0 +1,139 @@ + 'getSlug' + ]; + } + + public function getSlug( $event ) + { + if ( empty( $this->owner->{$this->out_attribute} ) ) { + $this->owner->{$this->out_attribute} = $this->generateSlug( $this->owner->{$this->in_attribute} ); + } else { + $this->owner->{$this->out_attribute} = $this->generateSlug( $this->owner->{$this->out_attribute} ); + } + } + + private function generateSlug( $slug ) + { + $slug = $this->translit( $slug ); + if ( $this->checkUniqueSlug( $slug ) ) { + return $slug; + } else { + for ( $suffix = 2; !$this->checkUniqueSlug( $new_slug = $slug . '-' . $suffix ); $suffix++ ) {} + return $new_slug; + } + } + + private function slugify( $slug ) + { + if ( $this->translit ) { + return yii\helpers\Inflector::slug( TransliteratorHelper::process( $slug ), '-', true ); + } else { + return $this->slug( $slug, '-', true ); + } + } + + private function slug( $string, $replacement = '-', $lowercase = true ) + { + $string = preg_replace( '/[^\p{L}\p{Nd}]+/u', $replacement, $string ); + $string = trim( $string, $replacement ); + return $lowercase ? strtolower( $string ) : $string; + } + + private function checkUniqueSlug( $slug ) + { + $pk = $this->owner->primaryKey(); + $pk = $pk[0]; + + $condition = $this->out_attribute . ' = :out_attribute'; + $params = [ ':out_attribute' => $slug ]; + if ( !$this->owner->isNewRecord ) { + $condition .= ' and ' . $pk . ' != :pk'; + $params[':pk'] = $this->owner->{$pk}; + } + + return !$this->owner->find() + ->where( $condition, $params ) + ->one(); + } + + static function translit ($string, $setting = 'all') + { + $letter = array ( + + 'а' => 'a', 'б' => 'b', 'в' => 'v', + 'г' => 'g', 'д' => 'd', 'е' => 'e', + 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', + 'и' => 'i', 'й' => 'y', 'к' => 'k', + 'л' => 'l', 'м' => 'm', 'н' => 'n', + 'о' => 'o', 'п' => 'p', 'р' => 'r', + 'с' => 's', 'т' => 't', 'у' => 'u', + 'ф' => 'f', 'х' => 'h', 'ц' => 'c', + 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch', + 'ь' => "", 'ы' => 'y', 'ъ' => "", + 'э' => 'e', 'ю' => 'yu', 'я' => 'ya', + 'ї' => 'yi', 'є' => 'ye', 'і' => 'ee', + + 'А' => 'A', 'Б' => 'B', 'В' => 'V', + 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', + 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z', + 'И' => 'I', 'Й' => 'Y', 'К' => 'K', + 'Л' => 'L', 'М' => 'M', 'Н' => 'N', + 'О' => 'O', 'П' => 'P', 'Р' => 'R', + 'С' => 'S', 'Т' => 'T', 'У' => 'U', + 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', + 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch', + 'Ь' => "", 'Ы' => 'Y', 'Ъ' => "", + 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya', + 'Ї' => 'Yi', 'Є' => 'Ye', 'І' => 'Ee' + ); + + $symbol = array ( + ' ' => '-', "'" => '', '"' => '', + '!' => '', "@" => '', '#' => '', + '$' => '', "%" => '', '^' => '', + ';' => '', "*" => '', '(' => '', + ')' => '', "+" => '', '~' => '', + '.' => '', ',' => '-', '?' => '', + '…' => '', '№' => 'N', '°' => '', + '`' => '', '|' => '', '&' => '-and-', + '<' => '', '>' => '' + ); + + if ($setting == 'all') + { + $converter = $letter + $symbol; + } + else if ($setting == 'letter') + { + $converter = $letter; + } + else if ($setting == 'symbol') + { + $converter = $symbol; + } + + $url = strtr ($string, $converter); + + $url = str_replace ("---", '-', $url); + $url = str_replace ("--", '-', $url); + + return $url; + } + +} \ No newline at end of file diff --git a/common/models/TemplateLocation.php b/common/models/TemplateLocation.php new file mode 100644 index 0000000..c00d5c9 --- /dev/null +++ b/common/models/TemplateLocation.php @@ -0,0 +1,40 @@ +where(' + template_location_id NOT IN + ( + SELECT template_location_id + FROM banner + '.($template_location_id ? 'WHERE template_location_id != '.$template_location_id : '').' + ) + AND is_banner = 1 + ') + ->all(); + } + + public function findFreeLocationForSlider () + { + return TemplateLocation::find() + ->where(' + template_location_id NOT IN + ( + SELECT template_location_id + FROM slider + ) + AND is_slider = 1 + ') + ->all(); + } +} \ No newline at end of file diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index dacecae..a8ffd07 100644 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -2,7 +2,7 @@ namespace common\modules\product\models; -use common\behaviors\Slug; +use common\behaviors\RuSlug; use common\components\artboxtree\ArtboxTreeBehavior; use common\modules\relation\relationBehavior; use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; @@ -41,7 +41,7 @@ class Category extends \yii\db\ActiveRecord 'keyNamePath' => 'path', ], 'slug' => [ - 'class' => Slug::className(), + 'class' => RuSlug::className(), 'in_attribute' => 'name', 'out_attribute' => 'alias', 'translit' => true diff --git a/common/translation/ru/app.php b/common/translation/ru/app.php index 66b4f36..9397773 100644 --- a/common/translation/ru/app.php +++ b/common/translation/ru/app.php @@ -31,4 +31,5 @@ return [ 'personal_data' => 'Личные данные', 'my_orders' => 'Мои заказы', 'bookmarks' => 'Закладки', + 'basket' => 'Корзина', ]; \ No newline at end of file diff --git a/common/widgets/BasketHead.php b/common/widgets/BasketHead.php new file mode 100644 index 0000000..c0dcac6 --- /dev/null +++ b/common/widgets/BasketHead.php @@ -0,0 +1,50 @@ +session->get('order'); + unset($sessionData['order_id']); + $count = count($sessionData); + $price = 0; + if(is_array($sessionData) && !empty($sessionData)){ + + $variant = ProductVariant::find()->where(['product_variant_id'=>array_keys($sessionData)])->indexBy('product_variant_id')->all(); + + + foreach ($sessionData as $k => $item) { + $sessionData[$k]['item'] = $variant[$k]; + $price += $variant[$k]->price * $sessionData[$k]['num']; + } + + + return $this->render('basket_head',[ + 'items'=>$sessionData, + 'count' => $count, + 'price' => $price + ]); + + } + + } +} \ No newline at end of file diff --git a/common/widgets/BasketModal.php b/common/widgets/BasketModal.php index 8649b5c..d810482 100644 --- a/common/widgets/BasketModal.php +++ b/common/widgets/BasketModal.php @@ -31,7 +31,7 @@ class BasketModal extends Widget } - return $this->render('busket_modal',[ + return $this->render('basket_modal',[ 'items'=>$sessionData, 'count' => $count, 'price' => $price diff --git a/common/widgets/views/basket_head.php b/common/widgets/views/basket_head.php new file mode 100644 index 0000000..34f8043 --- /dev/null +++ b/common/widgets/views/basket_head.php @@ -0,0 +1,10 @@ + +
+ +
+
'head_basket_count']) :'' ?>
+
+ +
diff --git a/common/widgets/views/basket_modal.php b/common/widgets/views/basket_modal.php new file mode 100644 index 0000000..2ed0e5f --- /dev/null +++ b/common/widgets/views/basket_modal.php @@ -0,0 +1,53 @@ + +
+ +
+
+

:

+

: грн.

+
+
+ 'close']) ?> + 'button']);?> +
+
diff --git a/common/widgets/views/busket_modal.php b/common/widgets/views/busket_modal.php deleted file mode 100644 index 2ed0e5f..0000000 --- a/common/widgets/views/busket_modal.php +++ /dev/null @@ -1,53 +0,0 @@ - -
- -
-
-

:

-

: грн.

-
-
- 'close']) ?> - 'button']);?> -
-
diff --git a/console/migrations/m160331_122305_template_location.php b/console/migrations/m160331_122305_template_location.php new file mode 100644 index 0000000..92ea718 --- /dev/null +++ b/console/migrations/m160331_122305_template_location.php @@ -0,0 +1,27 @@ +createTable('{{%template_location}}', [ + 'template_location_id' => $this->primaryKey(), + 'template_location_name' => $this->string(255)->notNull(), + 'template_location_title' => $this->string(255), + 'width' => $this->integer(4)->notNull(), + 'height' => $this->integer(4)->notNull(), + 'sort' => $this->integer(6)->notNull(), + 'is_slider' => $this->smallInteger(1), + 'is_banner' => $this->smallInteger(1), + ]); + } + + public function down() + { + $this->dropTable('{{%template_location}}'); + } + + +} diff --git a/console/migrations/m160331_132149_slider.php b/console/migrations/m160331_132149_slider.php new file mode 100644 index 0000000..c138b38 --- /dev/null +++ b/console/migrations/m160331_132149_slider.php @@ -0,0 +1,27 @@ +createTable('{{%slider}}', [ + 'slider_id' => $this->primaryKey(), + 'template_location_id' => $this->integer(4)->notNull(), + 'speed' => $this->integer(4), + 'duration' => $this->integer(4), + 'title' => $this->string(200), + 'status' => $this->smallInteger(1), + ]); + $this->addForeignKey('template_location_slider_fk', 'template_location', 'template_location_id', 'slider', 'template_location_id', 'CASCADE', 'CASCADE'); + } + + public function down() + { + //$this->dropForeignKey('template_location_slider_fk', '{{%template_location}}'); + $this->dropTable('{{%slider}}'); + } + + +} diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 77d7c60..9f53ae1 100644 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -4,6 +4,7 @@ /* @var $content string */ +use common\widgets\BasketHead; use common\widgets\BasketModal; use frontend\assets\AppAsset; use yii\helpers\Html; @@ -68,14 +69,7 @@ AppAsset::register($this);
Звоните с 9.00 до 18.00 по будням
- -
- -
-
Корзина
-
- -
+ diff --git a/frontend/web/css/concat_all.css b/frontend/web/css/concat_all.css index 7f38f76..2c88100 100644 --- a/frontend/web/css/concat_all.css +++ b/frontend/web/css/concat_all.css @@ -5,6 +5,8 @@ .w_960 { width: 960px; margin: auto; + overflow: hidden; + } .cat_p_bradcrump { @@ -1013,7 +1015,7 @@ hr { .item_3_blocks_wrap .busket_block .quick_order form .quick_order_phone { font-size: 12px; color: #333333; - padding: 9px; + padding: 10px; border: 1px solid #C6C7C9; -webkit-border-radius: 2px; border-radius: 2px; @@ -3227,4 +3229,8 @@ span.red { .product_service ul li.item3 { background: url('/images/li3.png') left no-repeat; padding: 3px 23px; +} + +.head_basket_count{ + color:#6aa033; } \ No newline at end of file diff --git a/frontend/web/js/basket.js b/frontend/web/js/basket.js index c943b3b..1fb7e4b 100644 --- a/frontend/web/js/basket.js +++ b/frontend/web/js/basket.js @@ -3,6 +3,18 @@ $(document).ready(function(){ var result_block = $('.basket_result'); var one_item_block = $('.busket_block'); + function countItems(){ + var length = $('.busket_modal_01').find('.order_list_li').length; + if(length >= 1){ + $('.head_basket_count').html(length); + $('.all_count').html(length); + } else { + $('.head_basket_count').html(''); + $('.all_count').html(''); + } + } + + function changeAjaxPrice(id, num){ $.post( "/orders/buy-items", {id: id, num:num}, function( data ) { @@ -23,8 +35,10 @@ $(document).ready(function(){ var id = $(this).data('id'); $.post( "/orders/buy-items", {id: id, num:1}, function( data ) { $('.basket_result').each(function(){ - $(this).html(data) + $(this).html(data); + countItems(); }); + }); }); @@ -54,7 +68,7 @@ $(document).ready(function(){ block.remove(); }); countPrise(forCount); - + countItems(); -- libgit2 0.21.4