//SupplierController : Refacto done

This commit is contained in:
mDeflotte committed 2011-09-28 13:43:00 +00:00
1 parent 281663a212
commit 942cc9a252
1 file changed
+35 -18
+35 -18
View File
@@ -43,6 +43,10 @@ class SupplierControllerCore extends FrontController
parent::canonicalRedirection($this->context->link->getSupplierLink($this->supplier)); parent::canonicalRedirection($this->context->link->getSupplierLink($this->supplier));
} }
/**
* Initialize supplier controller
* @see FrontController::init()
*/
public function init() public function init()
{ {
parent::init(); parent::init();
@@ -51,7 +55,7 @@ class SupplierControllerCore extends FrontController
{ {
$this->supplier = new Supplier($id_supplier, $this->context->language->id); $this->supplier = new Supplier($id_supplier, $this->context->language->id);
if (!Validate::isLoadedObject($this->supplier) OR !$this->supplier->active) if (!Validate::isLoadedObject($this->supplier) || !$this->supplier->active)
{ {
header('HTTP/1.1 404 Not Found'); header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found'); header('Status: 404 Not Found');
@@ -62,11 +66,32 @@ class SupplierControllerCore extends FrontController
} }
} }
/**
* Assign template vars related to page content
* @see FrontController::process()
*/
public function process() public function process()
{ {
if (Validate::isLoadedObject($this->supplier) AND $this->supplier->active AND $this->supplier->isAssociatedToGroupShop()) if (Validate::isLoadedObject($this->supplier) && $this->supplier->active && $this->supplier->isAssociatedToGroupShop())
$this->assignOne();
else if (!Tools::getValue('id_supplier'))
$this->assignAll();
if ($this->supplier)
{ {
$nbProducts = $this->supplier->getProducts($this->supplier->id, NULL, NULL, NULL, $this->orderBy, $this->orderWay, true); $this->productSort();
$this->setTemplate(_PS_THEME_DIR_.'supplier.tpl');
}
else
$this->setTemplate(_PS_THEME_DIR_.'supplier-list.tpl');
}
/**
* Assign template vars if displaying one supplier
*/
private function assignOne()
{
$nbProducts = $this->supplier->getProducts($this->supplier->id, null, null, null, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$nbProducts); $this->pagination((int)$nbProducts);
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'nb_products' => $nbProducts, 'nb_products' => $nbProducts,
@@ -75,7 +100,11 @@ class SupplierControllerCore extends FrontController
'supplier' => $this->supplier, 'supplier' => $this->supplier,
)); ));
} }
elseif (!Tools::getValue('id_supplier'))
/**
* Assign template vars if displaying the supplier list
*/
private function assignAll()
{ {
if (Configuration::get('PS_DISPLAY_SUPPLIERS')) if (Configuration::get('PS_DISPLAY_SUPPLIERS'))
{ {
@@ -84,8 +113,8 @@ class SupplierControllerCore extends FrontController
$this->pagination($nbProducts); $this->pagination($nbProducts);
$suppliers = Supplier::getSuppliers(true, $this->context->language->id, true, $this->p, $this->n); $suppliers = Supplier::getSuppliers(true, $this->context->language->id, true, $this->p, $this->n);
foreach ($suppliers AS &$row) foreach ($suppliers as &$row)
$row['image'] = (!file_exists(_PS_SUPP_IMG_DIR_.'/'.$row['id_supplier'].'-medium.jpg')) ? $this->context->language->iso_code.'-default' : $row['id_supplier'];; $row['image'] = (!file_exists(_PS_SUPP_IMG_DIR_.'/'.$row['id_supplier'].'-medium.jpg')) ? $this->context->language->iso_code.'-default' : $row['id_supplier'];
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'pages_nb' => ceil($nbProducts / (int)$this->n), 'pages_nb' => ceil($nbProducts / (int)$this->n),
@@ -98,16 +127,4 @@ class SupplierControllerCore extends FrontController
else else
$this->context->smarty->assign('nbSuppliers', 0); $this->context->smarty->assign('nbSuppliers', 0);
} }
if ($this->supplier)
$this->setTemplate(_PS_THEME_DIR_.'supplier.tpl');
else
$this->setTemplate(_PS_THEME_DIR_.'supplier-list.tpl');
}
public function displayHeader($display = true)
{
parent::displayHeader();
$this->productSort();
}
} }