You are here:  » Populate Fields during Import


Populate Fields during Import

Submitted by marco.saiu on Sun, 2017-12-31 15:17 in

Hello David,

have idea how to keep data from field if another field contain X?

For example:

feature(0-25)name: can contains some type of data but are variable

and

feature(0-25)value: contains speficiation.

The filter work in this mode:

if featureXname= "Color" populate color with featureXvalue

I create SQL script but is good load data during the xml import.

"UPDATE pt_products SET acolor=color WHERE color!=''"
"UPDATE pt_products SET acolor=CONCAT(acolor,',',features0value) WHERE color!='' AND features0name='Color'"
"UPDATE pt_products SET acolor=CONCAT(acolor,',',features1value) WHERE color!='' AND features1name='Color'"
{code saved}

Thanks,
Marco Saiu

Submitted by support on Tue, 2018-01-02 09:18

Hello Marco,

Using code similar to the modification to filter_recordPlaceholders described in this thread it would be no problem to create the $features array within the import record handler function; and then from it to set the value of any custom fields with names that exactly match feature name (to lower case). To give this a go, edit includes/admin.php and look for the following comment at line 448:

    /* check product record for minimum required fields */

...and REPLACE with:

    $features = array();
    $i = 0;
    $p = "";
    while(1)
    {
      if ($i) $p = "@".$i;
      if (!isset($filter_record["FEATURES/FEATURE".$p."-NAME"])) break;
      $name = $filter_record["FEATURES/FEATURE".$p."-NAME"];
      $value = $filter_record["FEATURES/FEATURE".$p."-VALUE"];
      $features[strtolower($name)] = $value;
      $i++;
    }
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($features[$field]))
      {
       $importRecord[$field] = $features[$field];
      }
    }
    /* check product record for minimum required fields */

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Tue, 2018-01-02 11:25

Hello David,

in Italian have some features name with special char.

I have create custom fields lower case and without special char.

How to match special char with normal char?

For examle:

è -> e / a -> à / o -> ò etc.. etc..

Submitted by marco.saiu on Tue, 2018-01-02 11:29

and fields not have black space in database!

Età
Marca o compatibilità
Interfaccia
Piattaforma
Personaggio
Tema
Schermo
Hard Disk
Memoria RAM
Frequenza processore
Taglia OLD
Certificazione
Colore del Metallo - Pietra

etc... etc... this is a part of -name value in feature fields.

Thanks,
Marco Saiu

Submitted by marco.saiu on Tue, 2018-01-02 11:48

And sometimes have merchant with features name duplicate for example Sizes and Colours in more then 1 field and i need concat values with ,

Sometimes have Size,Size,Size,Size,Size in feature fields with different values XS,S,M,L,XL,XXL and same for other features type...

Thanks David

Submitted by support on Tue, 2018-01-02 12:34

Hello Marco,

The following version of the above code will convert to ASCII so "è" will become "e" and replace spaces with underscore. It will also append subsequent values of the same name with comma separation.

    $features = array();
    $i = 0;
    $p = "";
    while(1)
    {
      if ($i) $p = "@".$i;
      if (!isset($filter_record["FEATURES/FEATURE".$p."-NAME"])) break;
      $name = strtolower($filter_record["FEATURES/FEATURE".$p."-NAME"]);
      $name = tapestry_normalise($name);
      $name = str_replace(" ","_",$name);
      $name = iconv("UTF-8","ASCII//TRANSLIT",$name);
      $value = $filter_record["FEATURES/FEATURE".$p."-VALUE"];
      if (!isset($features[$name]))
      {
        $features[$name] = $value;
      }
      else
      {
        $features[$name] .= ",".$value;
      }
      $i++;
    }
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($features[$field]))
      {
       $importRecord[$field] = $features[$field];
      }
    }
    /* check product record for minimum required fields */

The iconv() function requires that the locale be set so to do this add the following line to the end of your config.advanced.php:

  setlocale(LC_ALL,"en_US.utf8");

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Tue, 2018-01-02 13:16

