diff --git a/index.php b/index.php index 21b651269ba1eecb33e459f2656215bf02f2271f..a49e56fec0764332379ba4b0900bd272e4185675 100644 --- a/index.php +++ b/index.php @@ -20,9 +20,9 @@ * Menu */ $menuParams = [ - 'showStart' => false, + 'showStart' => false, 'data-show-button-on-desktop' => 1, - 'Project' => $Site->getProject() + 'Project' => $Site->getProject() ]; if (isset($templateSettings['homeLink']) && $templateSettings['homeLink']) { @@ -33,10 +33,13 @@ $menuParams['startText'] = $templateSettings['homeLinkText']; } -if ($Project->getConfig('templateCologne.settings.enableIndependentMenu') && $Project->getConfig('templateCologne.settings.menuId')) { - $menuParams['menuId'] = $Project->getConfig('templateCologne.settings.menuId'); +$enableIndependentMenu = $Project->getConfig('templateCologne.settings.enableIndependentMenu'); +$independentMenuId = $Project->getConfig('templateCologne.settings.menuId'); + +if ($enableIndependentMenu && $independentMenuId) { + $menuParams['menuId'] = $enableIndependentMenu; $menuParams['showFirstLevelIcons'] = $Project->getConfig('templateCologne.settings.showFirstLevelIcons'); - $menuParams['showStart'] = false; + $menuParams['showStart'] = false; } // Site own / independent menu @@ -56,20 +59,22 @@ } $createBasketButton = true; +$simpleSiteTypes = [ + 'quiqqer/order:types/orderingProcess', + 'quiqqer/order:types/shoppingCart', + 'quiqqer/order-simple-checkout:types/simpleCheckout', +]; -if ($Site->getAttribute('type') == 'quiqqer/order:types/orderingProcess' || - $Site->getAttribute('type') == 'quiqqer/order:types/shoppingCart' || - $Site->getAttribute('type') == 'quiqqer/order-simple-checkout:types/simpleCheckout') { +if (in_array($Site->getAttribute('type'), $simpleSiteTypes)) { $createBasketButton = false; - $Template->setAttribute('content-header', false); } $InitialBasketPrice = new QUI\ERP\Money\Price(0, $Currency); -$Logo = $Project->getMedia()->getLogoImage(); +$Logo = $Project->getMedia()->getLogoImage(); $logoHeight = $templateSettings['logoHeight']; -$logoWidth = false; +$logoWidth = false; try { if ($Logo) { @@ -79,9 +84,9 @@ QUI\System\Log::addNotice($Exception->getMessage()); } -$templateSettings['Logo'] = $Logo; -$templateSettings['logoHeight'] = $logoHeight; -$templateSettings['logoWidth'] = $logoWidth; +$templateSettings['Logo'] = $Logo; +$templateSettings['logoHeight'] = $logoHeight; +$templateSettings['logoWidth'] = $logoWidth; $templateSettings['initialBasketPrice'] = $InitialBasketPrice->getDisplayPrice(); $templateSettings['createBasketButton'] = $createBasketButton; @@ -104,27 +109,24 @@ * Flags */ $Flags = new QUI\Bricks\Controls\LanguageSwitches\Flags([ - 'Site' => $Site, + 'Site' => $Site, 'showFlags' => true, - 'showText' => true, - 'all' => true + 'showText' => true, + 'all' => true ]); - /** * Langguage and currency swtich */ //$LangCurrencySwitch = new \QUI\TemplateCologne\Controls\LangCurrencySwitch(); $LangCurrencySwitch = null; - - /** * Sign up / registration page */ $registerSiteUrl = false; -$types = [ +$registerSiteTypes = [ 'quiqqer/frontend-users:types/registrationSignUp', 'quiqqer/frontend-users:types/registration', ]; @@ -133,7 +135,7 @@ 'where' => [ 'type' => [ 'type' => 'IN', - 'value' => $types + 'value' => $registerSiteTypes ] ], 'limit' => 1 @@ -145,18 +147,18 @@ } // array to assign -$templateSettings['BricksManager'] = QUI\Bricks\Manager::init(); -$templateSettings['Project'] = $Project; -$templateSettings['Menu'] = $Menu; -$templateSettings['Avatar'] = $Avatar; -$templateSettings['productPage'] = $productPage; -$templateSettings['Flags'] = $Flags; +$templateSettings['BricksManager'] = QUI\Bricks\Manager::init(); +$templateSettings['Project'] = $Project; +$templateSettings['Menu'] = $Menu; +$templateSettings['Avatar'] = $Avatar; +$templateSettings['productPage'] = $productPage; +$templateSettings['Flags'] = $Flags; $templateSettings['LangCurrencySwitch'] = $LangCurrencySwitch; -$templateSettings['countLanguages'] = \count($Project->getLanguages()); -$templateSettings['Search'] = new QUI\ERP\Products\Search\Controls\Suggest([ +$templateSettings['countLanguages'] = \count($Project->getLanguages()); +$templateSettings['Search'] = new QUI\ERP\Products\Search\Controls\Suggest([ 'globalsearch' => true ]); -$templateSettings['registerSiteUrl'] = $registerSiteUrl; +$templateSettings['registerSiteUrl'] = $registerSiteUrl; $Template->setAttributes($templateSettings); diff --git a/src/QUI/TemplateCologne/Controls/CurrencySwitch.php b/src/QUI/TemplateCologne/Controls/CurrencySwitch.php index e447122ee59c825aec8b622458055fdc37bff395..c1c124227cefb29e8912ea7618ff2e31fe323afc 100644 --- a/src/QUI/TemplateCologne/Controls/CurrencySwitch.php +++ b/src/QUI/TemplateCologne/Controls/CurrencySwitch.php @@ -21,11 +21,11 @@ class CurrencySwitch extends QUI\Control public function __construct($attributes = []) { $this->setAttributes([ - 'class' => 'quiqqer-currency-switch', + 'class' => 'quiqqer-currency-switch', 'userRelatedCurrency' => 1, // 1 / 0 -> is user allowed to change currency? ]); - $this->addCSSFile(dirname(__FILE__).'/CurrencySwitch.css'); + $this->addCSSFile(dirname(__FILE__) . '/CurrencySwitch.css'); parent::__construct($attributes); } @@ -51,7 +51,7 @@ public function getBody() if ($this->isCurrencySwitchAllowed()) { try { $Package = QUI::getPackage('quiqqer/erp'); - $Config = $Package->getConfig(); + $Config = $Package->getConfig(); if ($Config->getValue('general', 'userRelatedCurrency')) { $this->setJavaScriptControl('package/quiqqer/currency/bin/controls/Switch'); @@ -68,11 +68,11 @@ public function getBody() } $Engine->assign([ - 'this' => $this, + 'this' => $this, 'DefaultCurrency' => $Currency, ]); - return $Engine->fetch(dirname(__FILE__).'/CurrencySwitch.html'); + return $Engine->fetch(dirname(__FILE__) . '/CurrencySwitch.html'); } /** diff --git a/src/QUI/TemplateCologne/Controls/Menu/Categories.php b/src/QUI/TemplateCologne/Controls/Menu/Categories.php index 92bb4a1cf235d6ba9d88453bca5520dca2146a72..53885961b9d14550db30b57d4589fd377071be79 100644 --- a/src/QUI/TemplateCologne/Controls/Menu/Categories.php +++ b/src/QUI/TemplateCologne/Controls/Menu/Categories.php @@ -27,16 +27,16 @@ class Categories extends QUI\Control public function __construct($attributes = []) { $this->setAttributes([ - 'class' => 'quiqqer-categories-menu', - 'startId' => 1, // site id or site link where menu starts by. 1 is start page (first project page) - 'template' => \dirname(__FILE__).'/Categories.html', // nav wrapper - 'menuFile' => \dirname(__FILE__).'/Categories.Menu.html', // contains children (sites), - 'jsControl' => 'package/quiqqer/template-cologne/bin/javascript/controls/Menu/Categories', - 'showDescFor' => 'all', // Show category description: all / firstLevel / none + 'class' => 'quiqqer-categories-menu', + 'startId' => 1, // site id or site link where menu starts by. 1 is start page (first project page) + 'template' => \dirname(__FILE__) . '/Categories.html', // nav wrapper + 'menuFile' => \dirname(__FILE__) . '/Categories.Menu.html', // contains children (sites), + 'jsControl' => 'package/quiqqer/template-cologne/bin/javascript/controls/Menu/Categories', + 'showDescFor' => 'all', // Show category description: all / firstLevel / none 'showBasketButton' => false ]); - $this->addCSSFile(\dirname(__FILE__).'/Categories.css'); + $this->addCSSFile(\dirname(__FILE__) . '/Categories.css'); parent::__construct($attributes); } @@ -47,7 +47,7 @@ public function __construct($attributes = []) */ public function getBody() { - $Engine = QUI::getTemplateManager()->getEngine(); + $Engine = QUI::getTemplateManager()->getEngine(); $Project = $this->getProject(); @@ -66,10 +66,10 @@ public function getBody() return ''; } - $cache = EventHandler::menuCacheName().'/megaMenu/'; + $cache = EventHandler::menuCacheName() . '/megaMenu/'; $cache .= \md5( - $this->getSite()->getCachePath(). + $this->getSite()->getCachePath() . \serialize($this->getAttributes()) ); @@ -85,12 +85,12 @@ public function getBody() } $Engine->assign([ - 'menuFile' => $this->getAttribute('menuFile'), - 'this' => $this, - 'showDescFor' => $this->getAttribute('showDescFor'), + 'menuFile' => $this->getAttribute('menuFile'), + 'this' => $this, + 'showDescFor' => $this->getAttribute('showDescFor'), 'showBasketButton' => $showBasketButton, - 'Site' => $Site, - 'Project' => $Project + 'Site' => $Site, + 'Project' => $Project ]); $result = $Engine->fetch($this->getAttribute('template')); diff --git a/src/QUI/TemplateCologne/Controls/Payments.php b/src/QUI/TemplateCologne/Controls/Payments.php index d9178e1078048696a0aeda0c69574533acf53eb2..96d6e7834dfedf088a4756a79d10caf303fbad88 100644 --- a/src/QUI/TemplateCologne/Controls/Payments.php +++ b/src/QUI/TemplateCologne/Controls/Payments.php @@ -26,13 +26,13 @@ class Payments extends QUI\Control public function __construct($attributes = []) { $this->setAttributes([ - 'class' => 'quiqqer-payments-control', - 'showInactive' => false, - 'template' => 'list', + 'class' => 'quiqqer-payments-control', + 'showInactive' => false, + 'template' => 'list', // Custom children template (path to html file); overwrites "template". 'customTemplate' => false, // Custom children template css (path to css file); overwrites "template". - 'customCss' => false, + 'customCss' => false, ]); parent::__construct($attributes); @@ -51,7 +51,7 @@ public function getBody() return ''; } - $Engine = QUI::getTemplateManager()->getEngine(); + $Engine = QUI::getTemplateManager()->getEngine(); $Payments = \QUI\ERP\Accounting\Payments\Payments::getInstance(); $payments = $Payments->getpayments(); @@ -62,17 +62,16 @@ public function getBody() } $Engine->assign([ - 'payments' => $payments, + 'payments' => $payments, 'showInactive' => $this->getAttribute('showInactive') ]); // load custom template (if set) - if ($this->getAttribute('customTemplate') - && \file_exists($this->getAttribute('customTemplate')) - ) { - if ($this->getAttribute('customCss') - && \file_exists($this->getAttribute('customCss')) - ) { + $customTemplate = $this->getAttribute('customTemplate'); + $customCss = $this->getAttribute('customCss'); + + if ($customTemplate && \file_exists($customTemplate)) { + if ($customCss && \file_exists($customCss)) { $this->addCSSFile($this->getAttribute('customCss')); } @@ -83,12 +82,12 @@ public function getBody() switch ($this->getAttribute('template')) { case 'list': $template = dirname(__FILE__) . '/Payments.List.html'; - $css = dirname(__FILE__) . '/Payments.List.css'; + $css = dirname(__FILE__) . '/Payments.List.css'; break; case 'grid': default: $template = dirname(__FILE__) . '/Payments.Grid.html'; - $css = dirname(__FILE__) . '/Payments.Grid.css'; + $css = dirname(__FILE__) . '/Payments.Grid.css'; } $this->addCSSFile($css); diff --git a/src/QUI/TemplateCologne/Controls/ProductGallery.php b/src/QUI/TemplateCologne/Controls/ProductGallery.php index e8a5500701e2048b6724b682b42e0526ef7b6cb3..8a7386096c59739e2955f2e375f3fe333639fe81 100644 --- a/src/QUI/TemplateCologne/Controls/ProductGallery.php +++ b/src/QUI/TemplateCologne/Controls/ProductGallery.php @@ -8,6 +8,7 @@ use QUI; use QUI\ERP\Products\Handler\Fields; + use function is_a; use function usort; @@ -43,7 +44,7 @@ public function getBody() return ''; } - $Engine = QUI::getTemplateManager()->getEngine(); + $Engine = QUI::getTemplateManager()->getEngine(); $Product = $this->getAttribute('Product'); $Gallery = new QUI\Gallery\Controls\Slider(); @@ -52,7 +53,7 @@ public function getBody() } $typeVariantParent = is_a($Product->getType(), QUI\ERP\Products\Product\Types\VariantParent::class, true); - $typeVariantChild = is_a($Product->getType(), QUI\ERP\Products\Product\Types\VariantChild::class, true); + $typeVariantChild = is_a($Product->getType(), QUI\ERP\Products\Product\Types\VariantChild::class, true); // gallery $PlaceholderImage = $this->getProject()->getMedia()->getPlaceholderImage(); @@ -100,7 +101,7 @@ public function getBody() 'Gallery' => $Gallery, ]); - return $Engine->fetch(dirname(__FILE__).'/ProductGallery.html'); + return $Engine->fetch(dirname(__FILE__) . '/ProductGallery.html'); } /** @@ -109,6 +110,7 @@ public function getBody() * By @peat * * @param QUI\ERP\Products\Product\Product $Product + * * @return QUI\Projects\Media\Image[] */ protected function getVariantImages(QUI\ERP\Products\Product\Product $Product): array @@ -116,8 +118,8 @@ protected function getVariantImages(QUI\ERP\Products\Product\Product $Product): $images = $Product->getImages(); try { - $MainImage = $Product->getImage(); - $mainImageId = $MainImage->getId(); + $MainImage = $Product->getImage(); + $mainImageId = $MainImage->getId(); $hasMainImage = false; foreach ($images as $Image) { diff --git a/src/QUI/TemplateCologne/Controls/SimpleUserInfo.php b/src/QUI/TemplateCologne/Controls/SimpleUserInfo.php index 7626e141e6d99310ca0d4d12c2c93a59944e79e7..f33ce894d3b7de0fd042087039c1c020c4d5cb34 100644 --- a/src/QUI/TemplateCologne/Controls/SimpleUserInfo.php +++ b/src/QUI/TemplateCologne/Controls/SimpleUserInfo.php @@ -24,7 +24,7 @@ public function __construct($attributes = []) 'User' => null ]); - $this->addCSSFile(dirname(__FILE__).'/SimpleUserInfo.css'); + $this->addCSSFile(dirname(__FILE__) . '/SimpleUserInfo.css'); parent::__construct($attributes); } @@ -32,14 +32,13 @@ public function __construct($attributes = []) /** * (non-PHPdoc) * - * @see \QUI\Control::create() - * * @throws QUI\Exception + * @see \QUI\Control::create() */ public function getBody() { $Engine = QUI::getTemplateManager()->getEngine(); - $User = $this->getUser(); + $User = $this->getUser(); $avatarUrl = URL_OPT_DIR . 'quiqqer/template-cologne/bin/images/avatar-placeholder.svg'; @@ -48,9 +47,9 @@ public function getBody() } $Engine->assign([ - 'name' => $User->getName(), + 'name' => $User->getName(), 'registrationDay' => $User->getAttribute('regdate'), - 'avatarUrl' => $avatarUrl, + 'avatarUrl' => $avatarUrl, 'ordersNumber' => $this->getOrdersNumber($User) ]); @@ -100,6 +99,7 @@ public function getSite() * Get number of orders * * @param $User QUI\Interfaces\Users\User + * * @return int */ public function getOrdersNumber($User) diff --git a/src/QUI/TemplateCologne/EventHandler.php b/src/QUI/TemplateCologne/EventHandler.php index 73ccff1d8b2cc994b00bbefdb41dd4e23129b4fa..17c1f0102a1b76af1df5fa343f26293450d101d9 100644 --- a/src/QUI/TemplateCologne/EventHandler.php +++ b/src/QUI/TemplateCologne/EventHandler.php @@ -1,4 +1,5 @@ <?php + /** * This file contains \QUI\TemplateCologne\EventHandler */ @@ -48,8 +49,10 @@ public static function onSiteSave() * * @throws QUI\Exception */ - public static function onQuiqqerProductsProductButtonsEnd(\Quiqqer\Engine\Collector $Collector, \QUI\ERP\Products\Product\ViewFrontend $Product) - { + public static function onQuiqqerProductsProductButtonsEnd( + \Quiqqer\Engine\Collector $Collector, + \QUI\ERP\Products\Product\ViewFrontend $Product + ) { // setting $Project = QUI::getRewrite()->getProject(); @@ -57,7 +60,7 @@ public static function onQuiqqerProductsProductButtonsEnd(\Quiqqer\Engine\Collec return; } - $text = QUI::getLocale()->get('quiqqer/template-cologne', 'control.product.buy.know.button'); + $text = QUI::getLocale()->get('quiqqer/template-cologne', 'control.product.buy.know.button'); $disabled = 0; if (!$Product->getMaximumQuantity()) { @@ -65,11 +68,11 @@ public static function onQuiqqerProductsProductButtonsEnd(\Quiqqer\Engine\Collec } $Collector->append( - '<div class="product-data-actionButtons-buyNow" data-qui-options-disabled="'.$disabled.'"> + '<div class="product-data-actionButtons-buyNow" data-qui-options-disabled="' . $disabled . '"> <div class="product-data-actionButtons-buyNow-placeholder"></div> <button disabled data-qui="package/quiqqer/template-cologne/bin/javascript/controls/BuyNowButton" - data-qui-options-disabled="'.$disabled.'"> - <span class="add-to-basket-text">'.$text.'</span> + data-qui-options-disabled="' . $disabled . '"> + <span class="add-to-basket-text">' . $text . '</span> </button> </div>' ); diff --git a/src/QUI/TemplateCologne/Utils.php b/src/QUI/TemplateCologne/Utils.php index d001196ab8ce65122773c7df2ecdf333d4a771ae..81475da826351dffeea5bbc754767cf453ff48b5 100644 --- a/src/QUI/TemplateCologne/Utils.php +++ b/src/QUI/TemplateCologne/Utils.php @@ -76,7 +76,7 @@ public static function getConfig($params) /* @var $Project QUI\Template */ $Template = $params['Template']; - $cacheName = md5($params['Site']->getId() . $Project->getName() . $Project->getLang()); + $cacheName = md5($Site->getId() . $Project->getName() . $Project->getLang()); try { return QUI\Cache\Manager::get( @@ -92,7 +92,6 @@ public static function getConfig($params) /** * Logo height */ - $logoHeight = 60; if (intval($Project->getConfig('templateCologne.settings.logoHeight'))) { @@ -158,10 +157,13 @@ public static function getConfig($params) break; } - if ($Site->getAttribute('type') === 'quiqqer/order:types/orderingProcess' - || $Site->getAttribute('type') === 'quiqqer/order:types/shoppingCart' - || $Site->getAttribute('type') === 'quiqqer/order-simple-checkout:types/simpleCheckout' - ) { + $orderSiteTypes = [ + 'quiqqer/order:types/orderingProcess', + 'quiqqer/order:types/shoppingCart', + 'quiqqer/order-simple-checkout:types/simpleCheckout' + ]; + + if (in_array($Site->getAttribute('type'), $orderSiteTypes)) { switch ($Project->getConfig('templateCologne.settings.checkoutAppearance')) { case 'compact': $showBreadcrumb = false; @@ -278,16 +280,14 @@ public static function getConfig($params) /** * Menu appearance and smooth scroll */ + $showNavAfterScrollSetting = intval($Project->getConfig('templateCologne.settings.showNavAfterScroll')); $showNavAfterScroll = 0; $showMenuSmooth = false; // smooth animation - $setMenuPosBackOnInit - = false; // if true menu will be no longer fixed when user scrolls to menu initial position - if ($Project->getConfig('templateCologne.settings.showNavAfterScroll') - && intval( - $Project->getConfig('templateCologne.settings.showNavAfterScroll') - ) > 0 - ) { - $showNavAfterScroll = intval($Project->getConfig('templateCologne.settings.showNavAfterScroll')); + // if true menu will be no longer fixed when user scrolls to menu initial position + $setMenuPosBackOnInit = false; + + if ($showNavAfterScrollSetting && $showNavAfterScrollSetting > 0) { + $showNavAfterScroll = $showNavAfterScrollSetting; $showMenuSmooth = true; } @@ -295,17 +295,11 @@ public static function getConfig($params) $setMenuPosBackOnInit = true; } - /* page custom class */ - $pageCustomClass = false; + $pageCustomClass = $Site->getAttribute('templateCologne.pageCustomClass'); - if ($Site->getAttribute('templateCologne.pageCustomClass') - && $Site->getAttribute( - 'templateCologne.pageCustomClass' - ) !== '' - ) { - $pageCustomClass = 'templateCologne__' . $Site->getAttribute('templateCologne.pageCustomClass'); - $pageCustomClass .= ' ' . $Site->getAttribute('templateCologne.pageCustomClass'); + if ($pageCustomClass && $pageCustomClass !== '') { + $pageCustomClass .= 'templateCologne__' . $pageCustomClass; } /** @@ -556,10 +550,9 @@ private static function getPredefinedFooter($Project) /** Predefined footer: Payments Control */ $paymentsData = []; - if ($Project->getConfig('templateCologne.settings.predefinedFooter.payments') - && \class_exists( - '\QUI\ERP\Accounting\Payments\Payments' - ) + if ( + $Project->getConfig('templateCologne.settings.predefinedFooter.payments') + && \class_exists('\QUI\ERP\Accounting\Payments\Payments') ) { $PaymentsControl = new \QUI\TemplateCologne\Controls\Payments([ 'template' => $Project->getConfig('templateCologne.settings.predefinedFooter.payments.layout')