diff --git a/bin/css/style.css b/bin/css/style.css index 5cc013633102d3aa92f8ab310254c48e300e2702..d3384f6e176a98a4d071a178197dfcc1522a7f51 100644 --- a/bin/css/style.css +++ b/bin/css/style.css @@ -528,6 +528,13 @@ a.toTop:before { visibility: hidden; /* jumping fix */ } +.tobpar--separator { + margin-inline: 0.5em; + height: 1.25em; + width: 1px; + background: #ddd; +} + .topbar-left, .topbar-left > p { align-items: center; @@ -595,6 +602,24 @@ a.toTop:before { } } +/******************************/ +/* LanguageSwitches\DropDown */ +/******************************/ +.topbar-right > .quiqqer-bricks-languageswitch-dropdown { + height: 100%; +} + +/* +1. because `.cologne-header` has z-index 99, we must set this control to 100 +*/ +.topbar-right > .quiqqer-bricks-languageswitch-dropdown > .quiqqer-control-languageswitch-dropdown { + position: relative; + z-index: 100; /* 1 */ + display: flex; + align-items: center; + height: 100%; +} + /***************************/ /* template product search */ /***************************/ diff --git a/bin/javascript/controls/LangCurrencySwitch.js b/bin/javascript/controls/LangCurrencySwitch.js index 76b0cdb6cb04fc6e42616938a3d68af3c4d72938..7d967cdd640009d1065688c98c891be4f4937be0 100644 --- a/bin/javascript/controls/LangCurrencySwitch.js +++ b/bin/javascript/controls/LangCurrencySwitch.js @@ -88,7 +88,7 @@ define('package/quiqqer/template-cologne/bin/javascript/controls/LangCurrencySwi return new Promise(function (resolve) { - // save ajax request if the variable is set + // do not send ajax request if the variable is set if (COUNT_LANGUAGES) { if (COUNT_LANGUAGES <= 1) { self.langSwitch = false; diff --git a/index.php b/index.php index 072e27b19fdf6881616592a61870590467bcbd8c..300ee5f640873188b6b35e77f1edc674374b837b 100644 --- a/index.php +++ b/index.php @@ -110,7 +110,8 @@ /** * Lang currency swtich control */ -$LangCurrencySwitch = new \QUI\TemplateCologne\Controls\LangCurrencySwitch(); +//$LangCurrencySwitch = new \QUI\TemplateCologne\Controls\LangCurrencySwitch(); +$LangCurrencySwitch = null; /** * Sign up / registration page diff --git a/src/QUI/TemplateCologne/Controls/CurrencySwitch.css b/src/QUI/TemplateCologne/Controls/CurrencySwitch.css new file mode 100644 index 0000000000000000000000000000000000000000..85fa4fb203f8f65d3dc7370e735423b81cc364d5 --- /dev/null +++ b/src/QUI/TemplateCologne/Controls/CurrencySwitch.css @@ -0,0 +1,115 @@ +.currency-switch { + align-items: center; + display: inline-flex; + height: 100%; + position: relative; +} + +.lcs-button { + cursor: pointer; + white-space: nowrap; +} + +.lcs-button.lcs-button__no-hover { + cursor: default; +} + +.lcs-button.lcs-button__no-hover:hover { + color: inherit; +} + +.lcs-button.lcs-button__no-hover:hover .lcs-button-currency-code.text-muted { + color: #9ba3ad; +} + +.lcs-button.lcs-button__no-hover .fa { + display: none; +} + +.lcs-button-flag { + border-right: 1px solid #ddd; + padding: 0 1rem; +} + +.lcs-button-currency { + font-weight: 300; + margin: 0 1rem; +} + +.lcs-button-currency-sign { + +} + +/* loader */ +.qui-loader-inner > div { + align-items: center; + display: flex; + justify-content: center; +} + +.qui-loader-inner .qui-loader-inner-fa-circle-o-notch .fa-spin, +.qui-loader-inner .qui-loader-inner-fa-gear .fa-spin, +.qui-loader-inner .qui-loader-inner-fa-refresh .fa-spin, +.qui-loader-inner .qui-loader-inner-fa-spinner .fa-spin { + font-size: 1.5rem; + position: initial; + top: 0; +} + +/********/ +/* menu */ +/********/ +.lcs-menu-wrapper { + bottom: 0; + position: absolute; + right: 0; +} + +.lcs-menu { + background: #fff; + border: 1px solid rgb(221, 221, 221); + box-shadow: 0 7px 22px -5px rgba(48, 60, 72, 0.2); + min-width: 200px; + padding: 16px 20px; + position: absolute; + right: 0; + z-index: 1001; +} + +.lcs-menu:focus { + border: 1px solid red !important; +} + +/* currency */ +.lcs-menu .quiqqer-currency-switch { + border: 1px solid #ddd; + border-radius: 0.25rem; + display: flex; + float: none; + position: relative; + /*line-height: 40px;*/ + /*height: 40px;*/ +} + +.quiqqer-currency-switch.button { + align-items: center; + display: flex; + padding: 0 10px; + width: 100%; +} + +.quiqqer-currency-switch .quiqqer-currency-switch-arrow { + margin-left: auto; + position: initial; +} + +/* currency */ +.quiqqer-currency-switch-dd { + border: 1px solid rgb(221, 221, 221) !important; + box-shadow: 0 7px 22px -5px rgba(48, 60, 72, 0.2) !important; + display: none; +} + +.quiqqer-currency-switch-dd:after { + display: none; +} \ No newline at end of file diff --git a/src/QUI/TemplateCologne/Controls/CurrencySwitch.html b/src/QUI/TemplateCologne/Controls/CurrencySwitch.html new file mode 100644 index 0000000000000000000000000000000000000000..3d445797653bd1ec78589f1d17c23f2ec3f039bc --- /dev/null +++ b/src/QUI/TemplateCologne/Controls/CurrencySwitch.html @@ -0,0 +1,14 @@ +<div class="lcs-button"> + {if $currencySwitch} + <span class="lcs-button-currency" title="{$DefaultCurrency->getText()}"> + <span class="lcs-button-currency-sign">{$DefaultCurrency->getSign()}</span> + <span class="lcs-button-currency-code text-muted">{$DefaultCurrency->getCode()}</span> + </span> + {/if} + + {if $enableChange} + <span class="fa fa-caret-down"></span> + {/if} +</div> + +<div class="lcs-menu-wrapper"></div> \ No newline at end of file diff --git a/src/QUI/TemplateCologne/Controls/CurrencySwitch.php b/src/QUI/TemplateCologne/Controls/CurrencySwitch.php new file mode 100644 index 0000000000000000000000000000000000000000..7ea23846077e4f99d88c3dc32500ad71079d8152 --- /dev/null +++ b/src/QUI/TemplateCologne/Controls/CurrencySwitch.php @@ -0,0 +1,106 @@ +<?php + +/** + * This file contains QUI\TemplateCologne\Controls\CurrencySwitch + */ + +namespace QUI\TemplateCologne\Controls; + +use QUI; + +/** + * Class LangCurrencySwitch + */ +class CurrencySwitch extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = []) + { + $this->setAttributes([ + 'class' => 'currency-switch', +// 'data-qui' => 'package/quiqqer/template-cologne/bin/javascript/controls/CurrencySwitch', + 'userRelatedCurrency' => 1, // 1 / 0 -> is user allowed to change currency? + ]); + + $this->addCSSFile(dirname(__FILE__) . '/CurrencySwitch.css'); + + parent::__construct($attributes); + } + + /** + * (non-PHPdoc) + * + * @throws QUI\Exception + * @see \QUI\Control::create() + * + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $enableChange = false; + + // is user allowed to change currency? + $currencySwitch = false; + $userrelatedcurrency = 0; + + if ($this->isCurrencySwitchAllowed()) { + try { + $Package = QUI::getPackage('quiqqer/erp'); + $Config = $Package->getConfig(); + + if ($Config->getValue('general', 'userRelatedCurrency')) { + $userrelatedcurrency = 1; + $currencySwitch = true; + } + } catch (QUI\Exception $Exception) { + QUI\System\Log::writeException($Exception); + } + } + $this->setJavaScriptControlOption('userrelatedcurrency', $userrelatedcurrency); + + + if ($currencySwitch) { + $enableChange = true; + } + + $Currency = QUI\ERP\Currency\Handler::getDefaultCurrency(); + + if (QUI\ERP\Currency\Handler::getUserCurrency()) { + $Currency = QUI\ERP\Currency\Handler::getUserCurrency(); + } + + $Engine->assign([ + 'this' => $this, + 'currencySwitch' => $currencySwitch, + 'DefaultCurrency' => $Currency, + 'enableChange' => $enableChange + ]); + + return $Engine->fetch(dirname(__FILE__) . '/CurrencySwitch.html'); + } + + /** + * Is currency switch allowed? Setting has over currencies number. + * + * @return bool + * @throws QUI\Exception + */ + protected function isCurrencySwitchAllowed() + { + if (!$this->getAttribute('userRelatedCurrency')) { + return false; + } + + $currencies = QUI\ERP\Currency\Handler::getAllowedCurrencies(); + + if (count($currencies) > 1) { + return true; + } + + return false; + } +} diff --git a/template/topBar.html b/template/topBar.html index 765df434fd026e40247477e47f7df64d2779ebd6..96aea3f8b564604f564fa6aaa52dac7400b4ad4d 100644 --- a/template/topBar.html +++ b/template/topBar.html @@ -10,7 +10,13 @@ </div> {* language & currency switch *} - {$LangCurrencySwitch->create()} + {if false} + {$LangCurrencySwitch->create()} + {else} + {control control="\QUI\Bricks\Controls\LanguageSwitches\DropDown" showArrow=false} + <span class="tobpar--separator"></span> + {control control="QUI\TemplateCologne\Controls\CurrencySwitch"} + {/if} <span class="cologne-header-control-user"> {if $User->getId()}