当前位置: 首页>>代码示例>>PHP>>正文


PHP Varien_Io_File::streamWriteCsv方法代码示例

本文整理汇总了PHP中Varien_Io_File::streamWriteCsv方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Io_File::streamWriteCsv方法的具体用法?PHP Varien_Io_File::streamWriteCsv怎么用?PHP Varien_Io_File::streamWriteCsv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Varien_Io_File的用法示例。


在下文中一共展示了Varien_Io_File::streamWriteCsv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: export

 /**
  * Export function:
  * - Returns false, if an error occured or if there are no orders to export
  * - Returns array, containing the filename and the file contents
  *
  * @return bool|array
  */
 public function export()
 {
     $collection = $this->_hasOrdersToExport();
     if (!$collection) {
         return false;
     }
     $fileName = $this->getFileName();
     // Open file
     $file = new Varien_Io_File();
     $file->open(array('path' => Mage::getBaseDir('var')));
     $file->streamOpen($fileName);
     // Add headline
     $row = array('Kundenname', 'BLZ', 'Kontonummer', 'BIC/Swift-Code', 'IBAN', 'Betrag', 'Verwendungszweck');
     $file->streamWriteCsv($row);
     // Add rows
     foreach ($collection as $order) {
         /* @var $orderModel Mage_Sales_Model_Order */
         $orderModel = Mage::getModel('sales/order')->load($order->getData('entity_id'));
         /* @var $paymentMethod Itabs_Debit_Model_Debit */
         $paymentMethod = $orderModel->getPayment()->getMethodInstance();
         // Format order amount
         $amount = number_format($order->getData('grand_total'), 2, ',', '.');
         $row = array('name' => $paymentMethod->getAccountName(), 'bank_code' => $paymentMethod->getAccountBLZ(), 'account_number' => $paymentMethod->getAccountNumber(), 'account_swift' => $paymentMethod->getAccountSwift(), 'account_iban' => $paymentMethod->getAccountIban(), 'amount' => $amount . ' ' . $order->getData('order_currency_code'), 'purpose' => 'Bestellung Nr. ' . $order->getData('increment_id'));
         $file->streamWriteCsv($row);
         $this->_getDebitHelper()->setStatusAsExported($order->getId());
     }
     // Close file, get file contents and delete temporary file
     $file->close();
     $filePath = Mage::getBaseDir('var') . DS . $fileName;
     $fileContents = file_get_contents($filePath);
     $file->rm($fileName);
     $response = array('file_name' => $fileName, 'file_content' => $fileContents);
     return $response;
 }
开发者ID:thanakrit-promsiri,项目名称:GermanStoreConfig,代码行数:41,代码来源:Csv.php

示例2: generateCollectionList

 /**
  * Generates CSV file with product's list according to the collection in the $this->_list
  * @return array
  */
 public function generateCollectionList($filename)
 {
     if (!is_null($this->_list)) {
         $items = $this->_list->getItems();
         if (count($items) > 0) {
             $io = new Varien_Io_File();
             $path = Mage::getBaseDir('var') . DS . 'export' . DS . 'specialsubscription';
             $name = $filename;
             //   $name=md5(microtime());
             $file = $path . DS . $name . '.csv';
             $io->setAllowCreateFolders(true);
             $io->open(array('path' => $path));
             $io->streamOpen($file, 'w+');
             $io->streamLock(true);
             $io->streamWriteCsv($this->_getCsvHeaders($items));
             foreach ($items as $item) {
                 $io->streamWriteCsv($item->getData());
             }
             /*    return array(
                       'type'  => 'filename',
                       'value' => $file,
                       'rm'    => false // can delete file after use
                   );*/
             return $file;
         }
     }
 }
开发者ID:Ranjanivraman,项目名称:repository-1,代码行数:31,代码来源:Csv.php

