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 @@ + +
= Yii::t('app','articles')?>: = $count ?>
+= Yii::t('app','sum')?>: = $price ?> грн.
+= Yii::t('app','articles')?>: = $count ?>
-= Yii::t('app','sum')?>: = $price ?> грн.
-