* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7616 $ * @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 BlockBestSellers extends Module { private $_html = ''; private $_postErrors = array(); public function __construct() { $this->name = 'blockbestsellers'; $this->tab = 'front_office_features'; $this->version = '1.1'; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Top seller block'); $this->description = $this->l('Add a block displaying the shop\'s top sellers.'); } /** * @see ModuleCore::install() */ public function install() { if (!parent::install() OR !$this->registerHook('rightColumn') OR !$this->registerHook('header') OR !$this->registerHook('updateOrderStatus') OR !ProductSale::fillProductSales()) return false; return true; } /** * Called in administration -> module -> configure */ public function getContent() { $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitBestSellers')) { Configuration::updateValue('PS_BLOCK_BESTSELLERS_DISPLAY', (int)(Tools::getValue('always_display'))); $output .= '
'.$this->l('Confirmation').''.$this->l('Settings updated').'
'; } return $output.$this->displayForm(); } public function displayForm() { return '
'.$this->l('Settings').'

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

'; } public function hookRightColumn($params) { if (Configuration::get('PS_CATALOG_MODE')) return ; global $smarty; $currency = new Currency((int)($params['cookie']->id_currency)); $bestsellers = ProductSale::getBestSalesLight((int)($params['cookie']->id_lang), 0, 5); if (!$bestsellers AND !Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY')) return; $best_sellers = array(); if($bestsellers) foreach ($bestsellers AS $bestseller) { $bestseller['price'] = Tools::displayPrice(Product::getPriceStatic((int)($bestseller['id_product'])), $currency); $best_sellers[] = $bestseller; } $smarty->assign(array( 'best_sellers' => $best_sellers, 'mediumSize' => Image::getSize('medium'))); return $this->display(__FILE__, 'blockbestsellers.tpl'); } public function hookLeftColumn($params) { return $this->hookRightColumn($params); } public function hookHeader($params) { if (Configuration::get('PS_CATALOG_MODE')) return ; Tools::addCSS(($this->_path).'blockbestsellers.css', 'all'); } public function hookHome($params) { if (Configuration::get('PS_CATALOG_MODE')) return ; global $smarty; $currency = new Currency((int)($params['cookie']->id_currency)); $bestsellers = ProductSale::getBestSalesLight((int)($params['cookie']->id_lang), 0, 4); if (!$bestsellers AND !Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY')) return; $best_sellers = array(); if($bestsellers) foreach ($bestsellers AS $bestseller) { $bestseller['price'] = Tools::displayPrice(Product::getPriceStatic((int)($bestseller['id_product'])), $currency); $best_sellers[] = $bestseller; } $smarty->assign(array( 'best_sellers' => $best_sellers, 'homeSize' => Image::getSize('home'))); return $this->display(__FILE__, 'blockbestsellers-home.tpl'); } }