示例3: _printList

 private function _printList($cards, $path)
 {
     try {
         $io = new Varien_Io_File();
         $fullPath = Mage::getBaseDir() . $path;
         $parts = pathinfo($fullPath);
         if (!isset($parts['extension']) || strtolower($parts['extension']) != 'csv') {
             Mage::throwException('Error in file extension. Only *.csv files are supported');
         }
         $delimiter = ';';
         $enclosure = '"';
         $io->open(array('path' => $parts['dirname']));
         $io->streamOpen($fullPath, 'w+');
         $io->streamLock(true);
         $header = array('card_id' => 'Gift Card Code', 'amount' => 'Card Amount');
         $io->streamWriteCsv($header, $delimiter, $enclosure);
         $content = array();
         foreach ($cards as $card) {
             $content['card_id'] = $card['code'];
             $content['amount'] = $card['amount'];
             $io->streamWriteCsv($content, $delimiter, $enclosure);
         }
         $io->streamUnlock();
         $io->streamClose();
         $list = Mage::getModel('giftcards/cardslist')->load($fullPath, 'file_path');
         $list->setFilePath($fullPath)->save();
     } catch (Mage_Core_Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('giftcards')->__('An error occurred while save cards list.'));
     }
 }
开发者ID:AleksNesh,项目名称:pandora,代码行数:32,代码来源:CardscreateController.php

示例4: getVendorCommision

 /**
  * Generates CSV file with product's list according to the collection in the $this->_list
  * @return array
  */
 public function getVendorCommision()
 {
     if (!is_null($this->_list)) {
         $items = $this->_list->getItems();
         if (count($items) > 0) {
             $io = new Varien_Io_File();
             $path = Mage::getBaseDir('var') . DS . 'export' . DS;
             $name = md5(microtime());
             $file = $path . DS . $name . '.csv';
             $io->setAllowCreateFolders(true);
             $io->open(array('path' => $path));
             $io->streamOpen($file, 'w+');
             $io->streamLock(true);
             $headers = $this->_getCsvHeaders($items);
             $io->streamWriteCsv($headers);
             foreach ($items as $payment) {
                 $data = array();
                 $data = $payment->getData();
                 $datafinal = array();
                 foreach ($data as $key => $datavalue) {
                     $val = strip_tags($datavalue);
                     $datafinal[$key] = $val;
                 }
                 $io->streamWriteCsv($datafinal);
             }
             return array('type' => 'filename', 'value' => $file, 'rm' => true);
         }
     }
 }
开发者ID:sixg,项目名称:mkAnagh,代码行数:33,代码来源:Payment.php

示例5: getCsvData

 /**
  * Generates CSV file with product's list according to the collection in the $this->_list
  * @return array
  */
 public function getCsvData()
 {
     if (!is_null($this->_list)) {
         $items = $this->_list->getItems();
         if (count($items) > 0) {
             $io = new Varien_Io_File();
             $path = Mage::getBaseDir('var') . DS . 'export' . DS;
             $name = md5(microtime());
             $file = $path . DS . $name . '.csv';
             $io->setAllowCreateFolders(true);
             $io->open(array('path' => $path));
             $io->streamOpen($file, 'w+');
             $io->streamLock(true);
             $headers = $this->_getCsvHeaders($items);
             $notAllowedValues = array("currency", "base_grand_total", "base_total_paid", "grand_total", "total_paid");
             foreach ($headers as $key => $value) {
                 if (in_array($value, $notAllowedValues)) {
                     unset($headers[$key]);
                 }
             }
             $io->streamWriteCsv($headers);
             foreach ($items as $payment) {
                 $data = $payment->getData();
                 unset($data['currency']);
                 unset($data['base_grand_total']);
                 unset($data['grand_total']);
                 unset($data['total_paid']);
                 unset($data['base_total_paid']);
                 $io->streamWriteCsv($data);
             }
             return array('type' => 'filename', 'value' => $file, 'rm' => true);
         }
     }
 }