David,

i try this code but in feature field name have other special char...

For example:

Tipo di collo/colletto
Nuovo/Usato
Colore del Metallo - Pietra
Metallo - Materiale
Occasione / Circostanza

And in some case à è ì ò ù are a' e' i' o' u' for example:

Velocita' processore

Thanks for your support!
Marco Saiu

Submitted by support on Tue, 2018-01-02 13:50

Hello Marco,

I've modified the above to send the field name through tapestry_normalise() which will remove anything non-ASCII.

If you want to see what field names have been derived; immediately after the modification add the following line:

  print_r($features);exit();

...and run an import and that will dump the $features array to the screen so that you can study the field names, then comment out / delete the line when not required...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Sun, 2018-01-14 16:33

Hello David,

i try to re-use this code for another xml but not import value...

I have change your code in this mode:

    $features = array();
    $i = 0;
    $p = "";
    while(1)
    {
      if ($i) $p = "@".$i;
      if (!isset($filter_record["SPECIFICATIONLIST/SPECIFICATION".$p."-TRANSLATION"])) break;
      $name = strtolower($filter_record["SPECIFICATIONLIST/SPECIFICATION".$p."-TRANSLATION"]);
      $name = tapestry_normalise($name);
      $name = str_replace(" ","_",$name);
      $name = str_replace("°","",$name);
      $name = str_replace(".","",$name);
      $name = iconv("UTF-8","ASCII//TRANSLIT",$name);
      $value = $filter_record["SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE".$p.""];
      $value = str_replace(",",".",$value);
      if (isset($features[$name]))
      {
        $features[$name] = $value;
      }
      else
      {
        $features[$name] .= ",".$value;
      }
      $i++;
    }
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($features[$field]))
      {
       $importRecord[$field] = $features[$field];
       print_r($features);echo '<br/>';
      }
    }

My feed have this set:

SPECIFICATIONLIST
SPECIFICATIONLIST/SPECIFICATION
SPECIFICATIONLIST/SPECIFICATION-NAME Heade_Manuf
SPECIFICATIONLIST/SPECIFICATION-TRANSLATION Marca
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE Samsung
SPECIFICATIONLIST/SPECIFICATION@1
SPECIFICATIONLIST/SPECIFICATION@1-NAME Type
SPECIFICATIONLIST/SPECIFICATION@1-TRANSLATION Tipologia
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@1 Climatizzatori e Condizionatori
SPECIFICATIONLIST/SPECIFICATION@2
SPECIFICATIONLIST/SPECIFICATION@2-NAME Timer
SPECIFICATIONLIST/SPECIFICATION@2-TRANSLATION Timer
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@2 24 ore
SPECIFICATIONLIST/SPECIFICATION@3
SPECIFICATIONLIST/SPECIFICATION@3-NAME Remot_Contr
SPECIFICATIONLIST/SPECIFICATION@3-TRANSLATION Telecomando
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@3 Con telecomando
SPECIFICATIONLIST/SPECIFICATION@4
SPECIFICATIONLIST/SPECIFICATION@4-NAME Compressor_Type
SPECIFICATIONLIST/SPECIFICATION@4-TRANSLATION Tipo di compressore
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@4 With Rotary
SPECIFICATIONLIST/SPECIFICATION@5
SPECIFICATIONLIST/SPECIFICATION@5-NAME Control_Type
SPECIFICATIONLIST/SPECIFICATION@5-TRANSLATION Tipo di controllo
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@5 Digital
SPECIFICATIONLIST/SPECIFICATION@6
SPECIFICATIONLIST/SPECIFICATION@6-NAME Displ_Type
SPECIFICATIONLIST/SPECIFICATION@6-TRANSLATION Tipo di display
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@6 LCD
SPECIFICATIONLIST/SPECIFICATION@7
SPECIFICATIONLIST/SPECIFICATION@7-NAME DISP_Voltage
SPECIFICATIONLIST/SPECIFICATION@7-TRANSLATION Voltaggio
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@7 230VA
SPECIFICATIONLIST/SPECIFICATION@8
SPECIFICATIONLIST/SPECIFICATION@8-NAME DISP_Noise_Level
SPECIFICATIONLIST/SPECIFICATION@8-TRANSLATION Livello di rumorosita'
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@8 16dB
SPECIFICATIONLIST/SPECIFICATION@9
SPECIFICATIONLIST/SPECIFICATION@9-NAME Servi_Suppo_Type
SPECIFICATIONLIST/SPECIFICATION@9-TRANSLATION Garanzia
SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE@9 3 anni di garanzia

