Kazi Azim Posted February 21, 2015 Share Posted February 21, 2015 (edited) Hello there, Please give me an idea how can I solve it? I have added few new home tabs in my site (Those are mainly category. I need them as home tab button also). Now I want to make those button functional, I want to get selected category's products when I'll click on any tab, as when I click on "Popular" or "Best Sellers" and it shows it's products. I've added new codes in themes/default-bootstrap/modules/blockbestsellers/tab.tpl file. <li><a data-toggle="tab" href="http://www.garage-shelving.co.uk/33-gs265-shelving" class="blocknewproducts">{l s='GS265' mod='blocknewproducts'}</a></li> <li><a data-toggle="tab" href="http://www.garage-shelving.co.uk/34-gs340-shelving" class="blocknewproducts">{l s='GS340' mod='blocknewproducts'}</a></li> <li><a data-toggle="tab" href="http://www.garage-shelving.co.uk/31-gs800-shelving" class="blocknewproducts">{l s='GS800' mod='blocknewproducts'}</a></li> <li><a data-toggle="tab" href="http://www.garage-shelving.co.uk/39-pallet-racking" class="blocknewproducts">{l s='Pallet Racking' mod='blocknewproducts'}</a></li> <li><a data-toggle="tab" href="http://www.garage-shelving.co.uk/43-workbenches" class="blocknewproducts">{l s='Workbenches' mod='blocknewproducts'}</a></li> <li><a data-toggle="tab" href="#blockbestsellers" class="blockbestsellers">{l s='Best Sellers' mod='blockbestsellers'}</a></li> And please check the link below and let me know what to do. [Removed at the request of domain owner] [PrestaShop 1.6.0.9] Screenshot: PS:1. This is my client's site, I'm not the owner.2. I've checked Nemo's http://nemops.com/prestashop-new-homepage-tabs/, but didn't understand properly how to get the needed feature. Thanks in advance, Kazi Azim Edited May 12, 2015 by Oron Reason : Please remove our website link from this post. (see edit history) Link to comment Share on other sites More sharing options...
fred-vinapresta Posted February 21, 2015 Share Posted February 21, 2015 Hi, first you have to modify the php file of you module to call the category products and send them to the view by smarty for example int the function hookdisplayHomeTabContent from blockbestsellers.php you can add something like $category33 = new Category(33, $this->context->language->id) ; $products_cat_33 = $category33->getProducts(); $category34 = new Category(34, $this->context->language->id) ; $products_cat_34 = $category34->getProducts(); $this->smarty->assign(array( 'products_cat_33' => $products_cat_33, 'products_cat_34' =>$products_cat_34 )); with that, you will be able to do a loop and display products for each tab's relative content 1 Link to comment Share on other sites More sharing options...
NeoXPress Posted February 21, 2015 Share Posted February 21, 2015 Looking at your site, it seems the current ones are just categories, so if you add a new category in your back office, it should show up in the home page,. Link to comment Share on other sites More sharing options...
Kazi Azim Posted February 22, 2015 Author Share Posted February 22, 2015 Hi, first you have to modify the php file of you module to call the category products and send them to the view by smarty for example int the function hookdisplayHomeTabContent from blockbestsellers.php you can add something like $category33 = new Category(33, $this->context->language->id) ; $products_cat_33 = $category33->getProducts(); $category34 = new Category(34, $this->context->language->id) ; $products_cat_34 = $category34->getProducts(); $this->smarty->assign(array( 'products_cat_33' => $products_cat_33, 'products_cat_34' =>$products_cat_34 ));with that, you will be able to do a loop and display products for each tab's relative content Thank you very much Fred, After open "blockbestsellers.php" file I get confuse how and where I'll add your those codes, can you show me that too kindly? Here is my site's blockbestsellers.php file's full codes. Thanks again in advance. if (!defined('_PS_VERSION_')) exit; class BlockBestSellers extends Module { protected static $cache_best_sellers; public function __construct() { $this->name = 'blockbestsellers'; $this->tab = 'front_office_features'; $this->version = '1.5.8'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Top-sellers block'); $this->description = $this->l('Adds a block displaying your store\'s top-selling products.'); $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); } public function install() { $this->_clearCache('*'); if (!parent::install() || !$this->registerHook('header') || !$this->registerHook('actionOrderStatusPostUpdate') || !$this->registerHook('addproduct') || !$this->registerHook('updateproduct') || !$this->registerHook('deleteproduct') || !$this->registerHook('displayHomeTab') || !$this->registerHook('displayHomeTabContent') || !ProductSale::fillProductSales() ) return false; // Hook the module either on the left or right column $theme = new Theme(Context::getContext()->shop->id_theme); if ((!$theme->default_left_column || !$this->registerHook('leftColumn')) && (!$theme->default_right_column || !$this->registerHook('rightColumn')) ) { // If there are no colums implemented by the template, throw an error and uninstall the module $this->_errors[] = $this->l('This module need to be hooked in a column and your theme does not implement one'); parent::uninstall(); return false; } Configuration::updateValue('PS_BLOCK_BESTSELLERS_TO_DISPLAY', 10); return true; } public function uninstall() { $this->_clearCache('*'); return parent::uninstall(); } public function hookAddProduct($params) { $this->_clearCache('*'); } public function hookUpdateProduct($params) { $this->_clearCache('*'); } public function hookDeleteProduct($params) { $this->_clearCache('*'); } public function hookActionOrderStatusPostUpdate($params) { $this->_clearCache('*'); } public function _clearCache($template, $cache_id = NULL, $compile_id = NULL) { parent::_clearCache('blockbestsellers.tpl'); parent::_clearCache('blockbestsellers-home.tpl', 'blockbestsellers-home'); parent::_clearCache('tab.tpl', 'blockbestsellers-tab'); } /** * Called in administration -> module -> configure */ public function getContent() { $output = ''; if (Tools::isSubmit('submitBestSellers')) { Configuration::updateValue('PS_BLOCK_BESTSELLERS_DISPLAY', (int)Tools::getValue('PS_BLOCK_BESTSELLERS_DISPLAY')); Configuration::updateValue('PS_BLOCK_BESTSELLERS_TO_DISPLAY', (int)Tools::getValue('PS_BLOCK_BESTSELLERS_TO_DISPLAY')); $this->_clearCache('*'); $output .= $this->displayConfirmation($this->l('Settings updated')); } return $output.$this->renderForm(); } public function renderForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Settings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Products to display'), 'name' => 'PS_BLOCK_BESTSELLERS_TO_DISPLAY', 'desc' => $this->l('Determine the number of product to display in this block'), 'class' => 'fixed-width-xs', ), array( 'type' => 'switch', 'label' => $this->l('Always display this block'), 'name' => 'PS_BLOCK_BESTSELLERS_DISPLAY', 'desc' => $this->l('Show the block even if no best sellers are available.'), 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ) ), 'submit' => array( 'title' => $this->l('Save') ) ) ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $this->fields_form = array(); $helper->identifier = $this->identifier; $helper->submit_action = 'submitBestSellers'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } public function getConfigFieldsValues() { return array( 'PS_BLOCK_BESTSELLERS_TO_DISPLAY' => (int)Tools::getValue('PS_BLOCK_BESTSELLERS_TO_DISPLAY', Configuration::get('PS_BLOCK_BESTSELLERS_TO_DISPLAY')), 'PS_BLOCK_BESTSELLERS_DISPLAY' => (int)Tools::getValue('PS_BLOCK_BESTSELLERS_DISPLAY', Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY')), ); } public function hookHeader($params) { if (Configuration::get('PS_CATALOG_MODE')) return; if (isset($this->context->controller->php_self) && $this->context->controller->php_self == 'index') $this->context->controller->addCSS(_THEME_CSS_DIR_.'product_list.css'); $this->context->controller->addCSS($this->_path.'blockbestsellers.css', 'all'); } public function hookDisplayHomeTab($params) { if (!$this->isCached('tab.tpl', $this->getCacheId('blockbestsellers-tab'))) { BlockBestSellers::$cache_best_sellers = $this->getBestSellers($params); $this->smarty->assign('best_sellers', BlockBestSellers::$cache_best_sellers); } if (BlockBestSellers::$cache_best_sellers === false) return false; return $this->display(__FILE__, 'tab.tpl', $this->getCacheId('blockbestsellers-tab')); } public function hookdisplayHomeTabContent($params) { if (!$this->isCached('blockbestsellers-home.tpl', $this->getCacheId('blockbestsellers-home'))) { $this->smarty->assign(array( 'best_sellers' => BlockBestSellers::$cache_best_sellers, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')) )); } if (BlockBestSellers::$cache_best_sellers === false) return false; return $this->display(__FILE__, 'blockbestsellers-home.tpl', $this->getCacheId('blockbestsellers-home')); } public function hookRightColumn($params) { if (!$this->isCached('blockbestsellers.tpl', $this->getCacheId('blockbestsellers-col'))) { if (!isset(BlockBestSellers::$cache_best_sellers)) BlockBestSellers::$cache_best_sellers = $this->getBestSellers($params); $this->smarty->assign(array( 'best_sellers' => BlockBestSellers::$cache_best_sellers, 'display_link_bestsellers' => Configuration::get('PS_DISPLAY_BEST_SELLERS'), 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'smallSize' => Image::getSize(ImageType::getFormatedName('small')) )); } if (BlockBestSellers::$cache_best_sellers === false) return false; return $this->display(__FILE__, 'blockbestsellers.tpl', $this->getCacheId('blockbestsellers-col')); } public function hookLeftColumn($params) { return $this->hookRightColumn($params); } protected function getBestSellers($params) { if (Configuration::get('PS_CATALOG_MODE')) return false; if (!($result = ProductSale::getBestSalesLight((int)$params['cookie']->id_lang, 0, (int)Configuration::get('PS_BLOCK_BESTSELLERS_TO_DISPLAY')))) return (Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false); $currency = new Currency($params['cookie']->id_currency); $usetax = (Product::getTaxCalculationMethod((int)$this->context->customer->id) != PS_TAX_EXC); foreach ($result as &$row) $row['price'] = Tools::displayPrice(Product::getPriceStatic((int)$row['id_product'], $usetax), $currency); return $result; } } Link to comment Share on other sites More sharing options...
Kazi Azim Posted February 22, 2015 Author Share Posted February 22, 2015 Looking at your site, it seems the current ones are just categories, so if you add a new category in your back office, it should show up in the home page,. Hi NeoXPress, Thank you for your reply, can you explain a bit more please? I didn't get it unfortunately. Regards Kazi Azim Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now