* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class BlockNewProducts extends Module { public function __construct() { $this->name = 'blocknewproducts'; $this->tab = 'front_office_features'; $this->version = 0.9; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('New products block'); $this->description = $this->l('Displays a block featuring newly added products.'); } public function install() { if (parent::install() == false OR $this->registerHook('rightColumn') == false OR $this->registerHook('header') == 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('Please fill in the "products displayed" field.').'
'; elseif ((int)($productNbr) == 0) $output .= '
'.$this->l('Invalid number.').'
'; else { Configuration::updateValue('PS_BLOCK_NEWPRODUCTS_DISPLAY', (int)(Tools::getValue('always_display'))); Configuration::updateValue('NEW_PRODUCTS_NBR', (int)($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').'

'.$this->l('Show the block even if no products are available.').'

'; return $output; } public function hookRightColumn($params) { global $smarty; $newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0, (int)(Configuration::get('NEW_PRODUCTS_NBR'))); if (!$newProducts AND !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) return; $smarty->assign(array('new_products' => $newProducts, 'mediumSize' => Image::getSize('medium'))); return $this->display(__FILE__, 'blocknewproducts.tpl'); } public function hookLeftColumn($params) { return $this->hookRightColumn($params); } public function hookHeader($params) { Tools::addCSS(($this->_path).'blocknewproducts.css', 'all'); } }