Jump to content

override category and display products from specefique category by ID


Recommended Posts

I am making some modifications in the way that customers explore products in a new page .tpl by overriding category


public function initContent()



        $module = new cdkeys();

        $psversion = $module->psversion();

        $cdkeys = CdKeysArchive::getAllByCustomer($this->context->customer->id);

        if (!is_array($cdkeys))


            $cdkeys = array();



        $products_partial = Product::getProducts($this->context->language->id, 0, 50, 'name', 'asc');

        $products = Product::getProductsProperties($this->context->language->id, $products_partial);


            'products' => $products,

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

                'cdkeys' => $cdkeys,

                'cdkeys_count' => count($cdkeys),

                'cdkeys_customer' => $this->context->customer,

                'psversion' => $psversion





Is there a function that works but gets products from a defined category using a category ID (rather than the current category) ?

I would like to display products from a specific category

When I put this code, it shows me all the products.

{foreach from=$products item=product name=products} {$product.name|escape:'htmlall':'UTF-8'} {/foreach}


Share this post

Link to post
Share on other sites



$idCategory = Tools::getValue('id_category');
if ($idCategory) {
	$productInCategory = Db::getInstance()->executeS('SELECT id_product FROM '._DB_PREFIX_.'category_product WHERE id_category = '.(int)$idCategory.' GROUP BY id_product');
	$products = array();
	foreach ($productInCategory as $idProducts){
		$product = new Product((int)$idProduct['id_product'], true, $this->context->language->id, $this->context->shop->id);
		$products[] = array($product);

if ($products){
	$this->context->smarty->assign ..........


Share this post

Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More