Skip to content

Commit

Permalink
Merge pull request #20453 from Webelys-PS/combination-getbyean
Browse files Browse the repository at this point in the history
Search combination by ean
  • Loading branch information
PierreRambaud committed Aug 18, 2020
2 parents bab4499 + 115f9a8 commit 7b820eb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions classes/Combination.php
Expand Up @@ -406,6 +406,31 @@ public static function isCurrentlyUsed($table = null, $hasActiveColumn = false)
return parent::isCurrentlyUsed('product_attribute');
}

/**
* For a given ean13 reference, returns the corresponding id.
*
* @param string $ean13
*
* @return int|string Product attribute identifier
*/
public static function getIdByEan13($ean13)
{
if (empty($ean13)) {
return 0;
}

if (!Validate::isEan13($ean13)) {
return 0;
}

$query = new DbQuery();
$query->select('pa.id_product_attribute');
$query->from('product_attribute', 'pa');
$query->where('pa.ean13 = \'' . pSQL($ean13) . '\'');

return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}

/**
* For a given product_attribute reference, returns the corresponding id.
*
Expand Down

0 comments on commit 7b820eb

Please sign in to comment.