En las prácticas me han asignado trabajar con los módulos de PrestaShop.
Os voy a dejar los ejemplos que me estoy haciendo para conseguir soltura, antes de crear el mio propio, que me han solicitado.
Por cierto, nuevas reglas: buscar en ingles la información.
Aquí tenéis el link. Ahi tambien podeis encontrar información sobre PrestaShop.
Lenguajes que usaremos hoy XML y PHP.
Lenguajes que usaremos hoy XML y PHP.
Programas usados: XAMPP, JetBrains y notepad++.
Básicamente hoy hemos creado un modulo que te cambia el nombre del modulo.
Yo trabajo sobre una tienda ya creada previamente, la aplicación es gratuita, podéis crearos la vuestra.
1.- Nos dirigimos a C:\xampp\htdocs\tienda\modules
2.-Ahí añadimos nuestro esqueleto del modulo, que os podéis descargar aquí.
3.- Creación del XML
4.- Nuestro módulo php
Importante que el documento php y la carpeta y la clase del modulo se llamen igual
<?php
if (!defined('_PS_VERSION_'))
exit;
class blogModulePrestashop extends Module
{
/**
* ModulePrestashop constructor.
*/
public function __construct()
{
$this->name = 'blogmoduleprestashop';
$this->tab = 'others';
$this->version = '1.0';
$this->author = 'Navis';
$this->need_instance = 0;
$this->ps_versions_compilancy = array('min' => '1.5', 'max' => '1.6');
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Módulo vacío por Navis para Prestashop');
$this->description = $this->l('');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('MYMODULE_NAME'))
$this->warning = $this->l('No name provided.');
/*$this->start();*/
}
/**
* ModulePrestashop installation.
*/
public function install()
{
if (!parent::install())
return false;
return true;
}
/**
* ModulePrestashop uninstallation.
*/
public function uninstall()
{
if (!parent::uninstall())
return false;
return true;
}
/**
* ModulePrestashop Content example web.
*/
public function getContent()
{
$output = null;
if (Tools::isSubmit('submit'.$this->name))
{
$my_module_name = strval(Tools::getValue('MYMODULE_NAME'));
if (!$my_module_name
|| empty($my_module_name)
|| !Validate::isGenericName($my_module_name))
$output .= $this->displayError($this->l('Invalid Configuration value'));
else
{
Configuration::updateValue('MYMODULE_NAME', $my_module_name);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
}
return $output.$this->displayForm();
}
/**
* ModulePrestashop displayForm example web.
*/
public function displayForm()
{
// Get default language
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
// Init Fields form array
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Settings'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Configuration value'),
'name' => 'MYMODULE_NAME',
'size' => 20,
'required' => true
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
)
);
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true; // false -> remove toolbar
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
// Load current value
$helper->fields_value['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME');
return $helper->generateForm($fields_form);
}
}
if (!defined('_PS_VERSION_'))
exit;
class blogModulePrestashop extends Module
{
/**
* ModulePrestashop constructor.
*/
public function __construct()
{
$this->name = 'blogmoduleprestashop';
$this->tab = 'others';
$this->version = '1.0';
$this->author = 'Navis';
$this->need_instance = 0;
$this->ps_versions_compilancy = array('min' => '1.5', 'max' => '1.6');
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Módulo vacío por Navis para Prestashop');
$this->description = $this->l('');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('MYMODULE_NAME'))
$this->warning = $this->l('No name provided.');
/*$this->start();*/
}
/**
* ModulePrestashop installation.
*/
public function install()
{
if (!parent::install())
return false;
return true;
}
/**
* ModulePrestashop uninstallation.
*/
public function uninstall()
{
if (!parent::uninstall())
return false;
return true;
}
/**
* ModulePrestashop Content example web.
*/
public function getContent()
{
$output = null;
if (Tools::isSubmit('submit'.$this->name))
{
$my_module_name = strval(Tools::getValue('MYMODULE_NAME'));
if (!$my_module_name
|| empty($my_module_name)
|| !Validate::isGenericName($my_module_name))
$output .= $this->displayError($this->l('Invalid Configuration value'));
else
{
Configuration::updateValue('MYMODULE_NAME', $my_module_name);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
}
return $output.$this->displayForm();
}
/**
* ModulePrestashop displayForm example web.
*/
public function displayForm()
{
// Get default language
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
// Init Fields form array
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Settings'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Configuration value'),
'name' => 'MYMODULE_NAME',
'size' => 20,
'required' => true
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
)
);
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true; // false -> remove toolbar
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
// Load current value
$helper->fields_value['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME');
return $helper->generateForm($fields_form);
}
}
5.- Accedemos a nuestro zona de administración de nuestro PrestaShop
6.- Instalamos
Es posible, que al ser desconocidos, nos aparezca un mensaje
7.- Ya esta preparado para su uso:
Continuará...
0 comentarios:
Publicar un comentario