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; 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' $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' // 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 // Url to the file with your last numberversion of this module
//$this->url_last_version = 'http://www.example.com/versionmodule.txt'; //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
@ -122,7 +122,7 @@ class modImportZugferd extends DolibarrModules
'hooks' => array( 'hooks' => array(
'data' => array( 'data' => array(
'index', 'index',
'opensurveypollindex', 'productindex',
), ),
'entity' => '0', 'entity' => '0',
), ),
@ -648,38 +648,28 @@ class modImportZugferd extends DolibarrModules
$sql = array(); $sql = array();
// Document templates // Run standard init first (creates box definitions)
$moduledir = dol_sanitizeFileName('importzugferd'); $result = $this->_init($sql, $options);
$myTmpObjects = array();
$myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);
foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { // Now activate widget for product index page (area 4)
if ($myTmpObjectArray['includerefgeneration']) { // Box definition is now created by _init(), so we can find it
$src = DOL_DOCUMENT_ROOT.'/install/doctemplates/'.$moduledir.'/template_myobjects.odt'; $sql_box = "SELECT rowid FROM ".$this->db->prefix()."boxes_def WHERE file = 'box_new_products.php@importzugferd'";
$dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/'.$moduledir; $resql = $this->db->query($sql_box);
$dest = $dirodt.'/template_myobjects.odt'; 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)) { // Check if already activated for area 4 (product index)
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $sql_check = "SELECT rowid FROM ".$this->db->prefix()."boxes WHERE box_id = ".(int)$box_id." AND position = 4 AND entity = ".(int)$conf->entity;
dol_mkdir($dirodt); $resql2 = $this->db->query($sql_check);
$result = dol_copy($src, $dest, '0', 0); if ($resql2 && $this->db->num_rows($resql2) == 0) {
if ($result < 0) { // Not yet activated, add it
$langs->load("errors"); $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->error = $langs->trans('ErrorFailToCopyFile', $src, $dest); $this->db->query($sql_insert);
return 0;
} }
} }
$sql = array_merge($sql, array( return $result;
"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).")"
));
}
}
return $this->_init($sql, $options);
} }
/** /**