// Refacto generateShopList()

This commit is contained in:
rMalie
2012-03-15 09:33:23 +00:00
parent a4c36a529c
commit ea67b720ec
4 changed files with 43 additions and 46 deletions
+41
View File
@@ -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"' : '').'>&raquo; '.$shopData['name'].'</option>';
if (!(!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP))
$html .= '</optgroup>';
}
$html .= '</select>';
return $html;
}
}