Jump to content

Get product data and shop funcionallity from module


xkushme

Recommended Posts

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

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 by xkushme (see edit history)
Link to comment
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...