[-] BO : #PSFV-494 : BugFix - Block top menu now display CMS categories
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13781 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -32,6 +32,22 @@ class blocktopmenu extends Module
|
|||||||
private $_menu = '';
|
private $_menu = '';
|
||||||
private $_html = '';
|
private $_html = '';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pattern for matching config values
|
||||||
|
*/
|
||||||
|
private $pattern = '/^([A-Z_]*)[0-9]+/';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name of the controller
|
||||||
|
* Used to set item selected or not in top menu
|
||||||
|
*/
|
||||||
|
private $page_name = '';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Spaces per depth in BO
|
||||||
|
*/
|
||||||
|
private $spacer_size = '5';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->name = 'blocktopmenu';
|
$this->name = 'blocktopmenu';
|
||||||
@@ -95,7 +111,9 @@ class blocktopmenu extends Module
|
|||||||
|
|
||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
global $cookie;
|
$id_lang = Shop::getContextShopID();
|
||||||
|
$spacer = str_repeat(' ', $this->spacer_size);
|
||||||
|
|
||||||
if(Tools::isSubmit('submitBlocktopmenu'))
|
if(Tools::isSubmit('submitBlocktopmenu'))
|
||||||
{
|
{
|
||||||
if (Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', Tools::getValue('items')))
|
if (Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', Tools::getValue('items')))
|
||||||
@@ -104,7 +122,7 @@ class blocktopmenu extends Module
|
|||||||
$this->_html .= $this->displayError($this->l('Unable to update settings'));
|
$this->_html .= $this->displayError($this->l('Unable to update settings'));
|
||||||
Configuration::updateValue('MOD_BLOCKTOPMENU_SEARCH', (bool)Tools::getValue('search'));
|
Configuration::updateValue('MOD_BLOCKTOPMENU_SEARCH', (bool)Tools::getValue('search'));
|
||||||
}
|
}
|
||||||
if(Tools::isSubmit('submitBlocktopmenuLinks'))
|
else if(Tools::isSubmit('submitBlocktopmenuLinks'))
|
||||||
{
|
{
|
||||||
if(Tools::getValue('link') == '')
|
if(Tools::getValue('link') == '')
|
||||||
{
|
{
|
||||||
@@ -116,7 +134,7 @@ class blocktopmenu extends Module
|
|||||||
$this->_html .= $this->displayConfirmation($this->l('The link has been added'));
|
$this->_html .= $this->displayConfirmation($this->l('The link has been added'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Tools::isSubmit('submitBlocktopmenuRemove'))
|
else if(Tools::isSubmit('submitBlocktopmenuRemove'))
|
||||||
{
|
{
|
||||||
$id_linksmenutop = Tools::getValue('id_linksmenutop', 0);
|
$id_linksmenutop = Tools::getValue('id_linksmenutop', 0);
|
||||||
MenuTopLinks::remove($id_linksmenutop, (int)$this->context->shop->id);
|
MenuTopLinks::remove($id_linksmenutop, (int)$this->context->shop->id);
|
||||||
@@ -151,44 +169,43 @@ class blocktopmenu extends Module
|
|||||||
</td>
|
</td>
|
||||||
<td style="padding-left: 20px;">
|
<td style="padding-left: 20px;">
|
||||||
<select multiple="multiple" id="availableItems" style="width: 300px; height: 160px;">';
|
<select multiple="multiple" id="availableItems" style="width: 300px; height: 160px;">';
|
||||||
|
|
||||||
// BEGIN CMS
|
// BEGIN CMS
|
||||||
$this->_html .= '<optgroup label="'.$this->l('CMS').'">';
|
$this->_html .= '<optgroup label="'.$this->l('CMS').'">';
|
||||||
$_cms = CMS::listCms($cookie->id_lang);
|
$this->getCMSOptions();
|
||||||
foreach($_cms as $cms)
|
|
||||||
$this->_html .= '<option value="CMS'.$cms['id_cms'].'" style="margin-left:10px;">'.$cms['meta_title'].'</option>';
|
|
||||||
$this->_html .= '</optgroup>';
|
$this->_html .= '</optgroup>';
|
||||||
// END CMS
|
|
||||||
// BEGIN SUPPLIER
|
// BEGIN SUPPLIER
|
||||||
$this->_html .= '<optgroup label="'.$this->l('Supplier').'">';
|
$this->_html .= '<optgroup label="'.$this->l('Supplier').'">';
|
||||||
$suppliers = Supplier::getSuppliers(false, $cookie->id_lang);
|
$suppliers = Supplier::getSuppliers(false, $id_lang);
|
||||||
foreach($suppliers as $supplier)
|
foreach($suppliers as $supplier)
|
||||||
$this->_html .= '<option value="SUP'.$supplier['id_supplier'].'" style="margin-left:10px;">'.$supplier['name'].'</option>';
|
$this->_html .= '<option value="SUP'.$supplier['id_supplier'].'">'.$spacer.$supplier['name'].'</option>';
|
||||||
$this->_html .= '</optgroup>';
|
$this->_html .= '</optgroup>';
|
||||||
// END SUPPLIER
|
|
||||||
// BEGIN Manufacturer
|
// BEGIN Manufacturer
|
||||||
$this->_html .= '<optgroup label="'.$this->l('Manufacturer').'">';
|
$this->_html .= '<optgroup label="'.$this->l('Manufacturer').'">';
|
||||||
$manufacturers = Manufacturer::getManufacturers(false, $cookie->id_lang);
|
$manufacturers = Manufacturer::getManufacturers(false, $id_lang);
|
||||||
foreach($manufacturers as $manufacturer)
|
foreach($manufacturers as $manufacturer)
|
||||||
$this->_html .= '<option value="MAN'.$manufacturer['id_manufacturer'].'" style="margin-left:10px;">'.$manufacturer['name'].'</option>';
|
$this->_html .= '<option value="MAN'.$manufacturer['id_manufacturer'].'">'.$spacer.$manufacturer['name'].'</option>';
|
||||||
$this->_html .= '</optgroup>';
|
$this->_html .= '</optgroup>';
|
||||||
// END Manufacturer
|
|
||||||
// BEGIN Categories
|
// BEGIN Categories
|
||||||
$this->_html .= '<optgroup label="'.$this->l('Categories').'">';
|
$this->_html .= '<optgroup label="'.$this->l('Categories').'">';
|
||||||
$this->getCategoryOption(1, $cookie->id_lang);
|
$this->getCategoryOption();
|
||||||
$this->_html .= '</optgroup>';
|
$this->_html .= '</optgroup>';
|
||||||
// END Categories
|
|
||||||
// BEGIN Products
|
// BEGIN Products
|
||||||
$this->_html .= '<optgroup label="'.$this->l('Products').'">';
|
$this->_html .= '<optgroup label="'.$this->l('Products').'">';
|
||||||
$this->_html .= '<option value="PRODUCT" style="margin-left:10px;font-style:italic">'.$this->l('Choose ID product').'</option>';
|
$this->_html .= '<option value="PRODUCT" style="font-style:italic">'.$spacer.$this->l('Choose ID product').'</option>';
|
||||||
$this->_html .= '</optgroup>';
|
$this->_html .= '</optgroup>';
|
||||||
// END Products
|
|
||||||
// BEGIN Menu Top Links
|
// BEGIN Menu Top Links
|
||||||
$this->_html .= '<optgroup label="'.$this->l('Menu Top Links').'">';
|
$this->_html .= '<optgroup label="'.$this->l('Menu Top Links').'">';
|
||||||
$links = MenuTopLinks::gets($cookie->id_lang, null, (int)$this->context->shop->id);
|
$links = MenuTopLinks::gets($id_lang, null, (int)Shop::getContextShopID());
|
||||||
foreach($links as $link)
|
foreach($links as $link)
|
||||||
$this->_html .= '<option value="LNK'.$link['id_linksmenutop'].'" style="margin-left:10px;">'.$link['label'].'</option>';
|
$this->_html .= '<option value="LNK'.$link['id_linksmenutop'].'">'.$spacer.$link['label'].'</option>';
|
||||||
$this->_html .= '</optgroup>';
|
$this->_html .= '</optgroup>';
|
||||||
// END Menu Top Links
|
|
||||||
$this->_html .= '</select><br />
|
$this->_html .= '</select><br />
|
||||||
<br />
|
<br />
|
||||||
<a href="#" id="addItem" style="border: 1px solid rgb(170, 170, 170); margin: 2px; padding: 2px; text-align: center; display: block; text-decoration: none; background-color: rgb(250, 250, 250); color: rgb(18, 52, 86);"><< '.$this->l('Add').'</a>
|
<a href="#" id="addItem" style="border: 1px solid rgb(170, 170, 170); margin: 2px; padding: 2px; text-align: center; display: block; text-decoration: none; background-color: rgb(250, 250, 250); color: rgb(18, 52, 86);"><< '.$this->l('Add').'</a>
|
||||||
@@ -208,7 +225,8 @@ class blocktopmenu extends Module
|
|||||||
$("#availableItems option:selected").each(function(i){
|
$("#availableItems option:selected").each(function(i){
|
||||||
var val = $(this).val();
|
var val = $(this).val();
|
||||||
var text = $(this).text();
|
var text = $(this).text();
|
||||||
if(val == "PRODUCT")
|
text = text.replace(/(^\s*)|(\s*$)/gi,"");
|
||||||
|
if (val == "PRODUCT")
|
||||||
{
|
{
|
||||||
val = prompt("'.$this->l('Set ID product').'");
|
val = prompt("'.$this->l('Set ID product').'");
|
||||||
if(val == null || val == "" || isNaN(val))
|
if(val == null || val == "" || isNaN(val))
|
||||||
@@ -249,10 +267,11 @@ class blocktopmenu extends Module
|
|||||||
</form>
|
</form>
|
||||||
</fieldset><br />';
|
</fieldset><br />';
|
||||||
|
|
||||||
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
|
$defaultLanguage = intval($this->context->language->id);
|
||||||
$languages = Language::getLanguages();
|
$languages = $this->context->controller->getLanguages();
|
||||||
$iso = Language::getIsoById($defaultLanguage);
|
$iso = Language::getIsoById($defaultLanguage);
|
||||||
$divLangName = 'link_label';
|
$divLangName = 'link_label';
|
||||||
|
|
||||||
$this->_html .= '
|
$this->_html .= '
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><img src="../img/admin/add.gif" alt="" title="" />'.$this->l('Add Menu Top Link').'</legend>
|
<legend><img src="../img/admin/add.gif" alt="" title="" />'.$this->l('Add Menu Top Link').'</legend>
|
||||||
@@ -283,6 +302,11 @@ class blocktopmenu extends Module
|
|||||||
</form>
|
</form>
|
||||||
</fieldset><br />';
|
</fieldset><br />';
|
||||||
|
|
||||||
|
$links = MenuTopLinks::gets($id_lang, null, Shop::getContextShopID());
|
||||||
|
|
||||||
|
if (!count($links))
|
||||||
|
return $this->_html;
|
||||||
|
|
||||||
$this->_html .= '
|
$this->_html .= '
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><img src="../img/admin/details.gif" alt="" title="" />'.$this->l('List Menu Top Link').'</legend>
|
<legend><img src="../img/admin/details.gif" alt="" title="" />'.$this->l('List Menu Top Link').'</legend>
|
||||||
@@ -297,14 +321,13 @@ class blocktopmenu extends Module
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>';
|
<tbody>';
|
||||||
$links = MenuTopLinks::gets($cookie->id_lang, null, $this->context->shop->id);
|
|
||||||
foreach($links as $link)
|
foreach($links as $link)
|
||||||
{
|
{
|
||||||
$this->_html .= '
|
$this->_html .= '
|
||||||
<tr>
|
<tr>
|
||||||
<td>'.$link['id_linksmenutop'].'</td>
|
<td>'.$link['id_linksmenutop'].'</td>
|
||||||
<td>'.$link['label'].'</td>
|
<td>'.$link['label'].'</td>
|
||||||
<td>'.$link['link'].'</td>
|
<td><a href="'.$link['link'].'"'.(($link['new_window']) ? ' target="_blank"' : '').'>'.$link['link'].'</a></td>
|
||||||
<td>'.(($link['new_window']) ? $this->l('Yes') : $this->l('No')).'</td>
|
<td>'.(($link['new_window']) ? $this->l('Yes') : $this->l('No')).'</td>
|
||||||
<td>
|
<td>
|
||||||
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
|
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
|
||||||
@@ -322,162 +345,301 @@ class blocktopmenu extends Module
|
|||||||
|
|
||||||
private function getMenuItems()
|
private function getMenuItems()
|
||||||
{
|
{
|
||||||
// @todo why this ?
|
return explode(',', Configuration::get('MOD_BLOCKTOPMENU_ITEMS'));
|
||||||
return array('global' => explode(',', Configuration::get('MOD_BLOCKTOPMENU_ITEMS')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function makeMenuOption()
|
private function makeMenuOption()
|
||||||
{
|
{
|
||||||
global $cookie;
|
$menu_item = $this->getMenuItems();
|
||||||
foreach($this->getMenuItems() as $type => $items)
|
$id_lang = (int)$this->context->language->id;
|
||||||
{
|
$id_shop = (int)Shop::getContextShopID();
|
||||||
foreach ($items as $item)
|
|
||||||
{
|
foreach($menu_item as $type => $item)
|
||||||
$id = (int)substr($item, 3, strlen($item));
|
{
|
||||||
$disabled = ((Shop::getContext() == Shop::CONTEXT_SHOP && $type == 'global') ? ' disabled="disabled"': '');
|
if (!$item)
|
||||||
switch(substr($item, 0, 3))
|
continue;
|
||||||
{
|
|
||||||
case'CAT':
|
preg_match($this->pattern, $item, $values);
|
||||||
$this->getCategoryOption($id, $cookie->id_lang, false);
|
$id = (int)substr($item, strlen($values[1]), strlen($item));
|
||||||
break;
|
|
||||||
case'PRD':
|
switch (substr($item, 0, strlen($values[1])))
|
||||||
$product = new Product($id, true, $cookie->id_lang);
|
{
|
||||||
if(!is_null($product->id))
|
case'CAT':
|
||||||
$this->_html .= '<option value="PRD'.$id.'"'.$disabled.'>'.$product->name.'</option>'.PHP_EOL;
|
$category = new Category($id, $id_lang);
|
||||||
break;
|
if(!is_null($category->id))
|
||||||
case'CMS':
|
$this->_html .= '<option value="CAT'.$id.'">'.$category->name.'</option>'.PHP_EOL;
|
||||||
$cms = CMS::getLinks($cookie->id_lang, array($id));
|
break;
|
||||||
if(count($cms))
|
case'PRD':
|
||||||
$this->_html .= '<option value="CMS'.$id.'"'.$disabled.'>'.$cms[0]['meta_title'].'</option>'.PHP_EOL;
|
$product = new Product($id, true, $id_lang);
|
||||||
break;
|
if(!is_null($product->id))
|
||||||
case'MAN':
|
$this->_html .= '<option value="PRD'.$id.'">'.$product->name.'</option>'.PHP_EOL;
|
||||||
$manufacturer = new Manufacturer($id, $cookie->id_lang);
|
break;
|
||||||
if(!is_null($manufacturer->id))
|
case'CMS':
|
||||||
$this->_html .= '<option value="MAN'.$id.'"'.$disabled.'>'.$manufacturer->name.'</option>'.PHP_EOL;
|
$cms = new CMS($id, $id_lang);
|
||||||
break;
|
if (count($cms))
|
||||||
case'SUP':
|
$this->_html .= '<option value="CMS'.$id.'">'.$cms->meta_title.'</option>'.PHP_EOL;
|
||||||
$supplier = new Supplier($id, $cookie->id_lang);
|
break;
|
||||||
if(!is_null($supplier->id))
|
case'CMS_CAT':
|
||||||
$this->_html .= '<option value="SUP'.$id.'"'.$disabled.'>'.$supplier->name.'</option>'.PHP_EOL;
|
$category = new CMSCategory($id, $id_lang);
|
||||||
break;
|
if (count($category))
|
||||||
case'LNK':
|
$this->_html .= '<option value="CMS_CAT'.$id.'">'.$category->name.'</option>'.PHP_EOL;
|
||||||
$link = MenuTopLinks::get($id, $cookie->id_lang, (int)$this->context->shop->id);
|
break;
|
||||||
if(count($link))
|
case'MAN':
|
||||||
$this->_html .= '<option value="LNK'.$id.'"'.$disabled.'>'.$link[0]['label'].'</option>'.PHP_EOL;
|
$manufacturer = new Manufacturer($id, $id_lang);
|
||||||
break;
|
if(!is_null($manufacturer->id))
|
||||||
}
|
$this->_html .= '<option value="MAN'.$id.'">'.$manufacturer->name.'</option>'.PHP_EOL;
|
||||||
}
|
break;
|
||||||
}
|
case'SUP':
|
||||||
|
$supplier = new Supplier($id, $id_lang);
|
||||||
|
if(!is_null($supplier->id))
|
||||||
|
$this->_html .= '<option value="SUP'.$id.'">'.$supplier->name.'</option>'.PHP_EOL;
|
||||||
|
break;
|
||||||
|
case'LNK':
|
||||||
|
$link = MenuTopLinks::get($id, $id_lang, $id_shop);
|
||||||
|
if(count($link))
|
||||||
|
$this->_html .= '<option value="LNK'.$id.'">'.$link[0]['label'].'</option>'.PHP_EOL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function makeMenu()
|
private function makeMenu()
|
||||||
{
|
{
|
||||||
global $cookie, $page_name;
|
$this->page_name = $this->context->controller->php_self;
|
||||||
foreach($this->getMenuItems() as $type => $items)
|
|
||||||
|
$menu_items = $this->getMenuItems();
|
||||||
|
$id_lang = (int)$this->context->language->id;
|
||||||
|
$id_shop = (int)Shop::getContextShopID();
|
||||||
|
|
||||||
|
foreach($menu_items as $type => $item)
|
||||||
{
|
{
|
||||||
foreach ($items as $item)
|
if (!$item)
|
||||||
{
|
continue;
|
||||||
$id = (int)substr($item, 3, strlen($item));
|
|
||||||
switch(substr($item, 0, 3))
|
preg_match($this->pattern, $item, $value);
|
||||||
{
|
$id = (int)substr($item, strlen($value[1]), strlen($item));
|
||||||
case'CAT':
|
|
||||||
$this->getCategory($id, $cookie->id_lang);
|
switch(substr($item, 0, strlen($value[1])))
|
||||||
break;
|
{
|
||||||
case'PRD':
|
case'CAT':
|
||||||
$selected = ($page_name == 'product' && (Tools::getValue('id_product') == $id)) ? ' class="sfHover"' : '';
|
$this->getCategory($id);
|
||||||
$product = new Product($id, true, $cookie->id_lang);
|
break;
|
||||||
if(!is_null($product->id))
|
case'PRD':
|
||||||
$this->_menu .= '<li'.$selected.'><a href="'.$product->getLink().'">'.$product->name.'</a></li>'.PHP_EOL;
|
$selected = ($this->page_name == 'product' && (Tools::getValue('id_product') == $id)) ? ' class="sfHover"' : '';
|
||||||
break;
|
$product = new Product($id, true, $id_lang);
|
||||||
case'CMS':
|
if (!is_null($product->id))
|
||||||
$selected = ($page_name == 'cms' && (Tools::getValue('id_cms') == $id)) ? ' class="sfHover"' : '';
|
$this->_menu .= '<li'.$selected.'><a href="'.$product->getLink().'">'.$product->name.'</a></li>'.PHP_EOL;
|
||||||
$cms = CMS::getLinks($cookie->id_lang, array($id));
|
break;
|
||||||
if(count($cms))
|
case'CMS':
|
||||||
$this->_menu .= '<li'.$selected.'><a href="'.$cms[0]['link'].'">'.$cms[0]['meta_title'].'</a></li>'.PHP_EOL;
|
$selected = ($this->page_name == 'cms' && (Tools::getValue('id_cms') == $id)) ? ' class="sfHover"' : '';
|
||||||
break;
|
$cms = CMS::getLinks($id_lang, array($id));
|
||||||
case'MAN':
|
if (count($cms))
|
||||||
$selected = ($page_name == 'manufacturer' && (Tools::getValue('id_manufacturer') == $id)) ? ' class="sfHover"' : '';
|
$this->_menu .= '<li'.$selected.'><a href="'.$cms[0]['link'].'">'.$cms[0]['meta_title'].'</a></li>'.PHP_EOL;
|
||||||
$manufacturer = new Manufacturer($id, $cookie->id_lang);
|
break;
|
||||||
if(!is_null($manufacturer->id))
|
case'CMS_CAT':
|
||||||
{
|
$category = new CMSCategory($id, $id_lang);
|
||||||
if (intval(Configuration::get('PS_REWRITING_SETTINGS')))
|
if (count($category))
|
||||||
$manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name, false);
|
{
|
||||||
else
|
$this->_menu .= '<li><a href="#">'.$category->name.'</a>';
|
||||||
$manufacturer->link_rewrite = 0;
|
$this->getCMSMenuItems($category->id);
|
||||||
$link = new Link;
|
$this->_menu .= '</li>'.PHP_EOL;
|
||||||
$this->_menu .= '<li'.$selected.'><a href="'.$link->getManufacturerLink($id, $manufacturer->link_rewrite).'">'.$manufacturer->name.'</a></li>'.PHP_EOL;
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case'MAN':
|
||||||
case'SUP':
|
$selected = ($this->page_name == 'manufacturer' && (Tools::getValue('id_manufacturer') == $id)) ? ' class="sfHover"' : '';
|
||||||
$selected = ($page_name == 'supplier' && (Tools::getValue('id_supplier') == $id)) ? ' class="sfHover"' : '';
|
$manufacturer = new Manufacturer($id, $id_lang);
|
||||||
$supplier = new Supplier($id, $cookie->id_lang);
|
if (!is_null($manufacturer->id))
|
||||||
if(!is_null($supplier->id))
|
{
|
||||||
{
|
if (intval(Configuration::get('PS_REWRITING_SETTINGS')))
|
||||||
$link = new Link;
|
$manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name, false);
|
||||||
$this->_menu .= '<li'.$selected.'><a href="'.$link->getSupplierLink($id, $supplier->link_rewrite).'">'.$supplier->name.'</a></li>'.PHP_EOL;
|
else
|
||||||
}
|
$manufacturer->link_rewrite = 0;
|
||||||
break;
|
$link = new Link;
|
||||||
case'LNK':
|
$this->_menu .= '<li'.$selected.'><a href="'.$link->getManufacturerLink($id, $manufacturer->link_rewrite).'">'.$manufacturer->name.'</a></li>'.PHP_EOL;
|
||||||
$link = MenuTopLinks::get($id, $cookie->id_lang, (int)$this->context->shop->id);
|
}
|
||||||
if(count($link))
|
break;
|
||||||
$this->_menu .= '<li><a href="'.$link[0]['link'].'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.$link[0]['label'].'</a></li>'.PHP_EOL;
|
case'SUP':
|
||||||
break;
|
$selected = ($this->page_name == 'supplier' && (Tools::getValue('id_supplier') == $id)) ? ' class="sfHover"' : '';
|
||||||
}
|
$supplier = new Supplier($id, $id_lang);
|
||||||
}
|
if (!is_null($supplier->id))
|
||||||
|
{
|
||||||
|
$link = new Link;
|
||||||
|
$this->_menu .= '<li'.$selected.'><a href="'.$link->getSupplierLink($id, $supplier->link_rewrite).'">'.$supplier->name.'</a></li>'.PHP_EOL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case'LNK':
|
||||||
|
$link = MenuTopLinks::get($id, $id_lang, $id_shop);
|
||||||
|
if (count($link))
|
||||||
|
$this->_menu .= '<li><a href="'.$link[0]['link'].'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.$link[0]['label'].'</a></li>'.PHP_EOL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCategoryOption($id_category, $id_lang, $children = true)
|
private function getCategoryOption($id_category = 1, $id_lang = false, $recursive = true)
|
||||||
{
|
{
|
||||||
$categorie = new Category($id_category, $id_lang);
|
$id_lang = (int)($id_lang ? $id_lang : Shop::getContextShopID());
|
||||||
if(is_null($categorie->id))
|
$category = new Category($id_category, $id_lang);
|
||||||
return;
|
|
||||||
if(count(explode('.', $categorie->name)) > 1)
|
|
||||||
$name = str_replace('.', '', strstr($categorie->name, '.'));
|
|
||||||
else
|
|
||||||
$name = $categorie->name;
|
|
||||||
$this->_html .= '<option value="CAT'.$categorie->id.'" style="margin-left:'.(($children) ? round(15+(15*(int)$categorie->level_depth)) : 0).'px;">'.$name.'</option>';
|
|
||||||
if($children)
|
|
||||||
{
|
|
||||||
$childrens = Category::getChildren($id_category, $id_lang);
|
|
||||||
if(count($childrens))
|
|
||||||
foreach($childrens as $children)
|
|
||||||
$this->getCategoryOption($children['id_category'], $id_lang);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getCategory($id_category, $id_lang)
|
if (is_null($category->id))
|
||||||
{
|
return;
|
||||||
global $page_name;
|
|
||||||
|
|
||||||
$categorie = new Category($id_category, $id_lang);
|
if ($recursive)
|
||||||
if(is_null($categorie->id))
|
{
|
||||||
|
$childrens = Category::getChildren((int)$id_category, $id_lang);
|
||||||
|
$spacer = str_repeat(' ', $this->spacer_size * (int)$category->level_depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_html .= '<option value="CAT'.(int)$category->id.'">'.(isset($spacer) ? $spacer : '').$category->name.'</option>';
|
||||||
|
|
||||||
|
if (isset($childrens) && count($childrens))
|
||||||
|
foreach($childrens as $children)
|
||||||
|
$this->getCategoryOption((int)$children['id_category'], $id_lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getCategory($id_category, $id_lang = false)
|
||||||
|
{
|
||||||
|
$id_lang = $id_lang ? $id_lang : Shop::getContextShopID();
|
||||||
|
$category = new Category($id_category, $id_lang);
|
||||||
|
|
||||||
|
if (is_null($category->id))
|
||||||
return;
|
return;
|
||||||
$selected = ($page_name == 'category' && ((int)Tools::getValue('id_category') == $id_category)) ? ' class="sfHoverForce"' : '';
|
|
||||||
$this->_menu .= '<li'.$selected.'>';
|
$childrens = Category::getChildren($id_category, $id_lang);
|
||||||
if(count(explode('.', $categorie->name)) > 1)
|
$selected = ($this->page_name == 'category' && ((int)Tools::getValue('id_category') == $id_category)) ? ' class="sfHoverForce"' : '';
|
||||||
$name = str_replace('.', '', strstr($categorie->name, '.'));
|
$this->_menu .= '<li '.$selected.'>';
|
||||||
else
|
$this->_menu .= '<a href="'.$category->getLink().'">'.$category->name.'</a>';
|
||||||
$name = $categorie->name;
|
|
||||||
$this->_menu .= '<a href="'.$categorie->getLink().'">'.$name.'</a>';
|
if (count($childrens))
|
||||||
$childrens = Category::getChildren($id_category, $id_lang);
|
|
||||||
if(count($childrens))
|
|
||||||
{
|
{
|
||||||
$this->_menu .= '<ul>';
|
$this->_menu .= '<ul>';
|
||||||
|
|
||||||
foreach($childrens as $children)
|
foreach($childrens as $children)
|
||||||
$this->getCategory($children['id_category'], $id_lang);
|
$this->getCategory($children['id_category'], $id_lang);
|
||||||
|
|
||||||
$this->_menu .= '</ul>';
|
$this->_menu .= '</ul>';
|
||||||
}
|
}
|
||||||
$this->_menu .= '</li>';
|
$this->_menu .= '</li>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCMSMenuItems($parent, $depth = 1)
|
||||||
|
{
|
||||||
|
$id_lang = Context::getContext()->language->id;
|
||||||
|
|
||||||
|
if ($depth > 3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$categories = $this->getCMSCategories(false, $parent);
|
||||||
|
$pages = $this->getCMSPages($parent);
|
||||||
|
|
||||||
|
if (count($categories) || count($pages))
|
||||||
|
{
|
||||||
|
$this->_menu .= '<ul>';
|
||||||
|
|
||||||
|
foreach ($categories as $category)
|
||||||
|
{
|
||||||
|
$this->_menu .= '<li>';
|
||||||
|
$this->_menu .= '<a href="#">'.$category['name'].'</a>';
|
||||||
|
$this->getCMSMenuItems($category['id_cms_category'], $depth + 1);
|
||||||
|
$this->_menu .= '</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($pages as $page)
|
||||||
|
{
|
||||||
|
$cms = new CMS($page['id_cms'], $id_lang);
|
||||||
|
$links = $cms->getLinks($id_lang, array($cms->id));
|
||||||
|
|
||||||
|
$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
|
||||||
|
$this->_menu .= '<li '.$selected.'>';
|
||||||
|
$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
|
||||||
|
$this->_menu .= '</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_menu .= '</ul>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getCMSOptions($parent = 0, $depth = 1)
|
||||||
|
{
|
||||||
|
$categories = $this->getCMSCategories(false, $parent);
|
||||||
|
$pages = $this->getCMSPages($parent);
|
||||||
|
$spacer = str_repeat(' ', $this->spacer_size * (int)$depth);
|
||||||
|
|
||||||
|
foreach ($categories as $category)
|
||||||
|
{
|
||||||
|
$this->_html .= '<option value="CMS_CAT'.$category['id_cms_category'].'" style="font-weight: bold;">'.$spacer.$category['name'].'</option>';
|
||||||
|
$this->getCMSOptions($category['id_cms_category'], $depth + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($pages as $page)
|
||||||
|
$this->_html .= '<option value="CMS'.$page['id_cms'].'">'.$spacer.$page['meta_title'].'</option>';
|
||||||
|
}
|
||||||
|
|
||||||
public function hookTop($param)
|
public function hookTop($param)
|
||||||
{
|
{
|
||||||
global $smarty;
|
global $smarty;
|
||||||
|
|
||||||
$this->makeMenu();
|
$this->makeMenu();
|
||||||
|
|
||||||
$smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH'));
|
$smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH'));
|
||||||
$smarty->assign('MENU', $this->_menu);
|
$smarty->assign('MENU', $this->_menu);
|
||||||
$smarty->assign('this_path', $this->_path);
|
$smarty->assign('this_path', $this->_path);
|
||||||
|
|
||||||
return $this->display(__FILE__, 'blocktopmenu.tpl');
|
return $this->display(__FILE__, 'blocktopmenu.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCMSCategories($recursive = false, $parent = 1)
|
||||||
|
{
|
||||||
|
if ($recursive === false)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT bcp.`id_cms_category`, bcp.`id_parent`, bcp.`level_depth`, bcp.`active`, bcp.`position`, cl.`name`, cl.`link_rewrite`
|
||||||
|
FROM `'._DB_PREFIX_.'cms_category` bcp
|
||||||
|
INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl
|
||||||
|
ON (bcp.`id_cms_category` = cl.`id_cms_category`)
|
||||||
|
WHERE cl.`id_lang` = '.(int)Context::getContext()->language->id.'
|
||||||
|
AND bcp.`id_parent` = '.(int)$parent;
|
||||||
|
|
||||||
|
return Db::getInstance()->executeS($sql);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sql = 'SELECT bcp.`id_cms_category`, bcp.`id_parent`, bcp.`level_depth`, bcp.`active`, bcp.`position`, cl.`name`, cl.`link_rewrite`
|
||||||
|
FROM `'._DB_PREFIX_.'cms_category` bcp
|
||||||
|
INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl
|
||||||
|
ON (bcp.`id_cms_category` = cl.`id_cms_category`)
|
||||||
|
WHERE cl.`id_lang` = '.(int)Context::getContext()->language->id.'
|
||||||
|
AND bcp.`id_parent` = '.(int)$parent;
|
||||||
|
|
||||||
|
$results = Db::getInstance()->executeS($sql);
|
||||||
|
foreach ($results as $result)
|
||||||
|
{
|
||||||
|
$sub_categories = $this->getCMSCategories(true, $result['id_cms_category']);
|
||||||
|
if ($sub_categories && count($sub_categories) > 0)
|
||||||
|
$result['sub_categories'] = $sub_categories;
|
||||||
|
$categories[] = $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isset($categories) ? $categories : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getCMSPages($id_cms_category, $id_shop = false)
|
||||||
|
{
|
||||||
|
$id_shop = ($id_shop !== false) ? $id_shop : Context::getContext()->shop->id;
|
||||||
|
|
||||||
|
$sql = 'SELECT c.`id_cms`, cl.`meta_title`, cl.`link_rewrite`
|
||||||
|
FROM `'._DB_PREFIX_.'cms` c
|
||||||
|
INNER JOIN `'._DB_PREFIX_.'cms_shop` cs
|
||||||
|
ON (c.`id_cms` = cs.`id_cms`)
|
||||||
|
INNER JOIN `'._DB_PREFIX_.'cms_lang` cl
|
||||||
|
ON (c.`id_cms` = cl.`id_cms`)
|
||||||
|
WHERE c.`id_cms_category` = '.(int)$id_cms_category.'
|
||||||
|
AND cs.`id_shop` = '.(int)$id_shop.'
|
||||||
|
AND cl.`id_lang` = '.(int)Context::getContext()->language->id.'
|
||||||
|
AND c.`active` = 1
|
||||||
|
ORDER BY `position`';
|
||||||
|
|
||||||
|
return Db::getInstance()->executeS($sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user