obeatone Posted May 6, 2013 Share Posted May 6, 2013 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 More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 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 More sharing options...
obeatone Posted May 6, 2013 Author Share Posted May 6, 2013 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 More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 just type there 6 and let me know what's going on after that :-) code for you: $category = new Category(6, (int)Context::getContext()->language->id); Link to comment Share on other sites More sharing options...
obeatone Posted May 6, 2013 Author Share Posted May 6, 2013 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 More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 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 More sharing options...
obeatone Posted May 6, 2013 Author Share Posted May 6, 2013 It woooorks, thank you veeeery muchhhh Best ! Thibault Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 yeah im glad that it works for you :-) now i can go ahead and mark this thread as solved. btw. very nice shop, outstanding design! WOW! Link to comment Share on other sites More sharing options...
obeatone Posted May 6, 2013 Author Share Posted May 6, 2013 Thank you hehe Have a nice afternoon ! Regards, Thibaukt Link to comment Share on other sites More sharing options...
Dehswitat1 Posted June 6, 2013 Share Posted June 6, 2013 Can you use more than 1 id with this line ? $category =newCategory(6,(int)Context::getContext()->language->id); Link to comment Share on other sites More sharing options...
vekia Posted June 6, 2013 Share Posted June 6, 2013 nope, it isnt possible. when you use: $category = new Category($id); you define ONE object. it isnt possible to define many objects in one variable. Link to comment Share on other sites More sharing options...
Dehswitat1 Posted June 7, 2013 Share Posted June 7, 2013 Ok, thank you for your answer vekia Link to comment Share on other sites More sharing options...
vekia Posted June 7, 2013 Share Posted June 7, 2013 you're welcome if you've got any other questions - feel free to write Link to comment Share on other sites More sharing options...
juraganpsd Posted August 22, 2013 Share Posted August 22, 2013 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 More sharing options...
vekia Posted August 22, 2013 Share Posted August 22, 2013 in this case you will need 3 the same modules with different settings, there is not other way to achieve what you want you can try to duplicate (triplicate?) module that you use 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