Skip to content

Commit

Permalink
Merge pull request #28793 from frederic34/mod_barcode_story
Browse files Browse the repository at this point in the history
fix mod barcode product
  • Loading branch information
eldy authored Mar 12, 2024
2 parents 0e209ea + 37b22d5 commit 45f662b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 37 deletions.
27 changes: 12 additions & 15 deletions htdocs/core/modules/barcode/mod_barcode_product_standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ public function info($langs)
* Return an example of result returned by getNextValue
*
* @param Translate $langs Object langs
* @param Product $objproduct Object product
* @param ?Product $objproduct Object product
* @return string Return string example
*/
public function getExample($langs, $objproduct = 0)
public function getExample($langs, $objproduct = null)
{
$examplebarcode = $this->getNextValue($objproduct, '');
if (!$examplebarcode) {
Expand Down Expand Up @@ -155,18 +155,19 @@ public function literalBarcodeType($db, $type = 0)

return $out;
}

/**
* Return next value
*
* @param CommonObject $objproduct Object product
* @param string $type Type of barcode (EAN, ISBN, ...)
* @return string Value if OK, '' if module not configured, <0 if KO
* @param ?CommonObject $objproduct Object product (not used)
* @param string $type Type of barcode (EAN, ISBN, ...)
* @return string Value if OK, '' if module not configured, <0 if KO
*/
public function getNextValue($objproduct, $type = '')
public function getNextValue($objproduct = null, $type = '')
{
global $db, $conf;
global $db;

if (!$objproduct instanceof Product) {
if (is_object($objproduct) && !$objproduct instanceof Product) {
dol_syslog(get_class($this)."::getNextValue used on incompatible".get_class($objproduct), LOG_ERR);
return -1;
}
Expand All @@ -178,13 +179,8 @@ public function getNextValue($objproduct, $type = '')
$type = getDolGlobalString('PRODUIT_DEFAULT_BARCODE_TYPE');
} //get barcode type configuration for products if $type not set

// TODO

// Get Mask value
$mask = '';
if (getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK')) {
$mask = getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK');
}
$mask = getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK');

if (empty($mask)) {
$this->error = 'NotConfigured';
Expand Down Expand Up @@ -216,7 +212,8 @@ public function getNextValue($objproduct, $type = '')
}
}
//End barcode with key
return $numFinal;

return $numFinal;
}


Expand Down
30 changes: 12 additions & 18 deletions htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ public function __construct()
}


/** Return description of module
/**
* Return description of module
*
* @param Translate $langs Object langs
* @return string Description of module
* @param Translate $langs Object langs
* @return string Description of module
*/
public function info($langs)
{
Expand Down Expand Up @@ -120,10 +121,10 @@ public function info($langs)
* Return an example of result returned by getNextValue
*
* @param Translate $langs Object langs
* @param Societe $objthirdparty Object third-party
* @param ?Societe $objthirdparty Object third-party
* @return string Return string example
*/
public function getExample($langs, $objthirdparty = 0)
public function getExample($langs, $objthirdparty = null)
{
$examplebarcode = $this->getNextValue($objthirdparty, '');
if (!$examplebarcode) {
Expand Down Expand Up @@ -169,13 +170,13 @@ public function literalBarcodeType($db, $type = 0)
/**
* Return next value
*
* @param CommonObject $objthirdparty Object third-party
* @param ?CommonObject $objthirdparty Object third-party
* @param string $type Type of barcode (EAN, ISBN, ...)
* @return string Value if OK, '' if module not configured, <0 if KO
*/
public function getNextValue($objthirdparty, $type = '')
public function getNextValue($objthirdparty = null, $type = '')
{
global $db, $conf;
global $db;

require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean)
Expand All @@ -184,13 +185,8 @@ public function getNextValue($objthirdparty, $type = '')
$type = getDolGlobalString('GENBARCODE_BARCODETYPE_THIRDPARTY');
} //get barcode type configuration for companies if $type not set

// TODO

// Get Mask value
$mask = '';
if (getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK')) {
$mask = getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK');
}
$mask = getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK');

if (empty($mask)) {
$this->error = 'NotConfigured';
Expand Down Expand Up @@ -222,6 +218,7 @@ public function getNextValue($objthirdparty, $type = '')
}
}
//End barcode with key

return $numFinal;
}

Expand All @@ -242,10 +239,6 @@ public function getNextValue($objthirdparty, $type = '')
*/
public function verif($db, &$code, $thirdparty, $thirdparty_type, $type)
{
global $conf;

//var_dump($code.' '.$thirdparty->ref.' '.$thirdparty_type);exit;

require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';

$result = 0;
Expand Down Expand Up @@ -273,6 +266,7 @@ public function verif($db, &$code, $thirdparty, $thirdparty_type, $type)
}

dol_syslog(get_class($this)."::verif type=".$thirdparty_type." result=".$result);

return $result;
}

Expand Down
8 changes: 4 additions & 4 deletions htdocs/core/modules/barcode/modules_barcode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ abstract class ModeleNumRefBarCode extends CommonNumRefGenerator
/**
* Return next value available
*
* @param CommonObject $objcommon Object Product, Thirdparty
* @param string $type Type of barcode (EAN, ISBN, ...)
* @return string Value
* @param ?CommonObject $objcommon Object Product, Thirdparty
* @param string $type Type of barcode (EAN, ISBN, ...)
* @return string Value
*/
public function getNextValue($objcommon, $type = '')
public function getNextValue($objcommon = null, $type = '')
{
global $langs;
return $langs->trans("Function_getNextValue_InModuleNotWorking");
Expand Down

0 comments on commit 45f662b

Please sign in to comment.