You are here:  » SKU 13 digits


SKU 13 digits

Submitted by henk on Mon, 2012-08-13 08:51 in

Hi David,

One merchant leave the zero empty on EAN, the zero is always in front of the EAN number.

Is it possible when import to check on 13 digits if not put a 0 in front of it?

Thank You,
Henk

Submitted by support on Mon, 2012-08-13 09:56

Hello Henk,

Sure - I see from previous mods that your custom field is called "sku" so in your includes/admin.php look for the following comment which is around the area within the import record handler function just before the product record is inserted into the database:

    /* check product record for minimum required fields */

...and then add the following code - it doesn't matter exactly where as each line around this point in the code is just tidying data in various ways before the insert:

if (strlen($importRecord["sku"])==12) $importRecord["sku"] = "0".$importRecord["sku"];

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Mon, 2012-08-13 10:19

Super, Thx...:)

Henk

Submitted by IG on Fri, 2019-03-01 10:15

Dear David

How would you modify the above code to make sure that all the ean (or gtin) codes have 14 digits once imported.

If it has 14 digits > no action
If it has 13 digits > add a zero before the number
If it has 12 digits > add two zeros before the number

Kind regards,
IG

Submitted by support on Fri, 2019-03-01 10:37

Hello IG,

At the above point in includes/admin.php you could use:

  $importRecord["ean"] = str_pad($importRecord["ean"],14,"0",STR_PAD_LEFT);

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Fri, 2019-03-01 11:21

Great! Thank you.