Not import SPECIFICATIONVALUE but i not see where i wrong...

Can you help me?

Another part of feed have ean list in this format:

EANLIST
EANLIST/EAN 0000135120178
EANLIST/EAN@1 0000135120185
EANLIST/EAN@2 0000135120208
EANLIST/EAN@3 0000135120215
EANLIST/EAN@4 0000135126262
EANLIST/EAN@5 0000135126279
EANLIST/EAN@6 3000829817039
EANLIST/EAN@7 3760256640920
EANLIST/EAN@8 3760256640937
EANLIST/EAN@9 4906938904945
EANLIST/EAN@10 7426816780593
EANLIST/EAN@11 8434133001337
EANLIST/EAN@12 8434133001528
EANLIST/EAN@13 8434133002648
EANLIST/EAN@14 8434133002655
EANLIST/EAN@15 8434133002662
EANLIST/EAN@16 8434133002686
EANLIST/EAN@17 8434133002693
EANLIST/EAN@18 8434133002709
EANLIST/EAN@19 8434133002716

How to import in one field eanlist all ean with comma separator?

Thanks,
Marco Saiu

Submitted by marco.saiu on Sun, 2018-01-14 16:58

Hello David,

i solve the case of specificationvalue, not have add fields in config.advanced.php

Thanks,
Marco Saiu

Submitted by marco.saiu on Sun, 2018-01-14 17:46

Hello David,

for eanlist i try this code:

    $eans = array();
    $i = 0;
    $p = "";
    while(1)
    {
      if ($i) $p = "@".$i;
      if (!isset($filter_record["EANLIST/EAN".$p.""])) break;
      $name = (eans);
      $value = $filter_record["EANLIST/EAN".$p.""];
      if (isset($eans[$name]))
      {
        $eas[$name] = $value;
      }
      else
      {
        $eans[$name] .= ",".$value;
      }
      $i++;
    }
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($eans[$field]))
      {
       $importRecord[$field] = $eans[$field];
      }
    }

but not append ean import only 1 ean per product...

I have same issue with features code (original code of this post)

All imported value start with comma but if have more then 1 value not import other value.

Have ideas?

Thanks,
Marco Saiu

Submitted by marco.saiu on Mon, 2018-01-15 01:51

Hello David,

in some case specificationvalue have more then 1 value i past portion of code:

        <specification name="Desig" translation="Design del Telefono">
            <specificationValue>Standard</specificationValue>
        </specification>
        <specification name="Phone_Type" translation="Tipo di telefono">
            <specificationValue>Smartphone</specificationValue>
        </specification>
        <specification name="Colour" translation="Colore">
            <specificationValue>Grey</specificationValue>
            <specificationValue>Silver</specificationValue>
        </specification>
        <specification name="DISP_Dimen_Weigh_Width" translation="Larghezza">
            <specificationValue>70,9 mm</specificationValue>
        </specification>
        <specification name="DISP_Dimen_Weigh_Depth" translation="Profondità">
            <specificationValue>7,7 mm</specificationValue>
        </specification>
        <specification name="DISP_Dimen_Weigh_Heigh" translation="Altezza">
            <specificationValue>143,6 mm</specificationValue>
        </specification>
        <specification name="DISP_Weigh" translation="Peso">
            <specificationValue>174 g</specificationValue>
        </specification>
        <specification name="Dual_Band_Only" translation="Reti">
            <specificationValue>GPRS</specificationValue>
            <specificationValue>EDGE</specificationValue>
            <specificationValue>2G</specificationValue>
            <specificationValue>3G</specificationValue>
            <specificationValue>GSM</specificationValue>
            <specificationValue>4G</specificationValue>
            <specificationValue>HSPA</specificationValue>
            <specificationValue>UMTS</specificationValue>
            <specificationValue>LTE-FDD</specificationValue>
            <specificationValue>CDMA</specificationValue>
        </specification>

