Example #1
0
 function main()
 {
     if (!$this->lastArgument()) {
         echo 'vfmagento importvehicles <filename>' . "\n";
         exit;
     }
     $file = $this->lastArgument();
     $writer = new Zend_Log_Writer_Stream('vehicles-list-import.csv.log');
     $log = new Zend_Log($writer);
     $importer = new VF_Import_VehiclesList_CSV_Import($file);
     $importer->setLog($log);
     $importer->import();
 }
    protected function importDefinitions()
    {
        $csvData = 'make, model, trim, engine, year
honda, civic, ex, a, 2000
honda, civic, ex, b, 2000
honda, civic, lx, a, 2000
honda, civic, lx, b, 2000
honda, civic, lx, b, 2001
not honda, civic, lx, b, 2000';
        $csvFile = TEMP_PATH . '/definitions.csv';
        file_put_contents($csvFile, $csvData);
        $importer = new VF_Import_VehiclesList_CSV_Import($csvFile);
        $importer->import();
    }
 function doIndexAction()
 {
     $config = $this->getConfig();
     $this->block->setTemplate('vf/vaf/vfdata.phtml');
     $form = $this->form();
     $this->block->form = $form;
     if ($this->getRequest()->getParam('download')) {
         $download_url = 'http://data.vehiclefits.com/api/download?token=' . $config->vfdata->api_token;
         $local_file = sys_get_temp_dir() . '/' . uniqid();
         $local_stream = fopen($local_file, 'w');
         $download_stream = fopen($download_url, 'r');
         while (!feof($download_stream)) {
             $buffer = fread($download_stream, 512);
             // use a buffer of 512 bytes
             fwrite($local_stream, $buffer);
         }
         fclose($download_stream);
         fclose($local_stream);
         $importer = new VF_Import_VehiclesList_CSV_Import($local_file);
         $importer->import();
         $this->block->downloaded = true;
         return;
     }
     if ($this->getRequest()->getParam('upload')) {
         $upload_url = 'http://data.vehiclefits.com/api/upload?token=' . $config->vfdata->api_token;
         $local_file = sys_get_temp_dir() . '/' . uniqid();
         $local_stream = fopen($local_file, 'w');
         $exporter = new VF_Import_VehiclesList_CSV_Export();
         $exporter->export($local_stream);
         $ch = curl_init($upload_url);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($local_file));
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $response = curl_exec($ch);
         $this->block->uploaded = $response;
     }
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getParams())) {
         $config->vfdata->api_token = $form->getValue('api_token');
         $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => ELITE_CONFIG));
         echo $writer->write();
     }
 }
Example #4
0
 function indexAction()
 {
     $schema = $this->schema();
     if ($this->getRequest()->isPost()) {
         if ($this->attemptedFileUpload() && $this->fileUploadHasError()) {
             $this->flashFileUploadErrorMessage();
         } else {
             if ($_FILES['file']['tmp_name']) {
                 $tmpFile = $_FILES['file']['tmp_name'];
             } else {
                 $tmpFile = sys_get_temp_dir() . '/' . sha1(uniqid());
                 file_put_contents($tmpFile, $_POST['text']);
             }
             $importer = new \VF_Import_VehiclesList_CSV_Import($tmpFile);
             //$importer->setLog($log);
             $importer->import();
             $this->flashMessenger()->setNamespace('success')->addMessage('Imported Vehicles List');
         }
     }
     return array('schema' => $schema->getLevels());
 }
Example #5
0
 /** @return array Field positions keyed by the field's names */
 function getFieldPositions()
 {
     $this->fieldPositions = parent::getFieldPositions();
     if (!isset($this->fieldPositions['sku'])) {
         throw new VF_Import_VehiclesList_CSV_Exception_FieldHeaders('Unable to locate field header for [sku], perhaps not using comma delimiter');
     }
     return $this->fieldPositions;
 }
<?php

/**
 * Vehicle Fits
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to sales@vehiclefits.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Vehicle Fits to newer
 * versions in the future. If you wish to customize Vehicle Fits for your
 * needs please refer to http://www.vehiclefits.com for more information.
 * @copyright  Copyright (c) 2013 Vehicle Fits, llc
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
require_once 'config.php';
$file = 'vehicles-list-import.csv';
$writer = new Zend_Log_Writer_Stream('vehicles-list-import.csv.log');
$log = new Zend_Log($writer);
$importer = new VF_Import_VehiclesList_CSV_Import($file);
$importer->setLog($log);
$importer->import();