Jump to content

[solved] Need help to modify a product carrousel


obeatone

Recommended Posts

Hi all,

 

I bought a theme with a product carousel on homepage for my prestashop.

The problem is that the carousel shows recent product and I want to show only products from a specific category.

 

I tried to modify the code but i'm a beginner in PHP :(

Here the code that i think i have to modify :

 

public function getContent()

{

$output = '<h2>'.$this->displayName.'</h2>';

if (Tools::isSubmit('submitProductCarousel'))

{

Configuration::updateValue('NEW_PROD', (int)(Tools::getValue('new_prod')));

Configuration::updateValue('FEATURED_PROD', (int)(Tools::getValue('featured_prod')));

 

$output .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';

}

return $output.$this->displayForm();

}

 

public function hookDisplayHome($params)

{

$newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0);

 

$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);

$featuredProducts = $category->getProducts((int)Context::getContext()->language->id, 1, 10);

 

$this->smarty->assign(array(

'new_products' => $newProducts,

'show_new_prod' => (int)(Configuration::get('NEW_PROD')),

'featured_products' => $featuredProducts,

'show_featured_prod' => (int)(Configuration::get('FEATURED_PROD')),

'homeSize' => Image::getSize('home_default')

));

 

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

}

 

}

 

 

Anybody have an idea to modify my carrousel ? :)

 

Thank you in advance for your help and good afternoon !

Link to comment
Share on other sites

in your code you've got:

$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);

 

the category id is defined here:

Context::getContext()->shop->getCategory()

 

 

you can use category id instead this code, should help

Link to comment
Share on other sites

Ok thank you for your quick answer !

And what should i do ? My category id is 6.

 

I have to replace the line : $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);

by : $category = shop->getCategory(6), (int)Context::getContext()->language->id); ?

 

I don't want recent products, just products from my category

Link to comment
Share on other sites

Argh it doesn't work i have the same result :(

 

Here the entire code of my php file named prodcarousel.php :

My homepage is here: adelineaffre.com/store

 

 

 

 

<?php

 

if (!defined('_PS_VERSION_'))

exit;

 

class TptnProdCarousel extends Module

{

public function __construct()

{

$this->name = 'tptnprodcarousel';

$this->tab = 'Blocks';

$this->version = '1.0';

$this->author = 'Templatin';

$this->need_instance = 0;

 

parent::__construct();

 

$this->displayName = $this->l('Products Carousel on homepage - Templatin');

$this->description = $this->l('Displays featured and new products carousel on homepage.');

}

 

public function install()

{

if ( (parent::install() == false)

|| (Configuration::updateValue('NEW_PROD', 1) == false)

|| (Configuration::updateValue('FEATURED_PROD', 1) == false)

|| ($this->registerHook('displayHome') == false) )

return false;

return true;

}

 

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>

<label>'.$this->l('Show New Products Carousel').' :</label>

<div class="margin-form">

<input type="radio" name="new_prod" id="new_prod_on" value="1" '.(Tools::getValue('new_prod', Configuration::get('NEW_PROD')) ? 'checked="checked" ' : '').'/>

<label class="t" for="new_prod_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>

<input type="radio" name="new_prod" id="new_prod_off" value="0" '.(!Tools::getValue('new_prod', Configuration::get('NEW_PROD')) ? 'checked="checked" ' : '').'/>

<label class="t" for="new_prod_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>

</div>

 

<label>'.$this->l('Show Featured Products Carousel').' :</label>

<div class="margin-form">

<input type="radio" name="featured_prod" id="featured_prod_on" value="1" '.(Tools::getValue('featured_prod', Configuration::get('FEATURED_PROD')) ? 'checked="checked" ' : '').'/>

<label class="t" for="featured_prod_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>

<input type="radio" name="featured_prod" id="featured_prod_off" value="0" '.(!Tools::getValue('featured_prod', Configuration::get('FEATURED_PROD')) ? 'checked="checked" ' : '').'/>

<label class="t" for="featured_prod_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>

</div>

 

<div class="margin-form">

<input type="submit" name="submitProductCarousel" value="'.$this->l('Save').'" class="button" />

</div>

</fieldset>

</form>';

return $output;

}

 

public function getContent()

{

$output = '<h2>'.$this->displayName.'</h2>';

if (Tools::isSubmit('submitProductCarousel'))

{

Configuration::updateValue('NEW_PROD', (int)(Tools::getValue('new_prod')));

Configuration::updateValue('FEATURED_PROD', (int)(Tools::getValue('featured_prod')));

 

$output .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';

}

return $output.$this->displayForm();

}

 

public function hookDisplayHome($params)

{

$newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0);

 

$category = new Category(6, (int)Context::getContext()->language->id);

$featuredProducts = $category->getProducts((int)Context::getContext()->language->id, 1, 10);

 

$this->smarty->assign(array(

'new_products' => $newProducts,

'show_new_prod' => (int)(Configuration::get('NEW_PROD')),

'featured_products' => $featuredProducts,

'show_featured_prod' => (int)(Configuration::get('FEATURED_PROD')),

'homeSize' => Image::getSize('home_default')

));

 

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

}

 

}

 

thank you very very much for your help !! :)

Link to comment
Share on other sites

try to use:

 

$category = new Category(6, (int)Context::getContext()->language->id);
$featuredProducts = $category->getProducts((int)Context::getContext()->language->id, 1, 10);
$newProducts = $featuredProducts;

 

instead the:

$newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0);
$category = new Category(6, (int)Context::getContext()->language->id);
$featuredProducts = $category->getProducts((int)Context::getContext()->language->id, 1, 10);

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

Hi Vekia,

 

How can i have multiple product carousel in homepage? let's say i want it this way.

 

Carousel 1 -> Products from category A

Carousel 2 -> Products from category B

Carousel 3 -> Products from category C

 

and so on...

 

Is there any free module of this? Do you have a solution?

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...