I have problem with my first module.
I create a module modules/fashion/fashion.php
<?php
class Fashion extends Module
{
function __construct()
{
$this->name = 'fashion';
$this->tab = 'administration';
$this->version = 1.0;
$this->bootstrap = true;
parent::__construct(); // The parent construct is required for translations
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Block Fashion');
$this->description = $this->l('Add a fashion block');
}
public function install()
{
if (!parent::install() ||
!$this->registerHook('header')) {
return false;
}
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
$tab = new Tab();
$tab->active = 1;
$tab->class_name = 'AdminFashionController';
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = "Fashion";
}
$tab->id_parent = (int)Tab::getIdFromClassName('Fashion');
$tab->module = $this->name;
return $tab->add();
}
public function uninstall()
{
// Uninstall Tabs
$tab = new Tab((int)Tab::getIdFromClassName('Fashion'));
$tab->delete();
// Uninstall Module
if (!parent::uninstall())
return false;
}
/**
* Returns module content
*
* #param array $params Parameters
* #return string Content
*/
}
?>
What is more i create modules/fashion/controller/admin/FashionAdminController.php
<?php
class FashionAdminController extends ModuleAdminController
{
public function initContent(){
parent::initContent();
$this->setTemplate('fashion.tpl');
}
}
?>
And modules/fashion/views/templates/admin/fashion.tpl
<!-- Block mymodule -->
<div id="mymodule_block_left" class="block">
<h4>Welcome!</h4>
<div class="block_content">
<p>Hello,
{if isset($my_module_name) && $my_module_name}
{$my_module_name}
{else}
World
{/if}
!
</p>
<ul>
<li>Click me!</li>
</ul>
</div>
</div>
<!-- /Block mymodule -->
So, when i click in my Admin Panel the link Fashion the shows "The page is no found" Why? What i did wrong? Can someone help me?
At first, check if the menu(tab) has been created in the backend or not.
I also think that the admin controller name should start with ADMIN : AdminFashionController and use this name for tab class :
$tab->class_name = 'AdminFashion';
Sample from default module:
public function installTab()
{
$tab = new Tab();
$tab->active = 1;
$tab->class_name = "AdminLinkWidget";
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = "Link Widget";
}
$tab->id_parent = (int)Tab::getIdFromClassName('AdminParentThemes');
$tab->module = $this->name;
return $tab->add();
}
You have to add "active" and remove "position"(is automatic)
Related
Controller
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Signin extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('cias');
$this->load->model('home_model');
$this->load->model('signin_model');
}
public function index(){
$this->is_signed_in();
}
function is_signed_in()
{
$is_signed_in = $this->session->userdata('is_signed_in');
if(!isset($is_signed_in) || $is_signed_in != TRUE)
{
// header
$data['logo'] = $this->home_model->get_logo_by_id();
// footer
$data['contact']=$this->home_model->get_contact();
$this->load->view('front/signin');
}
else
{
redirect('front/dashboard');
}
}
public function signinme()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|max_length[128]|trim');
$this->form_validation->set_rules('password', 'Password', 'required|max_length[32]');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$email = strtolower($this->security->xss_clean($this->input->post('email')));
$password = $this->input->post('password');
$result = $this->signin_model->sign_in_me($email, $password);
if(!empty($result))
{
$session_array = array('user_id'=>$result->user_id,
'name'=>$result->name,
'email'=>$result->email,
'phone'=>$result->phone,
'is_signed_in' => TRUE );
$this->session->set_userdata('logged_in', $session_array);
redirect('./dashboard');
}
else
{
$this->session->set_flashdata('error', 'Email Address or password mismatch');
$this->index();
}
}
}
}
Model
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Signin_model extends CI_Model
{
// This function used to check the login credentials of the user
function sign_in_me($email, $password)
{
$this->db->select('*');
$this->db->from('user_login');
$this->db->where('email', $email);
$this->db->where('isdeleted', 0);
$query = $this->db->get();
$user = $query->row();
if(!empty($user)){
if(verifyHashedPassword($password, $user->password)){
return $user;
} else {
return array();
}
} else {
return array();
}
}
function get_user_info_id($user_id){
$this->db->select('*');
$this->db->from('user_login');
$this->db->where('user_id', $user_id);
$query = $this->db->get();
return $query->row();
}
}
Want to redirect
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/FrontController.php';
class Dashboard extends FrontController {
public function __construct(){
parent::__construct();
$this->load->helper('cias');
$this->load->model('home_model');
$this->load->model('signin_model');
$this->is_signed_in();
}
public function index(){
$this->load->view("front/dashboard", $data);
}
function signout() {
$this->session->sess_destroy ();
redirect ( 'signin' );
}
}
I was able to create a menu tab in the back office but when I click on it, I get
Page not found.
The controller is missing or invalid.
Here's the code for my controller -
<?php
class AdminModuleNameConvert extends ModuleAdminController {
public function __construct() {
$this->bootstrap = true;
parent::__construct();
}
}
Using the solution provided by ethercreation, I get the controller to load, but it shows me
Try width :
In your module : modulenameconverter
class modulenameconverter extends Module
{
public function __construct(Context $context = null)
{
$this->name = 'modulenameconverter';
$this->version = '1';
$this->bootstrap = true;
$this->author = 'Stackoverflow';
$this->displayName = $this->l('modulenameconverter');
$this->description = $this->l('Module name converter');
parent::__construct();
}
public function install()
{
$tab = new Tab();
$tab->class_name = 'Adminmodulenameconverter';
$tab->module = 'modulenameconverter';
$tab->name[1] = 'modulenameconverter';
$tab->id_parent = 2;
$tab->active = 1;
if (!$tab->save()) {
return false;
}
return parent::install();
}
public function uninstall()
{
$id_tab = (int)Tab::getIdFromClassName('Adminmodulenameconverter');
$tab = new Tab($id_tab);
if (Validate::isLoadedObject($tab)) {
if (!$tab->delete()) {
return false;
}
} else {
return false;
}
return parent::uninstall();
}
}
In module/controllers/admin/AdminModulenameconverterController.php
class AdminNameconverterController extends ModuleAdminController
{
public function __construct()
{
parent::__construct();
$this->bootstrap = true;
$this->id_lang = $this->context->language->id;
$this->default_form_language = $this->context->language->id;
}
public function initContent()
{
parent::initContent();
}
}
I was having the exact same issue and it appears that I was not configuring the tab parameters correctly... I was trying to pass an array for the "$this->module" parameter so Prestashop could not find the module because in the database, the module linked to the tab was equal to ""...
So my best advice in this case is to always check your database fields to see if they are correctly filled.
To conclude : It's always the silliest issues that makes the biggest headaches... -_-'
How to add custom input field in Product image form using hooks.I am trying to add a new check box in product image form but i do not know how to create it by using modules as well as i am not able to override core product page template.I am createing directory structure inside themes/classic/module/module_name/.....
If some can write the main module php file of Prestashop 1.7 I am very thankful to you.
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class youmodule extends Module
{
protected $config_form = false;
public function __construct()
{
$this->name = 'youmodule';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('youmodule');
$this->description = $this->l('youmodule');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}
public function install()
{
return parent::install() &&
$this->registerHook('header') &&
$this->registerHook('displayAdminProductsExtra');
}
public function uninstall()
{
return parent::uninstall();
}
public function hookDisplayAdminProductsExtra($params)
{
$id_product = Tools::getValue('id_product');
//YOURCODE
$this->smarty->assign(array(
'yourvariable' => $yourvariabl
));
return $this->display(__FILE__, '/views/templates/admin/product.tpl');
}
}
I am new to prestashop. I wanted learn how the code will flow .
ex. how product are inserting in database ?
how product data is fetching and displaying in store page ?
please help me .
you should open PrestaShop Product class.
you can get all product data using this:
$product = new Product($id_product);
if add a new product:
$product = new Product();
write all parameters like:
$product->name = 'test';
$product->reference = '35GH';
$product->save();
If u print out product array you will see all parameters. GOod luck, have fun. And even lot of information in stackoverflow how to php add product and etc.
If you want to work on products like you want to add products,delete products,want some customization then first you have to create a new module. For that you have to create a new folder in that location with you module name
C:\wamp\www\prestashop\modules\your_module_name
Then after you have to create a file named your_module_name.php in that folder
C:\wamp\www\prestashop\modules\your_module_name\your_module_name.php
After then you have to code in that file like:
your_module_name.php
class your_module_name extends Module
{
public function __construct()
{
$this->name = 'your_module_name';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'abc';
$this->need_instance = 0;
//$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Your Module Name');
$this->description = $this->l('This is the module for facilitate user to purchase particular product.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('your_module_name')) {
$this->warning = $this->l('No name provided');
}
}
public function install()
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if (!parent::install())
{
return false;
}
$defaultsettings = $this->getDefaultSettings();
$defaultsettings = serialize($defaultsettings);
Configuration::updateValue('your_module_name', $defaultsettings);
return true;
}
public function uninstall()
{
if (!parent::uninstall()) {
return false;
}
return true;
}
public function getContent()
{
$output = null;
$product = new Product($id_product);
$product->name = 'test';
$product->reference = '35GH';
$product->save();
}
Now in that getContent method you can perform operations on products.I hope it would help you.
Hi i try to create an admin module to prestashop 1.6 but i find some problems.
I would create ( after module installation ) a new tab in main menù and after click on it i would to show a template (.tpl) where the admin user can do some thing on Db.
I have create a folder and insert it in modules folder, in this folder there are this files:
Controller > admin > AdminGcbulkController.php
gcbulk.tpl
gcbulk.php
gcbulk.php:
<?php
if (!defined('_PS_VERSION_'))
exit;
require(dirname(__FILE__) . '/gcbulk_header.class.php');
class gcbulk extends Module {
private $page_name = '';
public function __construct() {
$this->name = 'gcbulk'; // il nome del modulo (lo stesso del file principale)
$this->tab = 'others'; // sezione in cui va inserito
$this->version = 0.1;
$this->author = 'Autore';
$this->need_instance = 0;
/*
* need_instance specifica se un istanza del modulo deve essere caricata
* quando viene visualizzata la lista dei moduli
(di norma può essere lasciato a 0)
*/
parent::__construct();
$this->displayName = $this->l('Bulk');
$this->description = $this->l('Modulo Bulk');
$this->context->controller->addCSS(($this->_path).'gcbulk.css', 'all');
//$this->context->controller->addJS(($this->_path).'js/gc_bulk_script.js');
}
public function install() {
// Install Tabs
$parent_tab = new Tab();
// Need a foreach for the language
$parent_tab->name[$this->context->language->id] = $this->l('Bulk tab');
$parent_tab->class_name = 'AdminGcbulk';
$parent_tab->id_parent = 0; // Home tab
$parent_tab->module = $this->name;
$parent_tab->add();
if (!parent::install()
|| !$this->registerHook('admingc')
);
}
public function uninstall() {
// Uninstall Tabs
$tab = new Tab((int)Tab::getIdFromClassName('AdminGcbulk'));
$tab->delete();
// Uninstall Module
if (!parent::uninstall())
return false;
return true;
}
public function hookadmingc(){
$this->smarty->assign(array(
'ciao' => 'hola'
));
return $this->display(__FILE__, 'gcbulk.tpl');
}
}
?>
Controller > admin > AdminGcbulkController.php
<?php
class AdminGcbulkController extends ModuleAdminController
{
}
gcbulk.tpl containe simple html.
The creation of tab work fine but i don't know how to show .tpl after clik on it. Actualy return a blank page on the right of admin contents ( on left there is the menù )
Thanks for any help !
the controller should implement renderList as following :
public function renderList() {
$return = $this->context->smarty->fetch(_PS_MODULE_DIR_ . '/gcbulk/gcbulk.tpl');
return $return;
}
I recommend you to move your tpl in this folder : /gcbulk/views/templates/admin/gcbulk.tpl