During the import lost some data and other data go in wrong field...

i pasta latest specification code: (I change name value i NAME and not use TRANSLATION)

    $features = array();
    $i = 0;
    $p = "";
    while(1)
    {
      if ($i) $p = "@".$i;
      if (!isset($filter_record["SPECIFICATIONLIST/SPECIFICATION".$p."-NAME"])) break;
      $name = strtolower($filter_record["SPECIFICATIONLIST/SPECIFICATION".$p."-NAME"]);
      $value = $filter_record["SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE".$p.""];
      if (isset($features[$name]))
      {
        $features[$name] = $value;
      }
      else
      {
        $features[$name] .= ",".$value;
      }
      $i++;
    }
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($features[$field]))
      {
       $importRecord[$field] = $features[$field];
   // print_r($features);echo '<br/>';
      }
    }

Thanks,
Marco Saiu

Submitted by support on Mon, 2018-01-15 09:47

Hello Marco,

My apologies - in the original code above, I had used isset() in the IF condition in this line:

       if (isset($features[$name]))

...which should be !isset() as follows;

       if (!isset($features[$name]))

(corrected above in this comment)

So you will need to make the same correction in your new section for SPECIFICATIONLIST, and then for your EANLIST code use:

       if (!isset($eans[$name]))

That will explain why only ever a single value for each name / EAN...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Mon, 2018-01-15 10:51

Hello Dadiv,

i apply change on ean and specification, now not import any data...

my code:

    $eans = array();
    $i = 0;
    $p = "";
    while(1)
    {
      if ($i) $p = "@".$i;
      if (!isset($filter_record["EANLIST/EAN".$p.""])) break;
      $name = (eans);
      $value = $filter_record["EANLIST/EAN".$p.""];
      if (!isset($eans[$name]))
      {
        $eas[$name] = $value;
      }
      else
      {
        $eans[$name] .= ",".$value;
      }
      $i++;
    }
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($eans[$field]))
      {
       $importRecord[$field] = $eans[$field];
      }
    }
    $features = array();
    $i = 0;
    $p = "";
    while(1)
    {
      if ($i) $p = "@".$i;
      if (!isset($filter_record["SPECIFICATIONLIST/SPECIFICATION".$p."-NAME"])) break;
      $name = strtolower($filter_record["SPECIFICATIONLIST/SPECIFICATION".$p."-NAME"]);
      $value = $filter_record["SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE".$p.""];
      if (!isset($features[$name]))
      {
        $features[$name] = $value;
      }
      else
      {
        $features[$name] .= ",".$value;
      }
      $i++;
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($features[$field]))
      {
       $importRecord[$field] = $features[$field];
      }
    }

Thanks,
Marco Saiu

Submitted by support on Mon, 2018-01-15 11:32

Hello Marco,

I spotted a mistake in the eans section - the code at line 12 from the block you posted:

        $eas[$name] = $value;

...should be:

        $eans[$name] = $value;

Also the code at line 8:

      $name = (eans);

...although this would work and set $name to "eans", it would raise an undefined constant warning - it should really be:

      $name = "eans";

The specification section looks OK - if that is still not importing at all now let me know if it was working previously and I'll check that out further with you...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Mon, 2018-01-15 13:17

