You are here:  » Text before: 0

Support Forum



Text before: 0

Submitted by marco on Thu, 2008-10-23 12:03 in

Hello,

I would like to apply the 'text before' filter for an ean-number field.
The ean number in a particular datafeed consists of 12 numbers instead of the normal 13.
It misses the zero to start with:
For example, i would like to change: 885909259229 into 0885909259229

When i try to apply the text before filter, it does not accept the 0 (message: required field).

Is there a way to chance this?

Thanks,
Marco.

Submitted by support on Thu, 2008-10-23 12:05

Hello Marco,

Easily fixed, look for the following code on line 72 of includes/filter.php (within the filter_textBeforeValidate() function):

    widget_errorSet("text","required field");

...and simply comment out or delete this line. That should do the trick!

Cheers,
David.

Submitted by marco on Thu, 2008-10-23 12:16

Hello David, it works, thanks for your quick responce.

Submitted by marco on Thu, 2008-10-23 13:11

Hello Davaid,

I came across an other feed now, which has ean12 and ean13 numbers in it.
Text before won't work here because it does not need to be applied for the ean13 numbers.
So i was wondering if there is another way of dealing width this?

Is it possible that numbers are automatically converted to their 13 number equivalent?

The field i have used in the database now is varchar(32), so perhaps that does need be changed?

Thanks,
Marco.

Submitted by support on Thu, 2008-10-23 13:21

Hi Marco,

In that case, perhaps the easiest way is to hardcode the padding of the EAN field to 13 characters within the import record handler function; rather than use filters. This can be done quite easily using sprintf() with the %013d format, which means 13 characters, zero padded, decimal.

To do this, look for the following comment in includes/admin.php around about line 258:

/* create product record */

...and around about that point add this code:

$record[$admin_importFeed["field_name"]] = sprintf("%013d",$record[$admin_importFeed["field_name"]]);

(assuming that you have used "field_ean" as per other fields)

Hope this helps!

Cheers,
David.

Submitted by marco on Thu, 2008-10-23 14:08

Hello David,

I have changed the code below
/* create product record */

from:

 $sku = $record[$admin_importFeed["field_sku"]];

to:

 $sku = sprintf("%013d",$record[$admin_importFeed["field_sku"]]);

but it does not give the desired results.

All sku (i use this for the ean codes) fields are now converted to the same number (0002147483647) in the database?

Marco

Submitted by support on Thu, 2008-10-23 14:12

Hi Marco,

It may be a type conversion problem. Could you try:

 $sku = sprintf("%013d",intval($record[$admin_importFeed["field_sku"]]));

Cheers,
David.

Submitted by marco on Thu, 2008-10-23 14:19

Unfortunately that gives the same result

Submitted by support on Thu, 2008-10-23 14:23

Hi,

Ok, last attempt before changing tack... try using a string rather than decimal format, as in:

 $sku = sprintf("%013s",$record[$admin_importFeed["field_sku"]]);

(don't forget to remove the intval!!)

Cheers,
David.

Submitted by marco on Thu, 2008-10-23 14:35

Yes, that did it!
Thanks a lot,
Marco.

Submitted by marco on Mon, 2008-10-27 16:57

Hello,

I have noticed that if a sku is empty (or zero) it is also converted to '0000000000000' and is pricecompared with all other product without sku.

Is it posible to add a clausule to this code so that if an sku field is 'empty' or '0' it will not be imported in the database?

Regards,
Marco.

Submitted by support on Mon, 2008-10-27 16:59

Hi Marco,

Sure - after this line:

 $sku = sprintf("%013s",$record[$admin_importFeed["field_sku"]]);

...you could add:

  if (!intval($sku)) return;

Cheers,
David.

Submitted by marco on Tue, 2008-10-28 07:57

Hi David,

The products with empty sku (or zero) are now not imported at all. What i actually meant was that these products will be imported, but the sku field will remain completely empty.
Is this also possible?

Many thanks,
Marco

Submitted by support on Tue, 2008-10-28 09:11

Hi Marco,

Sorry about that! In that case, in place of:

if (!intval($sku)) return;

...just use:

if (!intval($sku)) $sku = "";

That should do the trick!

Cheers,
David.