eagleman Posted July 1, 2022 Share Posted July 1, 2022 I am making some modifications in the way that customers explore products in a new page .tpl by overriding category /public_html/controllers/front/AutoDiagController.php public function initContent() { $module = new cdkeys(); $psversion = $module->psversion(); $cdkeys = CdKeysArchive::getAllByCustomer($this->context->customer->id); if (!is_array($cdkeys)) { $cdkeys = array(); } parent::initContent(); $products_partial = Product::getProducts($this->context->language->id, 0, 50, 'name', 'asc'); $products = Product::getProductsProperties($this->context->language->id, $products_partial); $this->context->smarty->assign(array( 'products' => $products, 'homeSize' => Image::getSize('home_default'), 'cdkeys' => $cdkeys, 'cdkeys_count' => count($cdkeys), 'cdkeys_customer' => $this->context->customer, 'psversion' => $psversion )); $this->setTemplate('AutoDiag.tpl'); } 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} Link to comment Share on other sites More sharing options...
knacky Posted July 3, 2022 Share Posted July 3, 2022 Category::getProducts Or: $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 .......... } 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