JoelWebsites Posted January 12, 2015 Share Posted January 12, 2015 Hi I want help to create a module that displays all products eg. In normal php we would query the database <?php $sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = $conn->query($sql);if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; } ?> How do we echo this output to .tpl in prestashop in a module configuration section...Thanks ..your help will be appreciated Link to comment Share on other sites More sharing options...
vekia Posted January 12, 2015 Share Posted January 12, 2015 hello Product::getProducts function is what you're looking for. Link to comment Share on other sites More sharing options...
JoelWebsites Posted January 13, 2015 Author Share Posted January 13, 2015 I used $all_product = Product::getProducts(Configuration::get('PS_LANG_DEFAULT'),0,1000000); in the assign array I tried to use getproducts for message variable..but the tpl file is giving me a fatal error.Please can you elaborate on how should I use the function ? many thanks. private function _displayContent($message) { Tools::generateHtaccess(); $this->context->smarty->assign(array( 'message' => $message, 'allp' => Product::getProducts(Configuration::get('PS_LANG_DEFAULT'),0,1000000)); return $this->display(__FILE__, 'settings.tpl'); Link to comment Share on other sites More sharing options...
JoelWebsites Posted January 13, 2015 Author Share Posted January 13, 2015 (edited) I have found this example online. global $cookie;$id_lang = $cookie->id_lang;$product_list = array();if (count($product_ids)){$sql = 'SELECT p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,(p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) AS orderpriceFROM `'._DB_PREFIX_.'category_product` cpLEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)($id_lang).')LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)($id_lang).')LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'AND tr.`id_state` = 0)LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)($id_lang).')LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`WHERE p.`active` = 1' : '').''.($id_supplier ? 'AND p.id_supplier = '.(int)($id_supplier) : '').'AND p.`id_product` IN(' . implode(',', $product_ids) . ')';$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);/* Modify SQL result */$product_list = Product::getProductsProperties($id_lang, $result);} So I have all products in $product_list variable. How do I display $product_list on the .tpl?Will it work if its displayed after assigning the smarty array by just using {$product_list}? or is there some other way to do it? Edited January 13, 2015 by JoelWebsites (see edit history) Link to comment Share on other sites More sharing options...
farruk0 Posted June 29, 2015 Share Posted June 29, 2015 Hi Joel, did you create the module? If yes, could you please share it? THANK YOU!!! 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