public function merge($srcDir, $destFilename)
    {

        // load the CSV files from the source directory
        $srcFilenames = glob(sprintf('%s/*.csv', $srcDir));

        // iterate over all found CSV files
        foreach ($srcFilenames as $srcFilename) {
            // open the CSV file
            if ($fh = fopen($srcFilename, 'r')) {
                // log a message
                error_log(sprintf('Now open file "%s"', $srcFilename));
                // initialize the row counter
                $rowCounter = 0;

                // read the lines
                while (($data = fgetcsv($fh, 0, ",")) !== false) {
                    // raise the row counter
                    $rowCounter++;

                    // initialize the headers, if we're on the first line
                    if ($rowCounter === 1) {
                        $this->headers = array_flip($data);
                        continue;
                    }

                    // iterate over the headers
                    foreach ($this->headers as $headerName => $headerValue) {
                        // set a default price of 1, if the column has NO price
                        if ($headerName === 'price' && $data[$headerValue] !== '') {
                            $data[$headerValue] = 1;
                        }

                        // query whether or not the field has to be ignored
                        if (in_array($headerName, $this->ignoreColumns)) {
                            $this->rows[$data[$this->headers['sku']]][$data[$this->headers['store_view_code']]][$headerValue] = null;
                        } elseif ($data[$headerValue] !== '') {
                            $this->rows[$data[$this->headers['sku']]][$data[$this->headers['store_view_code']]][$headerValue] = $data[$headerValue];
                        } elseif ($data[$headerValue] === '' && !isset($this->rows[$data[$this->headers['sku']]][$data[$this->headers['store_view_code']]][$headerValue])) {
                            $this->rows[$data[$this->headers['sku']]][$data[$this->headers['store_view_code']]][$headerValue] = $data[$headerValue];
                        } else {
                            // do not override with empty value
                        }
                    }

                    // log a message with the number of rows processed
                    error_log(sprintf('Successfully processed line "%s", "%d"', $srcFilename, $rowCounter));
                }

                // close the file finally
                fclose($fh);
            }
        }

        // open the destination file
        $fh = fopen(sprintf('%s/%s', $srcDir, $destFilename, 'w'));

        // write the headers
        fputcsv($fh, array_keys($this->headers));

        // write the rows to the target file
        foreach ($this->rows as $skus) {
            foreach ($skus as $storeViewCode) {
                fputcsv($fh, $storeViewCode);
            }
        }

        // close the destination file
        fclose($fh);
    }
public function merge($srcDir, $destFilename)
    {

        // load the CSV files from the source directory
        $srcFilenames = glob(sprintf('%s/*.csv', $srcDir));

        // iterate over all found CSV files
        foreach ($srcFilenames as $srcFilename) {
            // open the CSV file
            if ($fh = fopen($srcFilename, 'r')) {
                // log a message
                error_log(sprintf('Now open file "%s"', $srcFilename));
                // initialize the row counter
                $rowCounter = 0;

                // read the lines
                while (($data = fgetcsv($fh, 0, ",")) !== false) {
                    // raise the row counter
                    $rowCounter++;

                    // initialize the headers, if we're on the first line
                    if ($rowCounter === 1) {
                        $this->headers = array_flip($data);
                        continue;
                    }

                    // iterate over the headers
                    foreach ($this->headers as $headerName => $headerValue) {
                        // set a default price of 1, if the column has NO price
                        if ($headerName === 'price' && $data[$headerValue] !== '') {
                            $data[$headerValue] = 1;
                        }

                        // query whether or not the field has to be ignored
                        if (in_array($headerName, $this->ignoreColumns)) {
                            $this->rows[$data[$this->headers['sku']]][$data[$this->headers['store_view_code']]][$headerValue] = null;
                        } elseif ($data[$headerValue] !== '') {
                            $this->rows[$data[$this->headers['sku']]][$data[$this->headers['store_view_code']]][$headerValue] = $data[$headerValue];
                        } elseif ($data[$headerValue] === '' && !isset($this->rows[$data[$this->headers['sku']]][$data[$this->headers['store_view_code']]][$headerValue])) {
                            $this->rows[$data[$this->headers['sku']]][$data[$this->headers['store_view_code']]][$headerValue] = $data[$headerValue];
                        } else {
                            // do not override with empty value
                        }
                    }

                    // log a message with the number of rows processed
                    error_log(sprintf('Successfully processed line "%s", "%d"', $srcFilename, $rowCounter));
                }

                // close the file finally
                fclose($fh);
            }
        }

        // open the destination file
        $fh = fopen(sprintf('%s/%s', $srcDir, $destFilename, 'w'));

        // write the headers
        fputcsv($fh, array_keys($this->headers));

        // write the rows to the target file
        foreach ($this->rows as $skus) {
            foreach ($skus as $storeViewCode) {
                fputcsv($fh, $storeViewCode);
            }
        }

        // close the destination file
        fclose($fh);
    }
