cyberfly Posted March 28, 2014 Share Posted March 28, 2014 (edited) Hi guys, I want to get specific category product list and display it at my template The page already display the product for that active category A, but I also want to show the product for category B in the same page. I want to achieve something like this This is my code, how do I change to get the specific product category by category id? {if isset($products)} <div id="" class="ca-container product_scroller"> <div class="ca-wrapper"> {foreach from=$products item=product name=products} <div class="ca-item ca-item-1"> <div class="ca-item-main"> <div class="ca-image"> <a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}" class="ca-url"> <img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'Medium_la_default')|escape:'html'}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" width="104px" height="104px" /> </a> </div> <div class="ca-label"><a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}" class="ca-url">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a></div> <!-- <a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}" class="ca-more">{l s='view details'}</a> --> </div> </div> {/foreach} </div> </div> <hr class="rags_subcategory"> {/if} Edited March 28, 2014 by cyberfly (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted March 29, 2014 Share Posted March 29, 2014 In the php file, choose the category ID you want, then $category = new Category($id_category_you_chose); $products = $category->getProducts($this->context->language->id); THe full parameters list: public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null) 2 Link to comment Share on other sites More sharing options...
cyberfly Posted March 29, 2014 Author Share Posted March 29, 2014 In the php file, choose the category ID you want, then $category = new Category($id_category_you_chose); $products = $category->getProducts($this->context->language->id); THe full parameters list: public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null) Hi there thanks for the help. Just a question, since I override the category controller, at which function in the override category controller should I put your code? Many thanks again Link to comment Share on other sites More sharing options...
cyberfly Posted March 31, 2014 Author Share Posted March 31, 2014 (edited) Problem solve. This is my code on override Category controller <?php //file in override/controllers/front/CategoryController.php class CategoryController extends CategoryControllerCore { public function initContent() { parent::initContent(); //load my custom template page, you can comment out if you want $this->setTemplate($this->getTpl()); $acc_products = $this->getAccessoriesProducts(); $this->context->smarty->assign(array( 'acc_products' => (isset($acc_products) && $acc_products) ? $acc_products : null )); } protected function getAccessoriesProducts() { $accessories_cat_id = 239; $acc_category = new Category($accessories_cat_id); $acc_products = $acc_category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay); return $acc_products; } } Edited March 31, 2014 by cyberfly (see edit history) 1 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