xkushme Posted November 11, 2013 Share Posted November 11, 2013 I´m starting with prestashop 1.5 and i´m creating a module where will appears: Two Featured Products and Four products on offer. I have already create the module (.php .tpl) basic files and i can get the products id, but i don´t know how to get the data of that products (title, image, description and price). This is my code: module.php public function obtenerDestacados(){$sql = 'SELECT id_product FROM '._DB_PREFIX_.'product';$results = Db::getInstance()->ExecuteS($sql);return $results;} module.tpl {foreach iniciallou::obtenerDestacados() as $prod}{$prod['id_product']}<br />{/foreach} How i can do something like the homeFeatured module from 0? How i can add a button to add that product to the cart? Is there some tutorial wich explain something like this? Thank you, and excuse my english. Link to comment Share on other sites More sharing options...
vekia Posted November 11, 2013 Share Posted November 11, 2013 to use iniciallou::obtenerDestacados() you need to create a static function (public static function obtenerDestacados() ) Link to comment Share on other sites More sharing options...
xkushme Posted November 12, 2013 Author Share Posted November 12, 2013 Thank you for your answer vekia, Could you tell me how to get data about a product (title, image url, description and price) from that function? I need to put an "add to cart" button after product data too. Thanks! Link to comment Share on other sites More sharing options...
vekia Posted November 12, 2013 Share Posted November 12, 2013 dont forget to pass $iniciallou variable to template smarty array {foreach from=$iniciallou::obtenerDestacados() item=product} {$product.id_product} {/foreach} Link to comment Share on other sites More sharing options...
xkushme Posted November 12, 2013 Author Share Posted November 12, 2013 (edited) Sorry, but i´m new in this, and i have a lot of questions ok, have a look: This is my .php file for the module: <?php if (!defined('_PS_VERSION_')) exit; class iniciallou extends Module { public function __construct(){ $this->name = 'iniciallou'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'AAS'; parent::__construct(); $this->displayName = $this->l('Modulo Inicial Movilöu'); $this->description = $this->l('Módulo que muestra los productos destacados, las ofertas y las novedades de la tienda.'); $this->confirmUninstall = $this->l('¿Seguro que quieres desinstalar este modulo?'); $this->_checkContent(); $this->context->smarty->assign('iniciallou', $this->name); } public static function obtenerDestacados(){ $sql = 'SELECT id_product FROM '._DB_PREFIX_.'product'; $results = Db::getInstance()->ExecuteS($sql); return $results; } private function _checkContent(){ if (!Configuration::get('MOD_SKELETON_NAME') && !Configuration::get('MOD_SKELETON_COLOR')) $this->warning = $this->l('Necesitas configurar el modulo.'); } public function install(){ if (!parent::install() || !$this->registerHook('displayHeader') || !$this->registerHook('displayHome') || !$this->_createContent()) return false; return true; } public function uninstall() { if (!parent::uninstall() || !$this->_deleteContent()) return false; return true; } private function _createContent() { if (!Configuration::updateValue('MOD_SKELETON_NAME', '') || !Configuration::updateValue('MOD_SKELETON_COLOR', '')) return false; return true; } private function _deleteContent() { if (!Configuration::deleteByName('iniciallou') return false; return true; } public function hookDisplayHeader(){ $this->context->controller->addCSS($this->_path.'css/style.css', 'all'); $this->context->controller->addJS($this->_path.'js/functions.js', 'all'); } public function hookDisplayHome(){ $this->context->smarty->assign(array('placement' => 'center',)); return $this->display(__FILE__, 'center.tpl'); } } ?> And this is my .tpl: <div id="cont_prod_home"> <div id="cont_prod_dest" class="bloques_productos" > <h4>{l s="PRODUCTOS DESTACADOS" mod="iniciallou"}</h4> <div class="cont_linea_sep"></div> {foreach from=iniciallou::obtenerDestacados() item=product} {$product.id_product} {/foreach} </div> <div id="cont_prod_ofer" class="bloques_productos"> <h4>{l s="OFERTAS" mod="iniciallou"}</h4> <div class="cont_linea_sep"></div> </div> <div id="cont_colec_dest" class="bloques_productos"> <h4>{l s="COLECCIÓN DESTACADA" mod="iniciallou"}</h4> <div class="cont_linea_sep"></div> </div> </div> When i put the code: {foreach from=$iniciallou::obtenerDestacados() item=product} {$product.id_product}{/foreach} The web don´t show anything in my home section, and i must unnistal the module, change names, and reinstall for fix that issue. Thanks! Edited November 12, 2013 by xkushme (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted November 12, 2013 Share Posted November 12, 2013 can you attach your module as a file not as a text? i copied code and it doesn't work at all. Link to comment Share on other sites More sharing options...
vekia Posted November 12, 2013 Share Posted November 12, 2013 problems are because while you pasting module code is expanded to several lines, code must be writed line by line Link to comment Share on other sites More sharing options...
xkushme Posted November 18, 2013 Author Share Posted November 18, 2013 Hello, Even writing the code line by line, the screen doesn´t show anything!! escamovilou.zip Link to comment Share on other sites More sharing options...
vekia Posted November 18, 2013 Share Posted November 18, 2013 code for template file: <div id="cont_prod_home"> {foreach from=escamovilou::obtenerDestacados() item=producto} {$producto.id_product} {/foreach} </div> Link to comment Share on other sites More sharing options...
xkushme Posted November 19, 2013 Author Share Posted November 19, 2013 it works! Now, i´m trying to show some subquery results, if alias is "p" how i can reference that fields in the tpl file? I try this: "$producto.p.id_product", but it doesn´t work. Thanks! Link to comment Share on other sites More sharing options...
vekia Posted November 19, 2013 Share Posted November 19, 2013 can you show $producto variable contents? <pre> {$producto|print_r} </pre> Link to comment Share on other sites More sharing options...
xkushme Posted November 19, 2013 Author Share Posted November 19, 2013 when i put that it shows 1 Link to comment Share on other sites More sharing options...
vekia Posted November 19, 2013 Share Posted November 19, 2013 so verify your function obtenerDestacados(), especially query Link to comment Share on other sites More sharing options...
xkushme Posted November 19, 2013 Author Share Posted November 19, 2013 ok, i use alias for the fields and it works! Thanks a lot vekia! 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