Override helper list footer in prestashop - prestashop

I would like to change admin products actions bulks, so i'm creating a module to do the trick,
In my module, i have not any controller, i'm overriding the adminProductsController, and i would like to override ADMIN/themes/default/template/helpers/list/footer_list.tpl, i tried to place it under /override/controllers/admin/templates/helpers/list, but i'm getting the default template.
In Helper.php
public function createTemplate($tpl_name)
{
var_dump($this->override_folder);
var_dump($this->module);
exit;
if ($this->override_folder)
{
if ($this->context->controller instanceof ModuleAdminController)
$override_tpl_path = $this->context->controller->getTemplatePath().$this->override_folder.$this->base_folder.$tpl_name;
elseif ($this->module)
$override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name;
else
{
if (file_exists($this->context->smarty->getTemplateDir(1).$this->override_folder.$this->base_folder.$tpl_name))
$override_tpl_path = $this->context->smarty->getTemplateDir(1).$this->override_folder.$this->base_folder.$tpl_name;
elseif (file_exists($this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name))
$override_tpl_path = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name;
}
}
elseif ($this->module)
$override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->base_folder.$tpl_name;
I'm getting NULL for $this->override_folder, i tried
$helper->override_folder = $this->tpl_folder;
In AdminController.php, renderList function.
Any one could help?
Thanks.

I solved the problem by adding the file in override/controllers/admin/templates/products/helpers/list

Related

Questions regarding update of table on Prestashop

I'm trying to update ps_stock_available when I modify the product on Prestashop. But it's unsuccessfull. Could you help me please ?
public function hookActionUpdateQuantity(array $params)
{
$id_product = $params['id_product'];
$product = new Product((int)$id_product);
$id_category = $product->id_category_default;
$db = \Db::getInstance();
$request_loc='SELECT location FROM `'._DB_PREFIX_.'category_location` WHERE `id_category` = '.(int)$id_category;
$location = $db->getValue($request_loc);
$request_id_stock='SELECT id_stock_available FROM `'._DB_PREFIX_.'stock_available` WHERE `id_product` = '.(int)$id_product;
$id_stock_available = $db->getValue($request_id_stock);
$result = $db->update('stock_available', array('location' => $location), '`id_stock_available` = '.(int)$id_stock_available);
}
I have written this code but it doesn't seem to work.
in order to accomplish this task I would rely to the native StockAvailable class metehods getStockAvailableIdByProductId() and setLocation() (check the classes/stock/StockAvailable.php file).
Anyway your code seems to be correct, so I would definitely check for undefined variables and/or something not working in the $db->update statement.
In case, you can change it to :
$db->execute('UPDATE '._DB_PREFIX_.'stock_available SET `location` = "'.pSQL($location).'" WHERE id_stock_available = '.(int)$id_stock_available;

Prestashop 1.7.7.5: FrameworkBundleAdminController: $this->module->getPathUri() returns an error

In my admin module's controller's listMappingsAction action, I want to show a Vue.JS template, passing two variables that need to call $this->module->getPathUri() to be assigned a value:
<?php
namespace XYZ\Controller;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Security\Annotation\AdminSecurity;
class AutomatizedMappingController extends FrameworkBundleAdminController
{
/**
* #AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message="Access denied.")
*/
function listMappingsAction() {
return $this->render('#Modules/XYZ/views/templates/admin/app.html.twig', [
'XYZ' => [
'pathApp' => $this->module->getPathUri() . 'views/js/app.js',
'chunkVendor' => $this->module->getPathUri() . 'views/js/chunk-vendors.js',
]
]);
}
}
The use of $this->module->getPathUri() results in this error being displayed:
Attempted to call an undefined method named "getPathUri" of class "XYZ\Controller\AutomatizedMappingController". [Symfony\Component\Debug\Exception\UndefinedMethodException 0]
What could I call to make it work? The docs don't mention this use case... https://devdocs.prestashop.com/1.7/modules/concepts/templating/vuejs/faq/#how-to-send-data-from-symfony-controller-to-vuejs
First of all you need to know there is a difference between a module and a admin-controller. You cannot call $this->module->getPathUri() because your not using a extends ModuleAdminController, extends ModuleFrontController, extends Module ...
So you can only call $this->module if your actually using files inside a module.
Since i don't know which path you are trying to go to ill pass you a few variables which you might be able to use.
$this->module->name = crezzurmodulename
$this->module->getLocalPath() = C:\yourstore/modules/crezzurmodulename/
$this->module->getPathUri() = /yourstore/modules/crezzurmodulename/
_MODULE_DIR_ = /yourstore/modules/
_PS_MODULE_DIR_ = C:\yourstore/modules/
__DIR__ = C:\yourstore\modules\crezzurmodulename\controllers\front
_PS_CAT_IMG_DIR_ = C:\yourstore/img/c/
_PS_PROD_IMG_DIR_ = C:\yourstore/img/p/
_PS_TMP_IMG_DIR_ = C:\yourstore/img/tmp/
_PS_ROOT_DIR_ = C:\yourstore
_PS_CACHE_DIR_ = C:\yourstore/var/cache/dev\
_PS_BASE_URL_ = http://127.0.0.1
__PS_BASE_URI__ = /yourstore/
_PS_TRANSLATIONS_DIR_ = C:\yourstore/translations/
_PS_BASE_URL_SSL_ = http://127.0.0.1 or https://127.0.0.1
_PS_DOWNLOAD_DIR_ = C:\yourstore/download/
_PS_COL_IMG_DIR_ = C:\yourstore/img/co/
_PS_SHIP_IMG_DIR_ = C:\yourstore/img/s/
_PS_UPLOAD_DIR_ = C:\yourstore/upload/

why it is showing project name as "Default" in sitefinity dashboard portal once I run it

I am new to Sitefinity. But I followed steps from tutorial and created the one project named as "SFcmsDemo" and when I run this project and Sitefinity dashboard appears on localhost it is showing name as "Default" instead of "SFcmsDemo", The tutorial I read is showing the correct name in that but when I tried it is showing as "Default". Can anyone please help me find out the root cause and solution for this. I am attaching some screenshot which will help to understand more. Thanks.
Default can be easily changed if you click on it and then Manage Site.
UPDATE
From the decompiled Telerik.Sitefinity.dll (v.12.2):
internal static Site GetOrCreateDefaultSite()
{
Site site;
string str = "CreateDefaultSite";
MultisiteManager manager = MultisiteManager.GetManager(null, str);
using (ElevatedModeRegion elevatedModeRegion = new ElevatedModeRegion(manager))
{
ProjectConfig projectConfig = Config.Get<ProjectConfig>();
Guid siteMapRootNodeId = projectConfig.DefaultSite.SiteMapRootNodeId;
Site site = (
from s in manager.GetSites()
where s.SiteMapRootNodeId == siteMapRootNodeId
select s).FirstOrDefault<Site>();
if (site == null)
{
site = (projectConfig.DefaultSite.Id == Guid.Empty ? manager.CreateSite() : manager.CreateSite(projectConfig.DefaultSite.Id));
site.IsDefault = true;
site.IsOffline = false;
site.site = projectConfig.DefaultSite.site;
site.SiteMapRootNodeId = siteMapRootNodeId;
site.Name = (projectConfig.ProjectName != "/" ? projectConfig.ProjectName : "Default");
....
Note in the last line how it looks in the projectConfig.ProjectName value and if it is equal to "/" then it sets it to "Default"
Now, if we look at the ProjectConfig there is this:
[Browsable(false)]
[ConfigurationProperty("projectName", DefaultValue="/")]
[ObjectInfo(typeof(ConfigDescriptions), Title="ProjectNameTitle", Description="ProjectNameDescription")]
public string ProjectName
{
get
{
return (string)this["projectName"];
}
internal set
{
this["projectName"] = value;
}
}
So, default value is indeed "/", so that's why when the site is created it has a name of Default.

Drupal 8: When I update the node field to a specific value, how to call my module (managefinishdate.module) to update another field?

I am having a node type with machine name to_do_item, and I want to create a module called managefinishdate to update the node: when a user edit the node's field (field_status) to "completed" and click "save", then the module will auto update the field_date_finished to current date.
I have tried to create the module and already success to install in "Extend":
function managefinishdate_todolist_update(\Drupal\Core\Entity\EntityInterface $entity) {
...
}
however, I am not sure is this module being called, because whatever I echo inside, seems nothing appeared.
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
/** * Implements hook_ENTITY_TYPE_update().
* If a user update status to Completed,
* update the finished date as save date
*/
function managefinishdate_todolist_update(\Drupal\Core\Entity\EntityInterface $entity) {
$node = \Drupal::routeMatch()->getParameter('node');
print_r($node);
//$entity_type = 'node';
//$bundles = ['to_do_item'];
//$fld_finishdate = 'field_date_finished';
//if ($entity->getEntityTypeId() != $entity_type || !in_array($entity->bundle(), $bundles)) {
//return;
//}
//$current_date=date("Y-m-d");
//$entity->{$fld_finishdate}->setValue($current_date);
}
Following Drupal convention, your module named 'manage_finish_date' should contain a 'manage_finish_date.module file that sits in the root directory that should look like this:
<?php
use Drupal\node\Entity\Node;
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function manage_finish_date_node_insert(Node $node) {
ManageFinishDate::update_time();
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function manage_finish_date_node_update(Node $node) {
ManageFinishDate::update_time();
}
You should also have another file called 'src/ManageFinishDate.php' that should look like this:
<?php
namespace Drupal\manage_finish_date;
use Drupal;
use Drupal\node\Entity\Node;
class ManageFinishDate {
public static function update_time($node, $action = 'create') {
// Entity bundles to act on
$bundles = array('to_do_item');
if (in_array($node->bundle(), $bundles)) {
// Load the node and update
$status = $node->field_status->value;
$node_to_update = Node::load($node);
if ($status == 'completed') {
$request_time = Drupal::time();
$node_to_update->set('field_date_finished', $request_time);
$node_to_update->save();
}
}
}
}
The code is untested, but should work. Make sure that the module name, and namespace match as well as the class filename and class name match for it to work. Also, clear you cache once uploaded.
This will handle newly created and updated nodes alike.
Please look after this sample code which may help you:
function YOUR_MODULE_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
switch ($entity->bundle()) {
//Replace CONTENT_TYPE with your actual content type
case 'CONTENT_TYPE':
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
// Set the current date
}
break;
}
}

[Zend_Form][1.11.1] Error Message Fatal error: Class 'Admin_Form_Login' not found in ...\modules\default\controllers\IndexController.php

I don't speak english fluently (i'm french) so i will be
i followed the tutorial here and i got this structure
Application
--Modules
------admin
---------controller
---------views
------etat
---------controller
---------views
------default
---------controller
---------views
--configs
bootstrap.php
My problem is that, when i created my first form and tried to view it in my browser, i got the following error:
Fatal error: Class 'Admin_Form_Login' not found in C:\wamp\www\get\application\modules\default\controllers\IndexController.php on line 14.
Here is my code:
My controller : /modules/etat/controller/IndexController.php
class Etat_IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
$form = new Etat_Form_InfoAgent();
$this->view->form = $form;
}
}
My form : /modules/etat/forms/InfoAgent.php
class Etat_Form_InfoAgent extends Zend_Form
{
public function init()
{
/* Form Elements & Other Definitions Here ... */
$this->setName('infoagent');
$this->setMethod('post');
$login = new Zend_Form_Element_Text('matricule');
$login->setLabel('Matricule:');
$login->setRequired(true);
$login->addFilter('StripTags');
$login->addFilter('StringTrim');
$this->addElement($login);
$password = new Zend_Form_Element_Password('agence');
$password->setLabel('Code agence:');
$password->setRequired(true);
$password->addFilter('StripTags');
$password->addFilter('StringTrim');
$this->addElement($password);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Valider');
//$submit->style = array('float: right');
$this->addElement($submit);
}
}
My view : /modules/etat/view/script/index.phtml
<br /><br />
<div id="view-content">
<?php echo $this->form; ?>
</div>
Configuration file : configs/application.ini
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
;Modular structure
resources.modules[] =
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.prefixDefaultModule = "1"
;database ressources
resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password =
resources.db.params.dbname = bd_test
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
I have searched the web for solution but i didn't get it. I saw a post about the same problem on your website (stackoverflow) and i tried to aplly your instructions without solving my problem.
i precise that i haven't change the code on my bootstrap and my public/index.php file
I hope you could help me soon.
thx
Make sure you have created a Bootstrap.php in each module directory, which looks like:
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{}
In which Admin is the name of the module.
Also, make sure there is actually a file Login.php inside directory modules/admin/forms with a class Admin_Form_Login