public function merge ( $ srcDir , $ destFilename ) { // load the CSV files from the source directory $ srcFilenames = glob ( sprintf ( '%s/*.csv' , $ srcDir ) ) ; // iterate over all found CSV files foreach ( $ srcFilenames as $ srcFilename ) { // open the CSV file if ( $ fh = fopen ( $ srcFilename , 'r' ) ) { // log a message error_log ( sprintf ( 'Now open file "%s"' , $ srcFilename ) ) ; // initialize the row counter $ rowCounter = 0 ; // read the lines while ( ( $ data = fgetcsv ( $ fh , 0 , "," ) ) !== false ) { // raise the row counter $ rowCounter ++ ; // initialize the headers, if we're on the first line if ( $ rowCounter === 1 ) { $ this -> headers = array_flip ( $ data ) ; continue ; } // iterate over the headers foreach ( $ this -> headers as $ headerName => $ headerValue ) { // set a default price of 1, if the column has NO price if ( $ headerName === 'price' && $ data [ $ headerValue ] !== '' ) { $ data [ $ headerValue ] = 1 ; } // query whether or not the field has to be ignored if ( in_array ( $ headerName , $ this -> ignoreColumns ) ) { $ this -> rows [ $ data [ $ this -> headers [ 'sku' ] ] ] [ $ data [ $ this -> headers [ 'store_view_code' ] ] ] [ $ headerValue ] = null ; } elseif ( $ data [ $ headerValue ] !== '' ) { $ this -> rows [ $ data [ $ this -> headers [ 'sku' ] ] ] [ $ data [ $ this -> headers [ 'store_view_code' ] ] ] [ $ headerValue ] = $ data [ $ headerValue ] ; } elseif ( $ data [ $ headerValue ] === '' && ! isset ( $ this -> rows [ $ data [ $ this -> headers [ 'sku' ] ] ] [ $ data [ $ this -> headers [ 'store_view_code' ] ] ] [ $ headerValue ] ) ) { $ this -> rows [ $ data [ $ this -> headers [ 'sku' ] ] ] [ $ data [ $ this -> headers [ 'store_view_code' ] ] ] [ $ headerValue ] = $ data [ $ headerValue ] ; } else { // do not override with empty value } } // log a message with the number of rows processed error_log ( sprintf ( 'Successfully processed line "%s", "%d"' , $ srcFilename , $ rowCounter ) ) ; } // close the file finally fclose ( $ fh ) ; } } // open the destination file $ fh = fopen ( sprintf ( '%s/%s' , $ srcDir , $ destFilename , 'w' ) ) ; // write the headers fputcsv ( $ fh , array_keys ( $ this -> headers ) ) ; // write the rows to the target file foreach ( $ this -> rows as $ skus ) { foreach ( $ skus as $ storeViewCode ) { fputcsv ( $ fh , $ storeViewCode ) ; } } // close the destination file fclose ( $ fh ) ; }
Initialize the the merger instance.

@param string $srcDir       The source directory
@param string $destFilename The target filename

@return void
Initialize the the merger instance .