You are here:  » Validate check EAN number


Validate check EAN number

Submitted by MrHolland on Mon, 2017-02-20 12:21 in

Hi there,

I'm importorting affialiate feeds and use the uidmap to map them on EAN. Now i just use the filter to check if the ean values are not empty but there are still unvalid EAN's.

There is no regexpression to validate an EAN number (ean numbers are actually 12 digits with 1 validation number at the end). It would be great of you can make a custom filter based on a php function but for now I would be very happy if I can add a check in the import script and when not valid drop the record.

Here is the function with a true or false output

{code saved}

If you could help me out I would appriciate that very much !

Submitted by support on Mon, 2017-02-20 13:03

Hello MrHolland;

Sure - add the following new code together with your validate_EAN13Barcode() function to includes/filter.php to add a new Check EAN filter, which will return an empty field if the value is invalid;

  /*************************************************/
  /* checkEAN */
  /*************************************************/
  $filter_names["checkEAN"] = "Check EAN";
  function filter_checkEANConfigure($filter_data)
  {
    print "<p>There are no additional configuration parameters for this filter.</p>";
  }
  function filter_checkEANValidate($filter_data)
  {
  }
  function filter_checkEANExec($filter_data,$text)
  {
    if (!validate_EAN13Barcode($text)) return "";
    return $text;
  }

(add as a Global Filter to your EAN field)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by MrHolland on Mon, 2017-02-20 13:27

I'm sorry for being such a noob (great way to add filters by the way :)

But how do i prevent the records from import ? I've made the filter and it just imports everything.

Add as global filter ? Do i need to add something like

    global $filter_dropRecordFlag;

Submitted by support on Mon, 2017-02-20 13:45

No worries!

Sure - to have the filter drop the record if EAN is invalid, use:

  /*************************************************/
  /* checkEAN */
  /*************************************************/
  $filter_names["checkEAN"] = "Check EAN";
  function filter_checkEANConfigure($filter_data)
  {
    print "<p>There are no additional configuration parameters for this filter.</p>";
  }
  function filter_checkEANValidate($filter_data)
  {
  }
  function filter_checkEANExec($filter_data,$text)
  {
    global $filter_dropRecordFlag;
    $filter_dropRecordFlag = !validate_EAN13Barcode($text);
    return $text;
  }

(setting $filter_dropRecordFlag to TRUE causes the entire record to be dropped, so the return value of your validate_EAN13Barcode() function can simply be assigned directly to the flag, with no alternation of $text required at all...)

Cheers,
David.
--
PriceTapestry.com