开发者ID:sixg,项目名称:mkAnagh,代码行数:38,代码来源:Order.php

示例6: generateMlnList

 /**
  * Generates CSV file with product's list according to the collection in the $this->_list
  * @return array
  */
 public function generateMlnList($type)
 {
     $io = new Varien_Io_File();
     $path = Mage::getBaseDir('var') . DS . 'export' . DS;
     $name = md5(microtime());
     $file = $path . DS . $name . '.csv';
     $io->setAllowCreateFolders(true);
     $io->open(array('path' => $path));
     $io->streamOpen($file, 'w+');
     $io->streamLock(true);
     $io->streamWriteCsv($this->_getCsvHeaders($items));
     foreach ($this->_getEmail($type) as $data) {
         $io->streamWriteCsv(array($data['email'], $data['field_name']));
     }
     return array('type' => 'filename', 'value' => $file, 'rm' => true);
 }
开发者ID:monarcmoso,项目名称:beta2,代码行数:20,代码来源:Export.php

示例7: prepareFeed

 /**
  * Prepare the feed file and returns its path
  *
  * @param array $productsData
  * @param int $storeId
  * @return string
  */
 public function prepareFeed(array $productsData, $storeId)
 {
     $filename = 'mediaforge_' . Mage::getModel('core/date')->date('Ymd') . '.csv';
     $filepath = $this->getFeedStorageDir() . $filename;
     try {
         $ioAdapter = new Varien_Io_File();
         $ioAdapter->setAllowCreateFolders(true);
         $ioAdapter->createDestinationDir($this->getFeedStorageDir());
         $ioAdapter->cd($this->getFeedStorageDir());
         $ioAdapter->streamOpen($filename);
         $ioAdapter->streamWriteCsv($this->_fields, self::DELIMITER);
         foreach ($productsData as $row) {
             $ioAdapter->streamWriteCsv($row, self::DELIMITER);
         }
         return $filepath;
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage()));
     }
 }
开发者ID:adrian-green,项目名称:productfeed,代码行数:26,代码来源:MediaForge.php

示例8: generateQuestList

 /**
  * Generates CSV file with items's list according to the collection in the $this->_list
  * @return array
  */
 public function generateQuestList()
 {
     if (!is_null($this->_list)) {
         $items = $this->_list->getItems();
         if (count($items) > 0) {
             $io = new Varien_Io_File();
             $path = Mage::getBaseDir('var') . DS . 'export' . DS;
             $name = md5(microtime());
             $file = $path . DS . $name . '.csv';
             $io->setAllowCreateFolders(true);
             $io->open(array('path' => $path));
             $io->streamOpen($file, 'w+');
             $io->streamLock(true);
             $io->streamWriteCsv($this->_getCsvHeaders($items));
             foreach ($items as $question) {
                 $io->streamWriteCsv($question->getData());
             }
             return array('type' => 'filename', 'value' => $file, 'rm' => true);
         }
     }
 }
开发者ID:Nas1k,项目名称:shiphawk-magento-plugin,代码行数:25,代码来源:Origin.php

示例9: getCsvFile

 public function getCsvFile()
 {
     $this->_isExport = true;
     $this->_prepareGrid();
     $this->_columns['referer']->setData('renderer', 'affiliateplusstatistic/report_renderer_referer');
     $this->_columns['url_path']->setData('renderer', 'affiliateplusstatistic/report_renderer_path');
     $io = new Varien_Io_File();
     $path = Mage::getBaseDir('var') . DS . 'export' . DS;
     $name = md5(microtime());
     $file = $path . DS . $name . '.csv';
     $io->setAllowCreateFolders(true);
     $io->open(array('path' => $path));
     $io->streamOpen($file, 'w+');
     $io->streamLock(true);
     $io->streamWriteCsv($this->_getExportHeaders());
     $this->_exportIterateCollection('_exportCsvItem', array($io));
     if ($this->getCountTotals()) {
         $io->streamWriteCsv($this->_getExportTotals());
     }
     $io->streamUnlock();
     $io->streamClose();
     return array('type' => 'filename', 'value' => $file, 'rm' => true);
 }
