From 5e0505cf05a39fd2d4858abac84df70342386eb7 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Wed, 20 Jun 2012 15:38:08 +0000 Subject: [PATCH] [-] MO: Blocktopmenu add links to shop git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@16101 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/shop/Shop.php | 46 +++++++++++++++------------ modules/blocktopmenu/blocktopmenu.php | 37 +++++++++++++++++---- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index e99eac49c..92010de20 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -165,27 +165,33 @@ class ShopCore extends ObjectModel { parent::__construct($id, $id_lang, $id_shop); if ($this->id) - { - $sql = 'SELECT su.physical_uri, su.virtual_uri, - su.domain, su.domain_ssl, t.id_theme, t.name, t.directory - FROM '._DB_PREFIX_.'shop s - LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop) - LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme) - WHERE s.id_shop = '.(int)$this->id.' - AND s.active = 1 - AND s.deleted = 0 - AND su.main = 1'; - if (!$row = Db::getInstance()->getRow($sql)) - return; + $this->setUrl(); + } - $this->theme_id = $row['id_theme']; - $this->theme_name = $row['name']; - $this->theme_directory = $row['directory']; - $this->physical_uri = $row['physical_uri']; - $this->virtual_uri = $row['virtual_uri']; - $this->domain = $row['domain']; - $this->domain_ssl = $row['domain_ssl']; - } + public function setUrl() + { + $sql = 'SELECT su.physical_uri, su.virtual_uri, + su.domain, su.domain_ssl, t.id_theme, t.name, t.directory + FROM '._DB_PREFIX_.'shop s + LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop) + LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme) + WHERE s.id_shop = '.(int)$this->id.' + AND s.active = 1 + AND s.deleted = 0 + AND su.main = 1'; + + if (!$row = Db::getInstance()->getRow($sql)) + return; + + $this->theme_id = $row['id_theme']; + $this->theme_name = $row['name']; + $this->theme_directory = $row['directory']; + $this->physical_uri = $row['physical_uri']; + $this->virtual_uri = $row['virtual_uri']; + $this->domain = $row['domain']; + $this->domain_ssl = $row['domain_ssl']; + + return true; } /** diff --git a/modules/blocktopmenu/blocktopmenu.php b/modules/blocktopmenu/blocktopmenu.php index 54077e327..72649f389 100644 --- a/modules/blocktopmenu/blocktopmenu.php +++ b/modules/blocktopmenu/blocktopmenu.php @@ -242,7 +242,21 @@ class Blocktopmenu extends Module $this->_html .= ''; $this->getCategoryOption(1, (int)$id_lang, (int)Shop::getContextShopID()); $this->_html .= ''; - + + // BEGIN Shops + if (Shop::isFeatureActive()) + { + $this->_html .= ''; + $shops = Shop::getShopsCollection(); + foreach ($shops as $shop) + { + if (!$shop->setUrl() && !$shop->getBaseURL()) + continue; + $this->_html .= ''; + } + $this->_html .= ''; + } + // BEGIN Products $this->_html .= ''; $this->_html .= ''; @@ -422,7 +436,6 @@ class Blocktopmenu extends Module $menu_item = $this->getMenuItems(); $id_lang = (int)$this->context->language->id; $id_shop = (int)Shop::getContextShopID(); - foreach ($menu_item as $item) { if (!$item) @@ -481,14 +494,17 @@ class Blocktopmenu extends Module $this->_html .= ''; } break; + case 'SHOP': + $shop = new Shop((int)$id); + if (Validate::isLoadedObject($shop)) + $this->_html .= ''.PHP_EOL; + break; } } } private function makeMenu() { - $this->page_name = Dispatcher::getInstance()->getController(); - $menu_items = $this->getMenuItems(); $id_lang = (int)$this->context->language->id; $id_shop = (int)Shop::getContextShopID(); @@ -555,6 +571,15 @@ class Blocktopmenu extends Module } break; + case 'SHOP': + $selected = ($this->page_name == 'index' && (Tools::getValue('id_shop') == $id)) ? ' class="sfHover"' : ''; + $shop = new Shop((int)$id); + if (Validate::isLoadedObject($shop)) + { + $link = new Link; + $this->_menu .= ''.$shop->name.''.PHP_EOL; + } + break; case 'LNK': $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) @@ -690,8 +715,8 @@ class Blocktopmenu extends Module public function hookTop($param) { $this->user_groups = ($this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'))); - $smarty_cache_id = 'blocktopmenu-'.(int)$this->context->shop->id.'-'.implode(', ',$this->user_groups).'-'.(int)$this->context->language->id.'-'.(int)Tools::getValue('id_category').'-'.(int)Tools::getValue('id_manufacturer').'-'.(int)Tools::getValue('id_supplier').'-'.(int)Tools::getValue('id_cms').'-'.(int)Tools::getValue('id_product'); - + $this->page_name = Dispatcher::getInstance()->getController(); + $smarty_cache_id = 'blocktopmenu-'.$this->page_name.'-'.(int)$this->context->shop->id.'-'.implode(', ',$this->user_groups).'-'.(int)$this->context->language->id.'-'.(int)Tools::getValue('id_category').'-'.(int)Tools::getValue('id_manufacturer').'-'.(int)Tools::getValue('id_supplier').'-'.(int)Tools::getValue('id_cms').'-'.(int)Tools::getValue('id_product'); Tools::enableCache(); if (!$this->isCached('blocktopmenu.tpl', $smarty_cache_id)) {