Fehler Widget Produktseite beseitigt

This commit is contained in:
Eduard Wisch 2026-02-02 09:10:37 +01:00
parent 489dd2e099
commit 04dbe4df24
2 changed files with 73 additions and 29 deletions

View file

@ -953,4 +953,58 @@ class ActionsImportZugferd
return 0;
}
/**
* Hook to add info box on products/services dashboard page
*
* @param array $parameters Parameters
* @param object $object Object
* @param string $action Action
* @param HookManager $hookmanager Hook manager
* @return int 0 = OK, >0 = number of errors
*/
public function dashboardProductsServices($parameters, &$object, &$action, $hookmanager)
{
global $langs, $user, $conf;
if (!$user->hasRight('produit', 'lire')) {
return 0;
}
$langs->load('importzugferd@importzugferd');
// Count products with ref starting with "New"
$sql = "SELECT COUNT(*) as total FROM " . MAIN_DB_PREFIX . "product";
$sql .= " WHERE entity IN (" . getEntity('product') . ")";
$sql .= " AND ref LIKE 'New%'";
$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
$count = (int) $obj->total;
if ($count > 0) {
$url = dol_buildpath('/importzugferd/new_products.php', 1);
$this->resprints = '
<div class="box-flex-item">
<div class="box-flex-item-with-margin">
<div class="info-box info-box-sm">
<span class="info-box-icon bg-infobox-importzugferd_newproducts">
<i class="fa fa-dol-importzugferd_newproducts"></i>
</span>
<div class="info-box-content">
<span class="info-box-text">' . $langs->trans("NewProductsToReview") . '</span>
<span class="info-box-number">
<a href="' . $url . '">' . $count . ' ' . $langs->trans("Products") . '</a>
</span>
</div>
</div>
</div>
</div>';
}
}
return 0;
}
}

View file

@ -76,7 +76,7 @@ class modImportZugferd extends DolibarrModules
$this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@importzugferd'
// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z'
$this->version = '2.3';
$this->version = '2.5';
// Url to the file with your last numberversion of this module
//$this->url_last_version = 'http://www.example.com/versionmodule.txt';
@ -122,7 +122,7 @@ class modImportZugferd extends DolibarrModules
'hooks' => array(
'data' => array(
'index',
'opensurveypollindex',
'productindex',
),
'entity' => '0',
),
@ -648,38 +648,28 @@ class modImportZugferd extends DolibarrModules
$sql = array();
// Document templates
$moduledir = dol_sanitizeFileName('importzugferd');
$myTmpObjects = array();
$myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);
// Run standard init first (creates box definitions)
$result = $this->_init($sql, $options);
foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
if ($myTmpObjectArray['includerefgeneration']) {
$src = DOL_DOCUMENT_ROOT.'/install/doctemplates/'.$moduledir.'/template_myobjects.odt';
$dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/'.$moduledir;
$dest = $dirodt.'/template_myobjects.odt';
// Now activate widget for product index page (area 4)
// Box definition is now created by _init(), so we can find it
$sql_box = "SELECT rowid FROM ".$this->db->prefix()."boxes_def WHERE file = 'box_new_products.php@importzugferd'";
$resql = $this->db->query($sql_box);
if ($resql && $this->db->num_rows($resql) > 0) {
$obj = $this->db->fetch_object($resql);
$box_id = $obj->rowid;
if (file_exists($src) && !file_exists($dest)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_mkdir($dirodt);
$result = dol_copy($src, $dest, '0', 0);
if ($result < 0) {
$langs->load("errors");
$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
return 0;
}
}
$sql = array_merge($sql, array(
"DELETE FROM ".$this->db->prefix()."document_model WHERE nom = 'standard_".strtolower($myTmpObjectKey)."' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity),
"INSERT INTO ".$this->db->prefix()."document_model (nom, type, entity) VALUES('standard_".strtolower($myTmpObjectKey)."', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")",
"DELETE FROM ".$this->db->prefix()."document_model WHERE nom = 'generic_".strtolower($myTmpObjectKey)."_odt' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity),
"INSERT INTO ".$this->db->prefix()."document_model (nom, type, entity) VALUES('generic_".strtolower($myTmpObjectKey)."_odt', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")"
));
// Check if already activated for area 4 (product index)
$sql_check = "SELECT rowid FROM ".$this->db->prefix()."boxes WHERE box_id = ".(int)$box_id." AND position = 4 AND entity = ".(int)$conf->entity;
$resql2 = $this->db->query($sql_check);
if ($resql2 && $this->db->num_rows($resql2) == 0) {
// Not yet activated, add it
$sql_insert = "INSERT INTO ".$this->db->prefix()."boxes (box_id, position, box_order, fk_user, entity) VALUES (".(int)$box_id.", 4, 'A01', 0, ".(int)$conf->entity.")";
$this->db->query($sql_insert);
}
}
return $this->_init($sql, $options);
return $result;
}
/**