I have create a custom module to display some images and text.I want to have a header for this module because I don't want to have the title frmo website.I need a individual title so I think I need to have a different header for this module or how can I have a title just for this module? The code for meta title is:
meta charset="utf-8" />
<title>{$meta_title|escape:'html':'UTF-8'}</title>
{if isset($meta_description) AND $meta_description}
<meta name="description" content="{$meta_description|escape:'html':'UTF-8'}" />
{/if}
So I will need the title to be My title
Can someone help me?
Page that you have created with your module are presumably FrontControllers. Otherwise, existing pages already have their purpose and meta tags.
If you did use FrontController to create a Page, then you can input meta information for your page in SEO & URLs > SEO & URLs > Add. There you can input custom url-rewrite for your page and met info.
#gskema This is my php code for module :
if (!defined('_PS_VERSION_'))
exit;
class mymodule5 extends Module
{
/* #var boolean error */
protected $_errors = false;
public function __construct()
{
$this->name = 'mymodule5';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'author';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('mymodule5');
$this->description = $this->l('Pagina livrare');
$this->confirmUninstall = $this->l('Are you sure you want to delete this module?');
}
public function install()
{
if (!parent::install())
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall())
return false;
return true;
}
public function countAllProducts()
{
return Db::getInstance()->getValue('SELECT COUNT(*) from ps_product WHERE active = 1');
}
public function setMedia()
{
parent::setMedia();
$this->addCSS(__PS_BASE_URI__.'modules/'.$this->module->name.'/css/'.$this- >module->name.'.css');
}
}
Related
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... -_-'
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.
I am trying to add some functionality to my shop and have spent the past two days trying to come to grasp with how smarty actually works within prestashop or rather in general.
I have so far made a module that can install, on install it creates a tab on the left menu, I can click on the tab and it will load the controller but this is where i get stuck... I can't figure out how to display custom content within that state.
What i would like is very simple, just a paragraph of text and a button. When clicking the button i will do a few things and record a few things then show the results as a simple report.
So for starters... I'd like to create the page with the paragraph and button.
So i have created a folder in the module diretory called priceupdate
Inside of this there is:
/priceupdate.php
<?php
if (!defined('_PS_VERSION_'))
exit;
class PriceUpdate extends Module
{
public function __construct()
{
$this->name = 'priceupdate';
$this->tab = 'quick_bulk_update';
$this->version = '0.8';
$this->author = 'Me';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Pricing Update');
$this->description = $this->l('Adds functionality relating to maintaining product my prices.');
$this->confirmUninstall = $this->l('Are you sure you would like to uninstall?');
}
public function install()
{
if (!parent::install()
|| !$this->installModuleTab('AdminPricingUpdate', array(1=>'Pricing Update'), 0))
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall()
|| !$this->uninstallModuleTab('AdminPricingUpdate', array(1=>'Pricing Update'), 0))
return false;
return true;
}
private function installModuleTab($tabClass, $tabName, $idTabParent)
{
$tab = new Tab();
$tab->name = $tabName;
$tab->class_name = $tabClass;
$tab->module = $this->name;
$tab->id_parent = $idTabParent;
if(!$tab->save())
return false;
return true;
}
private function uninstallModuleTab($tabClass)
{
$idTab = Tab::getIdFromClassName($tabClass);
if($idTab != 0)
{
$tab = new Tab($idTab);
$tab->delete();
return true;
}
return false;
}
}
?>
And
/controllers/admin/AdminPricingUpdateController.php
<?php
class AdminPricingUpdateController extends AdminController
{
public function __construct()
{
$this->lang = (!isset($this->context->cookie) || !is_object($this->context->cookie)) ? intval(Configuration::get('PS_LANG_DEFAULT')) : intval($this->context->cookie->id_lang);
parent::__construct();
}
public function display(){
parent::display();
}
public function renderList() {
return $this->context->smarty->fetch(dirname(__FILE__).'/content.tpl');
}
}
?>
This works however where I am stuck relates to the content.tpl part. What goes inside of this the content.tpl file in order to get it to make a blank page of content within the content area of the admin section?
I've looked through the manual and spent countless hours on forums looking though questions, tried to figure it out by breaking down other modules but i've found it too complex to really understand what is what.
If anyone could help me to understand this or point me to a source of info on this specific subject then it would be greatly appreciated, thanks!
Check that answer
If you need "a blank page of content within the content area of the admin section" you need to make the content.tpl blank.
Note in my example that you do not have to set the name of the template if it's called "content.tpl".
I want to make Cart order list empty after a new product has been added to the cart.
In fact only on product every time can be in cart.
Tanx
2 ways to add your custom logic :
create your own module and hook it on "actionCartSave"
override "add" and "update" methods in "Cart" class (/override/classes/Cartp.php)
Edit : The 2nd way os wrong because infinite update loop.
Here is a module that do it :
class OneProductCart extends Module {
public function __construct() {
$this->name = 'oneproductcart';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'SJousse';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('One Product Cart');
$this->description = $this->l('Keep only last product in cart.');
}
public function install() {
return (parent::install() && $this->registerHook('actionCartSave'));
}
public function hookActionCartSave($params) {
$cart = $params['cart'];
$last = $cart->getLastProduct();
$prods = $cart->getProducts();
foreach ($prods as $prod)
if ($prod['id_product'] != $last['id_product'])
$cart->deleteProduct($prod['id_product']);
}
}
For people using Prestashop v 1.4.9 and have created a module:
call global $smarty, $cart;
then run the function $cart->delete();
function hookHome($params)
{
global $smarty, $cart;
/** some code here **/
$cart->delete();
}
I am new to Prestashop and programming and I am trying to add some content to Prestashop 1.4.5.
I made a new simple module that hooks to the hookHeader. I got it working and it shows Hello World in the top of the shop. But when i open the site and open the source code I see it is added before the the doctype:
Hello World
My module php looks like this - I am not using a template:
if ( !defined( '_CAN_LOAD_FILES_' ) )
exit;
class primanetskintop extends Module {
function __construct()
{
$this->name = "skintop";
$this->tab = 'front_office_features';
$this->version = '0.1.0';
parent::__construct();
$this->displayName = $this->l('Insert skin top');
$this->description = $this->l('Skin - ikke slettes');
}
function install()
{
if (!parent::install() OR !$this->registerHook('header'))
return false;
return true;
}
function uninstal()
{
if (!parent::uninstall())
return false;
return true;
}
public function hookHeader($params)
{
echo "Hello World!";
}
Why does the hello world not show where the hookHeader is located? What am i doing wrong?
Thank you :D
It's because you can't use echo to add content to the header. Try:
public function hookHeader($params)
{
return "Hello World!";
}
You may want to analyze FrontControler.php from the classes dir to understand how this works.