Jump to content

how to edit pages in prestashop


JoelWebsites

Recommended Posts

Hi I wanna edit a page (my preferences) it shows index.php?controller=AdminEmployees&token=f698c48265a9b293866cd004a48e1a0f&id_employee=1&updateemployee url in the browser 

 

I want to add more content to this and get some information from the database tables to be displayed on the webpage

AdminEmployeesController.php

 

Please help me edit and add new content to this page.

Link to comment
Share on other sites

as log as you will not say something more what kind of options you want to add (type like: bool (yes/no) simple input text etc.) it will be a little hard to help.

 

 

you have to extend this array:

$this->fields_form 

add there your new db fields, like other fields. for example:

				array(
					'type' => 'text',
					'class' => 'fixed-width-xl',
					'label' => $this->l('My New Field'),
					'name' => 'newfield',
					'required' => true
				),
  • Like 1
Link to comment
Share on other sites

I have now created a module named mymodule' that is displaying some text that is placed in the mymodule.tpl file.

I want to display some values of an employee.from my ps_employee table in mySQL.It have colum names name date of joining,end date ,phone no and so on..I want to to display these details...I appreciate your help btw.

Link to comment
Share on other sites

in AdminEmployeesController.php you've got:


		$this->fields_form = array(
			'legend' => array(
				'title' => $this->l('Employees'),
				'icon' => 'icon-user'
			),
			'input' => array(
				array(
					'type' => 'text',
					'class' => 'fixed-width-xl',
					'label' => $this->l('First Name'),
					'name' => 'firstname',
					'required' => true
				),

in this array, you can define new fields, in that wat:

array(
					'type' => 'text',
					'class' => 'fixed-width-xl',
					'label' => $this->l('New variable'),
					'name' => 'newvariable',
					'required' => true
				),

so code with new fileld:


		$this->fields_form = array(
			'legend' => array(
				'title' => $this->l('Employees'),
				'icon' => 'icon-user'
			),
			'input' => array(
				array(
					'type' => 'text',
					'class' => 'fixed-width-xl',
					'label' => $this->l('First Name'),
					'name' => 'firstname',
					'required' => true
				),
array(
                    'type' => 'text',
                    'class' => 'fixed-width-xl',
                    'label' => $this->l('New variable'),
                    'name' => 'newvariable',
                    'required' => true
                ),
  • Like 1
Link to comment
Share on other sites

and how should one save the values from the database to these defined variables.

 

I am trying to create a module 

 

below is the code for mymodule.php

 

<?php
 
if (!defined('_PS_VERSION_'))
exit;
 
   
  class MyModule extends Module
{
  public function __construct()
  {
    $this->name = 'mymodule';
    $this->tab = '';
    $this->version = '1.2';
    $this->author = 'Joel Fernandes';
    $this->need_instance = 0;
$this->push_filename = _PS_CACHE_DIR_.'push/activity';
    $this->allow_push = true;
$this->push_time_limit = 180;
    
 
    parent::__construct();
 
    $this->displayName = $this->l('My module');
    $this->description = $this->l('This is a mymodule ');
 
    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
 
    if (!Configuration::get('MYMODULE_NAME'))      
      $this->warning = $this->l('No name provided');
  }
  
  
  
 
// this also works, and is more future-proof
public function install()
{
    if (!parent::install()
        || !$this->registerHook('dashboardZoneTwo')
        || !$this->registerHook('dashboardData'))
        return false;
    return true;
}
 
 
 
  
  
 public function uninstall()
{
  if (!parent::uninstall())
    Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'mymodule`');
  parent::uninstall();
}
 
 
 
 
 
 
public function hookDashboardZoneTwo($params)
{
 
 
echo $this->name = 'mymodule';
return $this->display(__FILE__,'mymodule.tpl');
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
  
}
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
?>
Link to comment
Share on other sites

im confused a little

you asked about controller modification, now you're asking about sql queries to save these datase from your module.

 

so, where you want to manage these datas? in controller, or in module?

if you modify controller, datas will be stored automatically in database.

Link to comment
Share on other sites

I appreciate your patience..and appreciate your attention..Let me explain...I was trying to create a module in the start...Bt I was finding it really difficult to create a module so I had taught to try modifying the controller..but then I had a tough time locating the controller as well...Now since I was successfully able to create a module ( the dashboard module is installed and the hook is registered and is working the hook name is hookDashboardZoneTwo as mentioned in the above mymodule code.)The tpl file is being displayed on the dashboard page.I need code to retrieve rows from the database and display it on the .tpl file(mymodule.tpl)...I have an ps_employee..where all the data I need is stored.I am finding it difficult to create the function to retrieve the data and I also need to know how to display these rows in the .tpl file.

Link to comment
Share on other sites

for eg in php we use

 

$strSQL = "SELECT * FROM ps_employee";

 
echo "<table border='1'> 
<tr> 
<th> Number
of stores  </th> 
<th> Shop name   </th>
<th> Plan   </th> 
<th> Language </th> 
<th> Lastname ID </th> 
<th> Firstname </th>
<th> phone1 </th>
<th> phone2 </th>
<th> email </th>
<th> start date </th>
<th> Plan end date </th>
<th> original cost </th>
<th> discounted cost </th>
<th>Reseller name</th>
<th> edit info </th>
 
 
</tr>";
 
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
 
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
 
  
  
  
  echo "<tr>"; 
echo "<td>" . $row['id_employee'] . "</td>"; 
echo "<td>" . $row['shopname'] . "</td>"; 
echo "<td>" . $row['id_profile'] . "</td>"; 
echo "<td>" . $row['id_lang'] . "</td>"; 
echo "<td>" . $row['lastname'] . "</td>"; 
echo "<td>" . $row['firstname'] . "</td>"; 
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['phone2'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['stats_date_to'] . "</td>";
echo "<td>" . $row['enddate'] . "</td>";
echo "<td>" . $row['originalcost'] . "</td>";
echo "<td>" . $row['discountedcost'] . "</td>";
echo "<td>" . $row['resellername'] . "</td>";
echo ("<td><a href=\"edit_form.php?id=$row[id_employee]\">Edit Enddate</a></td></tr>");
Link to comment
Share on other sites

in this case you can use default prestashop class named Db

with this class you can run queries to database in that way:
 

$query=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM ps_employee');

then assign this variable to template file,

$this->context->smarty->assign('query',$query);

and then you can use foreach loop on this variable

{foreach from=$query item=row}
do something with $row variable here
{/foreach}
Link to comment
Share on other sites


This is not the right forum for this topic, I'm moving it.

 

Remember: the PrestaShop forum is one of the biggest there is and a wise choice for a new thread means more replies, better replies, neater forums and a more efficient Community!  

 

Also, you might wanna be a little more specific in the description of what you're trying to customize. 

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...