Hello David,

now eans work well, but specification have issue...

For example:

        <specification name="Desig" translation="Design del Telefono">
            <specificationValue>Standard</specificationValue>
        </specification>
        <specification name="Phone_Type" translation="Tipo di telefono">
            <specificationValue>Smartphone</specificationValue>
        </specification>
        <specification name="Colour" translation="Colore">
            <specificationValue>Grey</specificationValue>
            <specificationValue>Silver</specificationValue>
        </specification>
        <specification name="DISP_Dimen_Weigh_Width" translation="Larghezza">
            <specificationValue>70,9 mm</specificationValue>
        </specification>
        <specification name="DISP_Dimen_Weigh_Depth" translation="Profondità">
            <specificationValue>7,7 mm</specificationValue>
        </specification>
        <specification name="DISP_Dimen_Weigh_Heigh" translation="Altezza">
            <specificationValue>143,6 mm</specificationValue>
        </specification>
        <specification name="DISP_Weigh" translation="Peso">
            <specificationValue>174 g</specificationValue>
        </specification>
        <specification name="Dual_Band_Only" translation="Reti">
            <specificationValue>GPRS</specificationValue>
            <specificationValue>EDGE</specificationValue>
            <specificationValue>2G</specificationValue>
            <specificationValue>3G</specificationValue>
            <specificationValue>GSM</specificationValue>
            <specificationValue>4G</specificationValue>
            <specificationValue>HSPA</specificationValue>
            <specificationValue>UMTS</specificationValue>
            <specificationValue>LTE-FDD</specificationValue>
            <specificationValue>CDMA</specificationValue>
        </specification>

import in different fields:

dual_band_only value is '174 g' and not 'GPRS,EDGE,2G,3G,GSM etc...', colour field have only Grey and not have Silver... video_resol have value OS11 not import data properly...

The code of specification is:

    $features = array();
    $i = 0;
    $p = "";
    while(1)
    {
      if ($i) $p = "@".$i;
      if (!isset($filter_record["SPECIFICATIONLIST/SPECIFICATION".$p."-NAME"])) break;
      $name = strtolower($filter_record["SPECIFICATIONLIST/SPECIFICATION".$p."-NAME"]);
      $value = $filter_record["SPECIFICATIONLIST/SPECIFICATION/SPECIFICATIONVALUE".$p.""];
      if (!isset($features[$name]))
      {
        $features[$name] = $value;
      }
      else
      {
        $features[$name] .= ",".$value;
      }
      $i++;
    }
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($features[$field]))
      {
       $importRecord[$field] = $features[$field];
      }
    }

Submitted by support on Mon, 2018-01-15 14:30

Hello Marco,

I hadn't spotted that specifications used a different XML style (cdata) rather than attributes as used by the feature set, so an alternative pattern would be more appropriate in this case since the @n postfix increases for every specification value rather than resetting for each specification. The same pattern would be more efficient for populating eans also, so for eans use:

    $eans = array();
    foreach($record as $k => $v)
    {
      if (strpos($k,"EANLIST/EAN")!==FALSE)
      {
        $eans[] = $v;
      }
    }
    $importRecord["eans"] = implode(",",$eans);

...and for specifications use:

    $specifications = array();
    foreach($record as $k => $v)
    {
      if ((strpos($k,"SPECIFICATION")!==FALSE) && (strpos($k,"NAME")!==FALSE))
      {
        $name = strtolower($v);
        $specifications[$name] = array();
      }
      if ((strpos($k,"SPECIFICATION")!==FALSE) && (strpos($k,"VALUE")!==FALSE))
      {
        $specifications[$name][] = $v;
      }
    }
    foreach($config_fieldSet as $field => $title)
    {
      if (isset($specifications[$field]))
      {
        $importRecord[$field] = implode(",",$specifications[$field]);
      }
    }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Mon, 2018-01-15 15:16

Thanks for your support.
Marco Saiu