Jump to content

Edit Homefeatured.tpl


Recommended Posts

Hi everyone :)

 

I have to edit the homefeatured.tpl file including the features of the product.

I saw that product.tpl uses this script

 

 

{if isset($features) && $features}

<!-- product's features -->

<ul id="idTab2" class="bullet">

{foreach from=$features item=feature}

{if isset($feature.value)}

<li><span>{$feature.name|escape:'htmlall':'UTF-8'}</span> {$feature.value|escape:'htmlall':'UTF-8'}</li>

{/if}

{/foreach}

</ul>

{/if}

 

to print them but if I include this in homefeatured.tpl it doesn't work.

Probably it's because $features it wasn't set up.

Any idea how can I do this?

 

Thank you in advance!

Patrizia

Link to comment
Share on other sites

Hi,

 

You need attach features to each product on modules/homefeatured/homefeatured.php. Try this code:

 

public function hookDisplayHome($params)
{
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

//attach features to product
foreach($products as &$product){
$productObj = new Product($product['id_product']);
$product['features'] = $productObj->getFrontFeatures($params['cookie']->id_lang); //get feature collection
}

$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize('home'),
));

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

 

Regards

Edited by Alexander Simonchik (see edit history)
  • Like 1
Link to comment
Share on other sites

Hi,

 

You need attach features to each product on modules/homefeatured/homefeatured.php. Try this code:

 

public function hookDisplayHome($params)
{
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

//attach features to product
foreach($products as &$product){
$productObj = new Product($product['id_product']);
$product['features'] = $productObj->getFrontFeatures($params['cookie']->id_lang); //get feature collection
}

$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize('home'),
));

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

 

Regards

 

Thank you :)

 

I added this code to the .tpl file

 

 

{if $product.features}

{foreach from=$product.features item=feature name=features}

<span style="font-weight:bold; text-transform:uppercase">{$feature.name|escape:'htmlall':'UTF-8'}:</span> {$feature.value|escape:'htmlall':'UTF-8'}<br/>

{/foreach}

 

{/if}

 

and it worked!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...