[+] Class: Product::getIdByEan13

Sometimes, it's can be good to get the Product ID by EAN13.
This commit is contained in:
PrestaEdit
2013-01-02 17:21:04 +01:00
parent d464c9cda5
commit 2a2190e4c9
+22
View File
@@ -5147,5 +5147,27 @@ class ProductCore extends ObjectModel
WHERE pa.`id_product` = '.(int)$this->id
);
}
/**
* For a given ean13 reference, returns the corresponding id
*
* @param string $ean13
* @return int id
*/
public static function getIdByEan13($ean13)
{
if (empty($ean13))
return 0;
if(!Validate::isEan13($ean13))
return 0;
$query = new DbQuery();
$query->select('p.id_product');
$query->from('product', 'p');
$query->where('p.ean13 = \''.pSQL($ean13).'\'');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
}