// Refacto generateShopList()
This commit is contained in:
@@ -390,50 +390,6 @@ function simpleXMLToArray ($xml, $flattenValues = true, $flattenAttributes = tru
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a sweet HTML list for shop selection
|
||||
*
|
||||
* @todo move in adminTab
|
||||
* @return string
|
||||
*/
|
||||
function generateShopList()
|
||||
{
|
||||
$tree = Shop::getTree();
|
||||
$context = Context::getContext();
|
||||
|
||||
// Get default value
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$value = '';
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
$value = 'g-'.Shop::getContextGroupShopID();
|
||||
else
|
||||
$value = 's-'.Shop::getContextShopID();
|
||||
|
||||
// Generate HTML
|
||||
$url = $_SERVER['REQUEST_URI'].(($_SERVER['QUERY_STRING']) ? '&' : '?').'setShopContext=';
|
||||
$html = '<select class="shopList chosen" onchange="location.href = \''.$url.'\'+$(this).val();">';
|
||||
|
||||
$html .= '<option value="" class="first">'.translate('All shops').'</option>';
|
||||
foreach ($tree as $gID => $group_data)
|
||||
{
|
||||
if ($context->controller->multishop_context & Shop::CONTEXT_GROUP)
|
||||
$html .= '<option class="group" value="g-'.$gID.'" '.(($value == 'g-'.$gID) ? 'selected="selected"' : '').'>'.translate('Group:').' '.htmlspecialchars($group_data['name']).'</option>';
|
||||
else
|
||||
$html .= '<optgroup class="group" label="'.translate('Group:').' '.htmlspecialchars($group_data['name']).'">';
|
||||
|
||||
if ($context->controller->multishop_context & Shop::CONTEXT_SHOP)
|
||||
foreach ($group_data['shops'] as $sID => $shopData)
|
||||
if ($shopData['active'])
|
||||
$html .= '<option value="s-'.$sID.'" class="shop" '.(($value == 's-'.$sID) ? 'selected="selected"' : '').'>» '.$shopData['name'].'</option>';
|
||||
|
||||
if (!($context->controller->multishop_context & Shop::CONTEXT_GROUP))
|
||||
$html .= '</optgroup>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* for retrocompatibility with old AdminTab, old index.php
|
||||
*
|
||||
|
||||
@@ -280,7 +280,7 @@ echo ' </select>
|
||||
</div>';
|
||||
|
||||
if (Shop::isFeatureActive())
|
||||
echo '<div id="header_shoplist">'.translate('Select your shop:').' '.generateShopList().'</div>';
|
||||
echo '<div id="header_shoplist">'.translate('Select your shop:').' '.Helper::renderShopList().'</div>';
|
||||
|
||||
echo '</div>';
|
||||
echo Hook::exec('displayBackOfficeTop');
|
||||
|
||||
@@ -1278,7 +1278,7 @@ class AdminControllerCore extends Controller
|
||||
'bo_query' => Tools::safeOutput(Tools::stripslashes(Tools::getValue('bo_query'))),
|
||||
'quick_access' => $quick_access,
|
||||
'multi_shop' => Shop::isFeatureActive(),
|
||||
'shop_list' => (Shop::isFeatureActive() ? generateShopList() : null), //@TODO refacto
|
||||
'shop_list' => Helper::renderShopList(),
|
||||
'shop' => $this->context->shop,
|
||||
'group_shop' => $this->context->shop->getGroup(),
|
||||
'tab' => $tab,
|
||||
|
||||
@@ -350,5 +350,46 @@ class HelperCore
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
public static function renderShopList()
|
||||
{
|
||||
if (!Shop::isFeatureActive())
|
||||
return null;
|
||||
|
||||
$tree = Shop::getTree();
|
||||
$context = Context::getContext();
|
||||
|
||||
// Get default value
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$value = '';
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
$value = 'g-'.Shop::getContextGroupShopID();
|
||||
else
|
||||
$value = 's-'.Shop::getContextShopID();
|
||||
|
||||
// Generate HTML
|
||||
$url = $_SERVER['REQUEST_URI'].(($_SERVER['QUERY_STRING']) ? '&' : '?').'setShopContext=';
|
||||
$html = '<select class="shopList chosen" onchange="location.href = \''.$url.'\'+$(this).val();">';
|
||||
|
||||
$html .= '<option value="" class="first">'.translate('All shops').'</option>';
|
||||
foreach ($tree as $gID => $group_data)
|
||||
{
|
||||
if (!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP)
|
||||
$html .= '<option class="group" value="g-'.$gID.'" '.(($value == 'g-'.$gID) ? 'selected="selected"' : '').'>'.translate('Group:').' '.htmlspecialchars($group_data['name']).'</option>';
|
||||
else
|
||||
$html .= '<optgroup class="group" label="'.translate('Group:').' '.htmlspecialchars($group_data['name']).'">';
|
||||
|
||||
if (!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_SHOP)
|
||||
foreach ($group_data['shops'] as $sID => $shopData)
|
||||
if ($shopData['active'])
|
||||
$html .= '<option value="s-'.$sID.'" class="shop" '.(($value == 's-'.$sID) ? 'selected="selected"' : '').'>» '.$shopData['name'].'</option>';
|
||||
|
||||
if (!(!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP))
|
||||
$html .= '</optgroup>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user