241 lines
7.7 KiB
PHP
Executable File
241 lines
7.7 KiB
PHP
Executable File
<?php
|
|
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
|
require_once(dirname(__FILE__).'/../../init.php');
|
|
require_once(dirname(__FILE__).'/Sale.php');
|
|
$controller->preProcess();
|
|
|
|
$id_manufacturer = Tools::getValue('id_manufacturer');
|
|
$manufacturer = NULL;
|
|
|
|
$id_tag = (int) Tools::getValue('id_tag');
|
|
$tag = NULL;
|
|
|
|
$langs = Language::getLanguages();
|
|
$lang = (int) $cookie->id_lang;
|
|
$isolang = Language::getIsoById($lang);
|
|
|
|
$featured_i18n = array(
|
|
'fr' => 'marques',
|
|
'en' => 'brands',
|
|
);
|
|
|
|
// TODO: Migrate to a dedicated controller
|
|
$on_i18n = array(
|
|
'fr' => 'sur',
|
|
'en' => 'on',
|
|
);
|
|
|
|
$current_url = explode('?', $_SERVER['REQUEST_URI']);
|
|
if($id_manufacturer) {
|
|
$manufacturer = new Manufacturer($id_manufacturer, $lang);
|
|
$canonical_url = __PS_BASE_URI__.(count($langs) > 1? $isolang.'/': '').(isset($featured_i18n[$isolang])? $featured_i18n[$isolang]: $featured_i18n['en']).'/'.$id_manufacturer.'-'.Tools::str2url($manufacturer->name).'.html';
|
|
} elseif($id_tag) {
|
|
$tag = Db::getInstance()->getRow('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'privatesale_tag_lang`
|
|
WHERE `id_lang` = '.(int) $cookie->id_lang.'
|
|
AND `id_tag` = '.(int) $id_tag.'
|
|
');
|
|
|
|
if(!$tag) {
|
|
Tools::redirect(__PS_BASE_URI__.(count($langs) > 1? $isolang.'/': '').(isset($featured_i18n[$isolang])? $featured_i18n[$isolang]: $featured_i18n['en']));
|
|
} else {
|
|
$canonical_url = __PS_BASE_URI__.(count($langs) > 1? $isolang.'/': '').(isset($featured_i18n[$isolang])? $featured_i18n[$isolang]: $featured_i18n['en']).'/'.$id_tag.'-'.Tools::str2url($tag['value']);
|
|
$smarty->assign('tag', $tag);
|
|
}
|
|
} else {
|
|
$canonical_url = __PS_BASE_URI__.(count($langs) > 1? $isolang.'/': '').(isset($featured_i18n[$isolang])? $featured_i18n[$isolang]: $featured_i18n['en']);
|
|
}
|
|
if($current_url[0] != $canonical_url) {
|
|
Tools::redirect($canonical_url.(count($current_url) > 1? '?'.$current_url[1]: ''));
|
|
}
|
|
|
|
try {
|
|
smartyRegisterFunction($smarty, 'modifier', 'str2url', array('Tools', 'str2url'));
|
|
} catch(Exception $e) {}
|
|
|
|
if(Configuration::get('PS_REWRITING_SETTINGS')) {
|
|
$smarty->assign(array(
|
|
'rewriting' => TRUE,
|
|
'base_url' => (count($langs) > 1? (isset($featured_i18n[$isolang])? $isolang.'/'.$featured_i18n[$isolang]: $isolang.'/'.$featured_i18n['en']): (isset($featured_i18n[$isolang])? $featured_i18n[$isolang]: $featured_i18n['en'])),
|
|
));
|
|
} else {
|
|
$smarty->assign('rewriting', FALSE);
|
|
}
|
|
|
|
$ordering = (int) Configuration::get('PRIVATESALES_FEATURED_ORDER');
|
|
$pqty = (int) Configuration::get('PRIVATESALES_FEATURED_PQTY');
|
|
|
|
if($ordering == 0) {
|
|
$list_i18n = array(
|
|
'fr' => array(
|
|
'Liste des marques partenaires de',
|
|
''
|
|
),
|
|
'en' => array(
|
|
'Featured brands on',
|
|
''
|
|
),
|
|
);
|
|
} else {
|
|
$list_i18n = array(
|
|
'fr' => array(
|
|
'Catégories de marques partenaires sur',
|
|
''
|
|
),
|
|
'en' => array(
|
|
'Featured brands categories on',
|
|
''
|
|
),
|
|
);
|
|
}
|
|
|
|
$smarty->assign(array(
|
|
'ordering' => $ordering,
|
|
'pqty' => $pqty,
|
|
));
|
|
|
|
if($id_manufacturer) {
|
|
$smarty->assign(array(
|
|
'brand' => $manufacturer,
|
|
));
|
|
|
|
if(Module::isInstalled('privatesales_stats')) {
|
|
$products = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT `id_product`
|
|
FROM `'._DB_PREFIX_.'privatesale_stats_product`
|
|
LEFT JOIN `'._DB_PREFIX_.'privatesale_brands`
|
|
ON `'._DB_PREFIX_.'privatesale_stats_product`.`id_sale` = `'._DB_PREFIX_.'privatesale_brands`.`id_sale`
|
|
WHERE `'._DB_PREFIX_.'privatesale_brands`.`id_brand` = '.(int) $id_manufacturer.'
|
|
ORDER BY `quantity` DESC
|
|
LIMIT '.$pqty.'
|
|
') as $product) {
|
|
$products[] = new Product($product['id_product'], $cookie->id_lang);
|
|
}
|
|
|
|
$smarty->assign(array(
|
|
'm_products' => $products,
|
|
));
|
|
} else {
|
|
$smarty->assign(array(
|
|
'm_products' => Manufacturer::getProducts($id_manufacturer, $cookie->id_lang, 0, $pqty, NULL, FALSE, FALSE, FALSE),
|
|
));
|
|
}
|
|
|
|
$smarty->assign(array(
|
|
'meta_title' => $manufacturer->name.' '.(isset($on_i18n[$isolang])? $on_i18n[$isolang]: $on_i18n['en']).' '.Configuration::get('PS_SHOP_NAME'),
|
|
'meta_description' => substr(strip_tags($manufacturer->short_description), 0, 120),
|
|
// 'meta_keywords' => '', // TODO: Handle keywords
|
|
));
|
|
|
|
require_once(dirname(__FILE__).'/../../header.php');
|
|
|
|
echo Module::display(dirname(__FILE__), 'featured_brand.tpl');
|
|
} elseif($id_tag) {
|
|
$smarty->assign(array(
|
|
'tag' => $tag,
|
|
));
|
|
|
|
$brands = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT DISTINCT `id_brand`
|
|
FROM `'._DB_PREFIX_.'privatesale_brands` b, `'._DB_PREFIX_.'privatesale_tag_sale` ts
|
|
WHERE ts.`id_tag` = '.(int) $id_tag.'
|
|
AND b.`id_sale` = ts.`id_sale`
|
|
') as $brand) {
|
|
$brands[] = $brand['id_brand'];
|
|
}
|
|
|
|
$smarty->assign(array(
|
|
'manufacturers' => Db::getInstance()->ExecuteS('
|
|
SELECT m.*, ml.`short_description`
|
|
FROM `'._DB_PREFIX_.'manufacturer` m
|
|
LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml
|
|
ON (
|
|
m.`id_manufacturer` = ml.`id_manufacturer`
|
|
AND ml.`id_lang` = '.(int) $cookie->id_lang.'
|
|
)
|
|
WHERE m.`active` = 1
|
|
AND m.`id_manufacturer` IN ('.implode(', ', $brands).')
|
|
ORDER BY m.`name` ASC
|
|
'),
|
|
));
|
|
|
|
$smarty->assign(array(
|
|
'meta_title' => $tag['value'].' '.(isset($on_i18n[$isolang])? $on_i18n[$isolang]: $on_i18n['en']).' '.Configuration::get('PS_SHOP_NAME'),
|
|
'meta_description' => substr(strip_tags($tag['legend']), 0, 120),
|
|
// 'meta_keywords' => '', // TODO: Handle keywords
|
|
));
|
|
|
|
require_once(dirname(__FILE__).'/../../header.php');
|
|
|
|
echo Module::display(dirname(__FILE__), 'featured.tpl');
|
|
} else {
|
|
if($ordering == 0) {
|
|
if(Module::isInstalled('privatesales_brands')) {
|
|
$sales = Sale::getSales(TRUE, (int) Configuration::get('PRIVATESALES_FEATURED_IGNORE') == 1? NULL: !((bool) Configuration::get('PRIVATESALES_GUESTLIST')), TRUE, (bool) Configuration::get('PRIVATESALES_FEATURED_CURRENT'), TRUE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'));
|
|
|
|
$brands = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT `id_brand`
|
|
FROM `'._DB_PREFIX_.'privatesale_brands`
|
|
WHERE `id_sale` IN ('.implode(', ', $sales).')
|
|
GROUP BY `id_brand`
|
|
') as $b) {
|
|
$brands[] = $b['id_brand'];
|
|
}
|
|
|
|
$smarty->assign(array(
|
|
'manufacturers' => Db::getInstance()->ExecuteS('
|
|
SELECT m.*, ml.`short_description`
|
|
FROM `'._DB_PREFIX_.'manufacturer` m
|
|
LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml
|
|
ON (
|
|
m.`id_manufacturer` = ml.`id_manufacturer`
|
|
AND ml.`id_lang` = '.(int) $cookie->id_lang.'
|
|
)
|
|
WHERE m.`active` = 1
|
|
AND m.`id_manufacturer` IN ('.implode(', ', $brands).')
|
|
ORDER BY m.`name` ASC
|
|
'),
|
|
));
|
|
} else {
|
|
$smarty->assign(array(
|
|
'manufacturers' => Manufacturer::getManufacturers(TRUE, (int) $cookie->id_lang, TRUE, FALSE, FALSE, TRUE),
|
|
));
|
|
}
|
|
|
|
$smarty->assign(array(
|
|
'meta_title' => (isset($list_i18n[$isolang])? $list_i18n[$isolang][0]: $list_i18n['en'][0]).' '.Configuration::get('PS_SHOP_NAME'),
|
|
'meta_description' => (isset($list_i18n[$isolang])? $list_i18n[$isolang][1]: $list_i18n['en'][1]),
|
|
// 'meta_keywords' => '', // TODO: Handle keywords
|
|
));
|
|
|
|
require_once(dirname(__FILE__).'/../../header.php');
|
|
|
|
echo Module::display(dirname(__FILE__), 'featured.tpl');
|
|
} elseif($ordering == 1) {
|
|
$smarty->assign(array(
|
|
'tags' => Db::getInstance()->ExecuteS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'privatesale_tag_lang`
|
|
WHERE `id_lang` = '.(int) $cookie->id_lang.'
|
|
ORDER BY `value` ASC
|
|
'),
|
|
));
|
|
|
|
$smarty->assign(array(
|
|
'meta_title' => (isset($list_i18n[$isolang])? $list_i18n[$isolang][0]: $list_i18n['en'][0]).' '.Configuration::get('PS_SHOP_NAME'),
|
|
'meta_description' => (isset($list_i18n[$isolang])? $list_i18n[$isolang][1]: $list_i18n['en'][1]),
|
|
// 'meta_keywords' => '', // TODO: Handle keywords
|
|
));
|
|
|
|
require_once(dirname(__FILE__).'/../../header.php');
|
|
|
|
echo Module::display(dirname(__FILE__), 'featured.tpl');
|
|
}
|
|
}
|
|
|
|
require_once(dirname(__FILE__).'/../../footer.php');
|