FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Prestashop Mapping solution
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Prestashop Mapping solution
Posted: Sun Oct 23, 2016 07:34 PM
James Bott wrote:Marc,

I also have to put for the half of all fields standard data, not provided into the csv.

Stock = "1"
Language = "NL"
Currence = "EUR"

These data can be pre filled than into the master file, since I create 1 record with relevant data.


I don't work with different languages much. Could you explain in more detail? Are you saying you are going to have to translate text during the import too? Yikes!

Currency: So there is a field in each file containing which currency is used? If so then a simple DO CASE loop for each field should solve this. However, I expect you will need to use the record's date (assuming there is one) to lookup the exchange rate that was in effect at the time the data was collected in order to do the proper conversion.

Still, look for commonality rather than coding for each file-type.

James


James,

So i don't need to code much, only the loop from the master file, where the field master->source contains data like

They are always "Char" type, and that is ok for the import in the shop.

Rec 1 = "substr(csv->data,5,2)" // from the mapping routine
Rec 2 = "EUR" // set default by me
Rec 3 = "1" // set default
Rec 4 = "val(csv->price,7,2)" // mapping routine

the difficult part is to get the data right (Pre-Process expression ??) but with the dbf and not in the csv files (they are left alone)

This is the only routine with the problem for now

master->source = REC1 so it contains something like
"substr(csv->data,5,2)"

Code (fw): Select all Collapse
do while !master->eof()
  cTemp = master->source  
  Cdata = cTemp  // here it should execute the functions in the string, so get the data from csv->data AND process it with the function substr()
  master->gooddate = cData
  master->(dbskip())
enddo


Since the functions like substr() and val(), ... exist, i thought it could be done in 1 loop and FWin can process this ??

The code in the errorlog.prg looks like it. Here are also functions processed in order to get a cfield filled with data

Code (fw): Select all Collapse
cErrorLog += "    " + Transform( ( Alias( n ) )->( RecNo() ), "99999" ) + ;
                      "      " + Transform( ( Alias( n ) )->( RecCount() ), "99999" ) + ;
                      "      " + cValToChar( ( Alias( n ) )->( BoF() ) ) + ;
                      "   " + cValToChar( ( Alias( n ) )->( EoF() ) ) + CRLF + CRLF


I think it is called expression that i need to process.
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Prestashop Mapping solution
Posted: Sun Oct 23, 2016 10:29 PM
Marc,

>So i don't need to code much, only the loop from the master file, where the field master->source contains data like:


I guess I have not been clear. Granted you only have to process each field once inside the import loop. However, you need to write a new loop for each type of CSV file. So let' say you have 80 fields (in the master file) and 50 types of CSV files, then you have do have a DO CASE statement that has 50 CASE statements and inside each one there has to be 80 process statements. So that is 50 x 80 = 4000 lines of code minimum!

Code (fw): Select all Collapse
// IMPORT CSV file into a DBF then open it here

DO WHILE .NOT. oCSV:eof() // in the master file
   DO CASE
      CASE nFiletype = 2018
         oMaster:ItemNo := ...
         oMaster:Descriptiion := ...
         ... all the way to 80 fields
      CASE nFiletype = 1334
         oMaster:ItemNo := ...
         oMaster:Descriptiion := ...
         ... all the way to 80 fields
      ... // one CASE for each filetype

On the other hand, maybe I sill don't understand what you are trying to do.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Prestashop Mapping solution
Posted: Tue Oct 25, 2016 09:23 PM
James,

Indeed, we are not on the same idea here ..

I have most of it working, and the finale process is converting the data. It works almost, with 1 problem.

I have started a new topic for it. It is a problem with the & operator.

Here is to code that will process all my csv files afther I have mapped the data.
Solving the converting issue will get me started. (see other topic)

Code (fw): Select all Collapse
function filldbf()
   Local aCustfields:={}

   use slave
   select slave
   zap
   close
   use DASSY NEW alias CUST
   use slave NEW alias slave
   use master NEW alias master

   select cust
   for i = 1 to cust->(FCOUNT())
      AADD(aCustfields,Fieldname(i))  // make arry with all fieldnames from datafile
   next

   select master
   master->(dbgotop())
   nMasterfields = master->(fcount())
   cust->(dbgotop())
   nTel = 0

   do while !cust->(eof())
      slave->(dbappend())

      for i = 1 to nMasterfields

         cWelkField = "master->"+fieldname(i)
         clookup = alltrim(&cWelkfield)        // data from the masterfile, result = fieldname to look for next
         if !empty(clookup)
            apos = ascan(aCustfields,clookup)  // to see if the data is a fieldname, could also be simple data

             if apos > 0  // found as a fieldname
                cTarget = "slave->"+fieldname(i)

  //            cField = "CUST->"+aCustfields[i]
                cField = "CUST->"+cLookup

 //               cData = &cField // not working
                cData = cField

              &cTarget = cData
            else  // standard data, but no fieldname
                cData = cField  // GIVES THE DATA, BUT ERROR FOR THE NEXT DO/ENDDO LOOK
                &cTarget = cData
           endif
         endif
        next
      cust->(dbskip())
   enddo

   select slave
   xbrowse()
   close all
return
Marc Venken

Using: FWH 23.08 with Harbour

Continue the discussion