I want to create a module that shows the product price in the product page tab. With my limited coding and prestashop structure knowledge, I created the module below. Currently, this module works fine and the simple txt html code in "mymodule.tpl" appears in my product page tabs.
The next two steps are
1-Calling product price from database in mymodule.php
2-Printing this variable through the mymodule.tpl. ( Call productprice variable from mymodule.php and print it).
The problem is that I don't know how to do both. I tried hard but couldn't find a solution. Can someone please help me?
Thanks in advance!
----------------------------------------------------------------------------------------------------
<?php
if (!defined('_PS_VERSION_'))
{
exit;
}
class MyModule extends Module
{
public function __construct()
{
$this->name = 'mymodule';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Firstname Lastname';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('My Module');
$this->description = $this->l('Description of my module.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('MYMODULE_NAME'))
$this->warning = $this->l('No name provided');
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
return parent::install() &&
$this->registerHook('displayAdminProductsExtra')&&
$this->registerHook('displayProductExtraContent')&&
$this->registerHook('ActionProductUpdate') &&
Configuration::updateValue('MYMODULE_NAME', 'my friend');
}
public function uninstall()
{
if (!parent::uninstall() ||
!Configuration::deleteByName('MYMODULE_NAME')
)
return false;
return true;
}
public function hookDisplayProductExtraContent($params)
{
$content = $this->display(__FILE__, 'mymodule.tpl');
$array[] = (new PrestaShop\PrestaShop\Core\Product\ProductExtraContent())
->setTitle('My New Tab Title')
->setContent($content);
return $array;
}
}
--------------------------------------------------------------------------------------------------------------------------------