Jump to content

Duplicate HomeFeatured module - no products


Recommended Posts

Hi,

 

I have a problem in finalizing duplication of HomeFeatured module. Maybe someone has an ideea or had the same issue and have a solution to it. I have successfully duplicate HomeFeatured module. It shows in my shop home page. Trouble is that I get no products in it for some of my categories, the one that I need. For some I do get. What is particular to the categories I do not get results (I do have products defined in them) is that they are recently defined. They have same access level like the ones I get products in it. In order to get products in a category I have changed below method in homefeatured1.php. Changes are marked in red.

 

function hookHome($params)

{

global $smarty;

 

$category = new Category(80, (int)Configuration::get('PS_LANG_DEFAULT'));

$nb = (int)Configuration::get('HOME_FEATURED1_NBR');

 

$smarty->assign(array(

'products' => $category->getProducts((int)$params['cookie']->id_lang, 80, ($nb ? $nb : 10)),

'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),

'homeSize' => Image::getSize('home')));

 

return $this->display(__FILE__, 'homefeatured1.tpl');

}

 

Thanks.

Edited by silberstern (see edit history)
Link to comment
Share on other sites

This work for me:

 

<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2012 PrestaShop SA
*  @version  Release: $Revision: 14011 $
*  @license	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
class HomeFeatured2 extends Module
{
private $_html = '';
private $_postErrors = array();
function __construct()
{
 $this->name = 'homefeatured2';
 $this->tab = 'front_office_features';
 $this->version = '0.9';
 $this->author = 'PrestaShop';
 $this->need_instance = 0;
 parent::__construct();

 $this->displayName = $this->l('Featured Products on the homepage');
 $this->description = $this->l('Displays Featured Products in the middle of your homepage.');
}
function install()
{
 if (!Configuration::updateValue('HOME_FEATURED_NBR2', 4) OR !parent::install() OR !$this->registerHook('productfooter') )
  return false;
 return true;
}
public function getContent()
{
 $output = '<h2>'.$this->displayName.'</h2>';
 if (Tools::isSubmit('submitHomeFeatured2'))
 {
  $nbr = (int)(Tools::getValue('nbr'));
  if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
$errors[] = $this->l('Invalid number of products');
  else
Configuration::updateValue('HOME_FEATURED_NBR2', (int)($nbr));
  if (isset($errors) AND sizeof($errors))
$output .= $this->displayError(implode('<br />', $errors));
  else
$output .= $this->displayConfirmation($this->l('Settings updated'));
 }
 return $output.$this->displayForm();
}
public function displayForm()
{
 $output = '
 <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
  <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
<p>'.$this->l('In order to add products to your homepage, just add them to the "home" category.').'</p><br />
<label>'.$this->l('Number of products displayed').'</label>
<div class="margin-form">
 <input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR2')))).'" />
 <p class="clear">'.$this->l('The number of products displayed on homepage (default: 10).').'</p>

</div>
<center><input type="submit" name="submitHomeFeatured2" value="'.$this->l('Save').'" class="button" /></center>
  </fieldset>
 </form>';
 return $output;
}
function hookproductfooter($params)
{
 global $smarty;
 $category = new Category(3, Configuration::get('PS_LANG_DEFAULT'));
 $nb = (int)(Configuration::get('HOME_FEATURED_NBR2'));
 $products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 20));
 if ($products) {
 shuffle($products);
 array_splice($products, ($nb ? $nb : 20));
 }
 $smarty->assign(array(
 'products' => $products,
 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
 'homeSize' => Image::getSize('home')));
 return $this->display(__FILE__, 'homefeatured2.tpl');
}
}

 

{*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2012 PrestaShop SA
*  @version  Release: $Revision: 14011 $
*  @license	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}
<!-- MODULE Home Featured 2 Products -->
<div id="productscategory_list" class="products_block">
<h4>{l s='Featured products' mod='homefeatured2'}</h4>
{if isset($products) AND $products}
 <div class="block_content">
  {assign var='liHeight' value=342}
  {assign var='nbItemsPerLine' value=4}
  {assign var='nbLi' value=$products|@count}
  {math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}
  {math equation="nbLines*liHeight" nbLines=$nbLines|ceil liHeight=$liHeight assign=ulHeight}
  <ul>
  {foreach from=$products item=product name=homeFeaturedProducts2}
<li class="ajax_block_product {if $smarty.foreach.homeFeaturedProducts2.first}first_item{elseif $smarty.foreach.homeFeaturedProducts2.last}last_item{else}item{/if} {if $smarty.foreach.homeFeaturedProducts2.iteration%$nbItemsPerLine == 0}last_item_of_line{elseif $smarty.foreach.homeFeaturedProducts2.iteration%$nbItemsPerLine == 1}clear{/if} {if $smarty.foreach.homeFeaturedProducts2.iteration > ($smarty.foreach.homeFeaturedProducts2.total - ($smarty.foreach.homeFeaturedProducts2.total % $nbItemsPerLine))}last_line{/if}">
 <a href="{$product.link}" title="{$product.name|escape:html:'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home')}" alt="{$product.name|escape:html:'UTF-8'}" /></a>
 <a href="{$product.link}" class="shoo-product-name" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|truncate:22:'...'|escape:'htmlall':'UTF-8'}</a>
{if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}<span class="price rouble">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span>{/if}
</li>
  {/foreach}
  </ul>
 </div>
{else}
 <p>{l s='No featured products' mod='homefeatured2'}</p>
{/if}
</div>
<!-- /MODULE Home Featured 2 Products -->

Edited by Kerm (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...