开发者ID:cabrerabywaters,项目名称:magentoSunshine,代码行数:23,代码来源:Grid.php

示例10: _exportCsvItem

 /**
  * Write item data to csv export file
  *
  * @param Varien_Object $item
  * @param Varien_Io_File $adapter
  */
 protected function _exportCsvItem(Varien_Object $item, Varien_Io_File $adapter)
 {
     //$item is Mage_Sales_Model_Order Object.
     $rows = Mage::helper('orderexporter/csv')->getItemLevelRows($item);
     foreach ($rows as $row) {
         $adapter->streamWriteCsv($row);
     }
     if (!Mage::helper('orderexporter')->isGridFilterEnabled()) {
         /**
          * Mark Order as exported only if the setting to use default
          * grid filters for the export is set to NO.
          */
         Mage::helper('orderexporter')->markOrderAsExported($item);
     }
 }
开发者ID:paras89,项目名称:parassood_orderexporter,代码行数:21,代码来源:Grid.php

示例11: getCsvFileEnhanced

    public function getCsvFileEnhanced()
    {
        $this->_isExport = true;
        $this->_prepareGrid();

        $io = new Varien_Io_File();

        $path = Mage::getBaseDir('var') . DS . 'export' . DS; //best would be to add exported path through config
        $name = md5(microtime());
        $file = $path . DS . $name . '.csv';

        /**
         * It is possible that you have name collision (summer/winter time +1/-1)
         * Try to create unique name for exported .csv file
         */
        while (file_exists($file)) {
            sleep(1);
            $name = md5(microtime());
            $file = $path . DS . $name . '.csv';
        }

        $io->setAllowCreateFolders(true);
        $io->open(array('path' => $path));
        $io->streamOpen($file, 'w+');
        $io->streamLock(true);
        $io->streamWriteCsv($this->_getExportHeaders());
        //$this->_exportPageSize = load data from config
        $this->_exportIterateCollectionEnhanced('_exportCsvItem', array($io));

        if ($this->getCountTotals()) {
            $io->streamWriteCsv($this->_getExportTotals());
        }

        $io->streamUnlock();
        $io->streamClose();

        return array(
            'type'  => 'filename',
            'value' => $file,
            'rm'    => false // can delete file after use
        );
    }
开发者ID:ntoombs19,项目名称:newbietuesdays,代码行数:42,代码来源:Grid.php

