Example #1
0
 public function __construct($fileName)
 {
     $this->fileName = $fileName;
     $inputFileType = 'Excel2007';
     /**  Create a new Reader of the type defined in $inputFileType  **/
     $this->objReader = PHPExcel_IOFactory::createReader($inputFileType);
     $worksheetList = $this->objReader->listWorksheetNames($this->fileName);
     $sheets = array($worksheetList[2], $worksheetList[3]);
     $this->objReader->setLoadSheetsOnly($sheets);
     $this->objReader->setReadDataOnly(true);
     SyncVendor::log("Begin loading " . $this->fileName . " base file.");
     $this->objPHPExcel = $this->objReader->load($this->fileName);
     SyncVendor::log("Base excel file loaded.");
 }
Example #2
0
 public function getNextLine()
 {
     if ($this->endOfFile) {
         if (!$this->fileSupplier->endReached()) {
             $this->currentSheetConfig = $this->fileSupplier->getCurrentSheetConfig();
             $this->currentFile = $this->fileSupplier->nextFile();
             SyncVendor::log("Loading " . pathinfo($this->currentFile, PATHINFO_BASENAME) . "...");
             if (file_exists($this->currentFile)) {
                 $this->objPHPExcel = PHPExcel_IOFactory::load($this->currentFile);
                 SyncVendor::log("Loading done. Parsing ...");
                 $this->lastRow = $this->objPHPExcel->getActiveSheet()->getHighestRow();
                 $this->currentLine = $this->currentSheetConfig['first-row'];
                 $this->endOfFile = false;
             } else {
                 SyncVendor::log("WARNING: File " . pathinfo($this->currentFile, PATHINFO_BASENAME) . " not found");
                 $this->endOfFile = true;
                 return $this->getNextLine();
             }
         } else {
             $this->endReached = true;
             return false;
         }
     }
     $returnData = array();
     $itemColumn = $this->currentSheetConfig['item-column'];
     $priceColumn = $this->currentSheetConfig['price-column'];
     $qtyColumn = $this->currentSheetConfig['qty-column'];
     $returnData['item'] = $this->objPHPExcel->getActiveSheet()->getCell($itemColumn . $this->currentLine)->getValue();
     if (isset($this->currentSheetConfig['separator'])) {
         $returnData['item'] = explode($this->currentSheetConfig['separator'], $returnData['item']);
         $returnData['item'] = $returnData['item'][0];
     }
     $returnData['price'] = $this->objPHPExcel->getActiveSheet()->getCell($priceColumn . $this->currentLine)->getValue() * (100 - $this->config['discount']) / 100;
     $returnData['qty'] = (int) $this->objPHPExcel->getActiveSheet()->getCell($qtyColumn . $this->currentLine)->getCalculatedValue();
     if (!$returnData['qty']) {
         $returnData['qty'] = 1;
     }
     if ($this->currentLine > $this->lastRow) {
         SyncVendor::log("File " . $this->currentFile . " parsed. " . $this->currentLine . " lines.");
         unset($this->objPHPExcel);
         $this->endOfFile = true;
         return $this->getNextLine();
     }
     $this->currentLine++;
     return $returnData;
 }
Example #3
0
 public function __construct($syncConfig)
 {
     $this->config = $syncConfig;
     if ($syncConfig['base-recreate-table'] == true) {
         $counter = 0;
         SyncVendor::log("Database table creation started.");
         $columns[] = 'item_id';
         $columns[] = 'interest';
         db_query("DROP TABLE IF EXISTS " . $syncConfig['base-table']);
         $query = "CREATE TABLE " . $syncConfig['base-table'] . " ( item_id VARCHAR(50) NOT NULL, interest DECIMAL(5,2) NOT NULL DEFAULT 100.00, ";
         foreach ($syncConfig['vendors'] as $vendor) {
             $query .= $vendor['base-data-column-name'] . " VARCHAR(50) NOT NULL,";
             $columns[] = $vendor['base-data-column-name'];
         }
         $query = rtrim($query, ",");
         $query .= ") ENGINE=InnoDB   DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;";
         db_query($query);
         $excelBaseData = new ExcelBaseData(DIR_SYNC_VENDORS . $syncConfig['base-file']);
         $excel = $excelBaseData->objPHPExcel;
         $this->excel = $excel;
         $lastRow = $excel->setActiveSheetIndex(0)->getHighestRow();
         for ($row = 2; $row <= $lastRow; $row++) {
             $query = "INSERT INTO " . $syncConfig['base-table'] . " ";
             $values = array();
             $itemId = $excel->setActiveSheetIndex(0)->getCell("A" . $row)->getValue();
             $values['item_id'] = "'" . $itemId . "'";
             $values['interest'] = $this->getInterest($itemId);
             foreach ($syncConfig['vendors'] as $vendor) {
                 $values[] = "'" . $excel->setActiveSheetIndex(0)->getCell($vendor["base-data-column"] . $row)->getValue() . "'";
                 //$values[] = $value ? $value : "''";
             }
             $query .= "(" . implode(",", $columns) . ") VALUES (" . implode(",", $values) . ")";
             db_query($query);
             $counter++;
             if (fmod($counter, 1000) == 0) {
                 SyncVendor::log($counter . " records inserted.");
             }
         }
         SyncVendor::log("Database table creation ended. " . $counter . " records inserted.");
         $excel->disconnectWorksheets();
         unset($this->objPHPExcel);
     }
 }
Example #4
0
    die('a');
} elseif ($mode == 'enable_discussions') {
    $product_ids = db_get_fields("SELECT product_id FROM cscart_products");
    foreach ($product_ids as $product_id) {
        $product_data = array();
        $product_data['discussion_type'] = "B";
        fn_discussion_update_product($product_data, $product_id);
    }
} elseif ($mode == 'sync_vendors') {
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    include_once DIR_SYNC_VENDORS . "SyncVendor.php";
    include_once DIR_SYNC_VENDORS . "PHPExcel.php";
    ini_set('max_execution_time', 0);
    ini_set('memory_limit', '512M');
    $svp = new SyncVendor();
    $svp->downloadSheets();
    $svp->run();
    return array(CONTROLLER_STATUS_OK, "settings.manage&section_id=Vendors?sync=y");
} elseif ($mode == 'show_log') {
    $lines = file(DIR_SYNC_VENDORS . "syncVendor.log");
    foreach ($lines as $line) {
        fn_echo($line . "<br>");
    }
    die;
}
// --------- ExIm core functions ------------------
//delete cache
function deleteDirectory($dir)
{
    if (!file_exists($dir)) {