name = 'blocknewproducts'; $this->tab = 'Blocks'; $this->version = 0.9; parent::__construct(); $this->displayName = $this->l('New products block'); $this->description = $this->l('Displays a block featuring newly added products'); } function install() { if (parent::install() == false OR $this->registerHook('rightColumn') == false OR Configuration::updateValue('NEW_PRODUCTS_NBR', 5) == false) return false; return true; } public function getContent() { $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitBlockNewProducts')) { if (!$productNbr = Tools::getValue('productNbr') OR empty($productNbr)) $output .= '
'.$this->l('You should fill the "products displayed" field').'
'; elseif (intval($productNbr) == 0) $output .= '
'.$this->l('Invalid number.').'
'; else { Configuration::updateValue('NEW_PRODUCTS_NBR', intval($productNbr)); $output .= '
'.$this->l('Confirmation').''.$this->l('Settings updated').'
'; } } return $output.$this->displayForm(); } public function displayForm() { $output = '
'.$this->l('Settings').'

'.$this->l('Set the number of products to be displayed in this block').'

'; return $output; } function hookRightColumn($params) { global $smarty; $newProducts = Product::getNewProducts(intval($params['cookie']->id_lang), 0, intval(Configuration::get('NEW_PRODUCTS_NBR'))); $smarty->assign(array('new_products' => $newProducts, 'mediumSize' => Image::getSize('medium'))); return $this->display(__FILE__, 'blocknewproducts.tpl'); } function hookLeftColumn($params) { return $this->hookRightColumn($params); } } ?>