MihaiAlex Posted July 28, 2014 Share Posted July 28, 2014 Hello, I have a module that creats a new page filled with products.What I need is to display a specific category or specific products.I will attach the code from allproducts.php <?php Class testmoduleAllproductsModuleFrontController extends ModuleFrontController { public function init() { $this->page_name = 'guestonmischa'; // page_name and body id $this->display_column_left = true; parent::init(); } public function initContent() { parent::initContent(); $products_count = $this->module->countAllProducts(); $this->pagination($products_count); // needs to be here, so that page number and products per page are assigned to "p" and "n" $products = Product::getProductsProperties($this->context->language->id, $products_partial); /* Retrieving product images */ foreach ($products as $key => $product) { foreach ($products as $key => $product) { $products[$key]['id_image'] = Product::getCover($product['id_product'])['id_image']; } } $this->context->smarty->assign(array( 'products' => $products, 'homeSize' => Image::getSize('home_default') )); $this->setTemplate('allproducts.tpl'); } public function setMedia() { parent::setMedia(); $this->addCSS(__PS_BASE_URI__.'modules/'.$this->module->name.'/css/'.$this->module->name.'.css'); } } Can someone help me to dispaly here a category or a product by ID for example. Thanks! Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 you can check how homefeatured addon (default one) gets products from "home" category. then you will be alter code to get products from any other category you want. Link to comment Share on other sites More sharing options...
MihaiAlex Posted July 28, 2014 Author Share Posted July 28, 2014 From what I found at this point this line of cod help the module to display all products: $products_partial = Product::getProducts($this->context->language->id, ((int)$this->p - 1) * (int)$this->n, $this->n, 'name', 'asc'); I'm wondering if here I can add a code to display Category with ID 4 for example. Link to comment Share on other sites More sharing options...
vekia Posted July 28, 2014 Share Posted July 28, 2014 you were so close $category = new Category(4, (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products=$category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position'); Link to comment Share on other sites More sharing options...
MihaiAlex Posted July 28, 2014 Author Share Posted July 28, 2014 After I add your code I get blamk page.The source code for my module is from here: http://nemops.com/creating-new-pages-in-prestashop/#.U9bIW_l_vff Link to comment Share on other sites More sharing options...
MihaiAlex Posted July 29, 2014 Author Share Posted July 29, 2014 I found the solution.I will attach the code if someone will need this kind of option: public function initContent() { parent::initContent(); $products_count = $this->module->countAllProducts(); $this->pagination($products_count); // needs to be here, so that page number and products per page are assigned to "p" and "n" $products_partial = Product::getProducts($this->context->language->id, ((int)$this->p - 1) * (int)$this->n, $this->n, 'name', 'asc'); $products = Product::getProductsProperties($this->context->language->id, $products_partial); $category = new Category(33, (int)Context::getContext()->shop->getCategory(), (int)Context::getContext()->id_lang); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); 33 is the ID of category Link to comment Share on other sites More sharing options...
vekia Posted July 29, 2014 Share Posted July 29, 2014 hello it's exactly the same code as i suggested where is the difference? ;-) Link to comment Share on other sites More sharing options...
airplanenoise Posted August 10, 2014 Share Posted August 10, 2014 i there - seems like this is close to being what I was looking for : trying to include a simple block that shows "new" products from a specific category on the homepage. I actually need to call it twice : once for category A, and another for category B. What would be ideal, would be to create a module that can have several instances, like a widget block "newest in category", with a hook onto the homepage, that's got an admin backend to select which category to pull from and how many to display. it's very much like the homefeatured block, so i tried to duplicate it, but i am still not sure i get where/how/when to put what, especially that often in this forum it refers to 1.5 or below and I jumped in on 1.6... too bad, it seems, as a lot of the resources are still for 1.5 and below. so — long story short : i want to duplicate the homefeatured block so that it shows latest products in a specific category, and i want to be able to call that block on the homepage only, but twice, once for category A and once for category B... can someone put me on track, and I will try it myself ? thanks — A Link to comment Share on other sites More sharing options...
Recommended Posts