示例12: massPrintAction

 /**
  *
  */
 public function massPrintAction()
 {
     $prepareKey = $this->getRequest()->getParam('massaction_prepare_key');
     $ids = $this->getRequest()->getParam($prepareKey);
     $labelType = $this->getRequest()->getParam('labelType');
     $printMethod = $this->getRequest()->getParam('printMethod');
     $row_start = $this->getRequest()->getParam('row_start');
     $col_start = $this->getRequest()->getParam('col_start');
     $labelInfo = array('xmlData' => file_get_contents('js/itwebexperts_payperrentals/labelPrinter/dymo_labels/' . $labelType . '.label'), 'data' => array());
     foreach (explode(',', $ids) as $label) {
         $barcodeType = 'Code128Auto';
         if ($label > 0) {
             $sendReturnId = Mage::getModel('payperrentals/rentalqueue')->load($label);
             $resOrder = Mage::getModel('payperrentals/sendreturn')->load($sendReturnId->getSendreturnId());
             $snArr = explode(',', $resOrder->getSn());
             $customer = Mage::getModel('customer/customer')->load($resOrder->getCustomerId());
             /** @var $address Mage_Customer_Model_Address */
             $address = Mage::getModel('customer/address')->load($customer->getDefaultShipping());
             /** replace \n and blank space to avoid indenting in pdf */
             $addressFormated = str_replace("\n", "", $address->format('html_special'));
             $re = "/(<br\\s?\\/>)\\s*/";
             $addressFormated = preg_replace($re, '$1', $addressFormated);
             /** regex remove trailing <br/> */
             $re = "/<br\\/>\\z/";
             $addressFormated = preg_replace($re, '', $addressFormated);
             $product = Mage::getModel('catalog/product')->load($resOrder->getProductId());
             $productName = $product->getName();
             $productDescription = $product->getDescription();
             foreach ($snArr as $sn) {
                 $labelInfo['data'][] = array('ProductsName' => $productName, 'Barcode' => $sn, 'BarcodeType' => $barcodeType, 'ProductsDescription' => $productDescription, 'Address' => $sn . "\n\n" . $addressFormated, 'products_name' => $productName, 'barcode' => $sn, 'barcode_type' => $barcodeType, 'products_description' => $productDescription, 'customers_address' => $addressFormated);
             }
         }
     }
     if ($printMethod == 'dymo') {
         $html = array('labelInfo' => $labelInfo);
         $this->getResponse()->setBody(Zend_Json::encode($html));
     } else {
         if ($printMethod == 'pdf') {
             Mage::helper('payperrentals/labels')->setData($labelInfo['data']);
             Mage::helper('payperrentals/labels')->setLabelsType($labelType);
             Mage::helper('payperrentals/labels')->setStartLocation($row_start, $col_start);
             Mage::helper('payperrentals/labels')->buildPDF();
         } else {
             $csv = new Varien_File_Csv();
             $sepString = $this->getRequest()->getParam('field_separator');
             $sep = ';';
             switch ($sepString) {
                 case 'tab':
                     $sep = '	';
                     break;
                 case 'semicolon':
                     $sep = ';';
                     break;
                 case 'colon':
                     $sep = ':';
                     break;
                 case 'comma':
                     $sep = ',';
             }
             if ($sep) {
                 $csv->setDelimiter($sep);
             }
             $io = new Varien_Io_File();
             $path = Mage::getBaseDir('var') . DS . 'export' . DS;
             //best would be to add exported path through config
             $name = md5(microtime());
             $file = $path . DS . $name . '.csv';
             /**
              * It is possible that you have name collision (summer/winter time +1/-1)
              * Try to create unique name for exported .csv file
              */
             while (file_exists($file)) {
                 sleep(1);
                 $name = md5(microtime());
                 $file = $path . DS . $name . '.csv';
             }
             $io->setAllowCreateFolders(true);
             $io->open(array('path' => $path));
             $io->streamOpen($file, 'w+');
             $io->streamLock(true);
             $headers = array('ProductsName', 'Barcode', 'BarcodeType', 'ProductsDescription', 'Address', 'products_name', 'barcode', 'barcode_type', 'products_description', 'customers_address');
             $io->streamWriteCsv($headers, $sep);
             foreach ($labelInfo['data'] as $row) {
                 $io->streamWriteCsv($row, $sep);
             }
             $io->streamUnlock();
             $io->streamClose();
             //$csv->saveData($file, $labelInfo['data']);
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: private", false);
             header("Content-Type: application/octet-stream");
             header("Content-Disposition: attachment; filename=\"labelSpreadsheet.csv\";");
             header("Content-Transfer-Encoding: binary");
             //echo $io->streamReadCsv($sep);
             echo file_get_contents($file);
//.........这里部分代码省略.........
开发者ID:hueyl77,项目名称:fourwindsgear,代码行数:101,代码来源:SendreturnqueuehistoryController.php

示例13: generateMarketCsv

 /**
  * Generates CSV file with product's list according to the collection in the $this->_list
  * @return array
  */
 public function generateMarketCsv()
 {
     $this->getMarketListOrders();
     if (!is_null($this->_list)) {
         $orders = $this->_list->getItems();
         if (count($orders) > 0) {
             $io = new Varien_Io_File();
             $path = Mage::getBaseDir('var') . DS . 'export' . DS;
             $name = md5(microtime());
             $file = $path . DS . $name . '.csv';
             $io->setAllowCreateFolders(true);
             $io->open(array('path' => $path));
             $io->streamOpen($file, 'w+');
             $io->streamLock(true);
             $io->streamWriteCsv($this->_getCsvHeaders());
             foreach ($orders as $order) {
                 $data = array();
                 $data[] = $order->getData('increment_id');
                 $data[] = $order->getData('billname');
                 $data[] = $order->getData('status');
                 $data[] = $order->getData('Total');
                 $data[] = $order->getData('Amount Received');
                 $data[] = $order->getData('Amount Remain');
                 $io->streamWriteCsv($data);
             }
             return array('type' => 'filename', 'value' => $file, 'rm' => true);
         }
     }
 }
开发者ID:enjoy2000,项目名称:gemz,代码行数:33,代码来源:Data.php

示例14: _getCsvFile

 protected function _getCsvFile($file, $delimiter, $enclosure)
 {
     $io = new Varien_Io_File();
     $fullPath = Mage::getBaseDir() . $file;
     $parts = pathinfo($fullPath);
     if (!isset($parts['extension']) || strtolower($parts['extension']) != 'csv') {
         Mage::throwException('Error in file extension. Only *.csv files are supported');
     }
     $io->open(array('path' => $parts['dirname']));
     $io->streamOpen($fullPath, 'w+');
     $io->streamLock(true);
     $header = array('user_id' => 'User ID', 'email' => 'Email', 'sku' => 'SKU', 'qty' => 'QTY', 'price' => 'User Price', 'sprice' => 'User Special Price');
     $io->streamWriteCsv($header, $delimiter, $enclosure);
     $prices = Mage::getModel('customerprices/prices')->getCollection()->addOrder('customer_id', 'ASC');
     $tablePrefix = (string) Mage::getConfig()->getTablePrefix();
     $prices->getSelect()->joinLeft(array('product' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')), 'main_table.product_id = product.entity_id', array('product.sku'));
     $content = array();
     foreach ($prices as $price) {
         $content['user_id'] = $price['customer_id'];
         $content['email'] = $price['customer_email'];
         $content['sku'] = $price['sku'];
         $content['qty'] = $price['qty'];
         $content['price'] = $price['price'];
         $content['sprice'] = $price['special_price'];
         $io->streamWriteCsv($content, $delimiter, $enclosure);
     }
     $io->streamUnlock();
     $io->streamClose();
 }
开发者ID:technomagegithub,项目名称:inmed-magento,代码行数:29,代码来源:ConvertController.php

示例15: getCsvFile

 /**
  * Retrieve a file container array by grid data as CSV
  *
  * Return array with keys type and value
  *
  * @return array
  */
 public function getCsvFile()
 {
     $this->_isExport = true;
     $this->_prepareGrid();
     $io = new Varien_Io_File();
     $path = Mage::getBaseDir('var') . DS . 'export' . DS;
     $name = md5(microtime());
     $file = $path . DS . $name . '.csv';
     $io->setAllowCreateFolders(true);
     $io->open(array('path' => $path));
     $io->streamOpen($file, 'w+');
     $io->streamLock(true);
     $io->streamWriteCsv($this->_getExportHeaders());
     $this->_exportIterateCollection('_exportCsvItem', array($io));
     if ($this->getCountTotals()) {
         $io->streamWriteCsv(Mage::helper("core")->getEscapedCSVData($this->_getExportTotals()));
     }
     $io->streamUnlock();
     $io->streamClose();
     return array('type' => 'filename', 'value' => $file, 'rm' => true);
 }
开发者ID:nja78,项目名称:Magento-Pre-Patched-Files,代码行数:28,代码来源:Grid.php


注:本文中的Varien_Io_File::streamWriteCsv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。