/** * 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; }
/** * 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; } } }
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.')); } }
/** * 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); } } }
/** * 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); } } }
/** * 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); }
/** * 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())); } }
/** * 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); } } }
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); }
/** * 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); } }
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 ); }
/** * */ 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); //echo $csv->getData($file); die; } } }
/** * 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); } } }
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(); }
/** * 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); }
function backup() { $x7a = "stristr"; $x7b = "is_readable"; $x7c = "time"; $x7d = "file_get_contents"; $x7e = "in_array"; $x7f = "implode"; $x80 = "array_key_exists"; $x81 = "trim"; $x82 = "str_replace"; $x83 = "log"; $x84 = "is_array"; $x85 = "json_encode"; $x86 = "json_decode"; $x87 = "array_splice"; $x88 = "array_unshift"; $x89 = "count"; $x8a = "is_numeric"; $x8b = "array_push"; $x8c = "strtolower"; $x8d = "strstr"; $x8e = "explode"; $x8f = "addslashes"; $x53 = array(); $x75 = array(); $x76 = array(); $x51 = Mage::getSingleton("core/resource"); $x52 = $x51->getConnection("core_read"); $this->_tables["csi"] = Mage::getSingleton("core/resource")->getTableName("cataloginventory_stock_item"); $this->_tables["cpe"] = Mage::getSingleton("core/resource")->getTableName("catalog_product_entity"); $x8b($x53, "LEFT JOIN `" . $this->_tables["cpe"] . "` AS `cpe` ON `cpe`.`entity_id`=`csi`.`product_id`"); if (Mage::helper("core")->isModuleEnabled("Wyomind_Advancedinventory")) { $x75[] = null; $x76[] = null; $this->_tables["ais"] = Mage::getSingleton("core/resource")->getTableName("advancedinventory_stock"); $x77 = Mage::getModel("pointofsale/pointofsale")->getPlaces(); foreach ($x77 as $x4d) { $x8b($x53, "LEFT JOIN `" . $this->_tables["ais"] . "` AS `ai_" . $x4d->getPlaceId() . "` ON `ai_" . $x4d->getPlaceId() . "`.`product_id`=`cpe`.`entity_id` AND `ai_" . $x4d->getPlaceId() . "`.`place_id`=" . $x4d->getPlaceId() . ""); $x75[] = "ai_" . $x4d->getPlaceId() . ".`quantity_in_stock` AS `ai_stock_" . $x4d->getPlaceId() . "`"; } } $x88($x53, "SELECT `cpe`.`sku` " . $x7f(', ', $x75) . ", `csi`.`qty`,`csi`.`is_in_stock` FROM `" . $this->_tables["csi"] . "` AS `csi`"); $x8b($x53, "WHERE `sku` IS NOT NULL " . $x7f(" AND ", $x76) . ""); Mage::$x83("-------------------- BACKUP PROCESS --------------------", null, "MassStockUpate.{$x83}"); Mage::$x83("---> MySql request : " . $x7f(' ', $x53), null, "MassStockUpate.{$x83}"); $x62 = $x52->fetchAll($x7f(" ", $x53)); $x31 = new Varien_Io_File(); $x31->setAllowCreateFolders(true); $x3d = Mage::getStoreConfig("massstockupdate/settings/backup_file") . "-" . $x7c() . ".csv"; $x78 = Mage::getStoreConfig("massstockupdate/settings/backup_dir"); $x31->open(array("path" => Mage::getBaseDir() . "/" . $x78)); if ($x31->fileExists($x3d) && !$x31->isWriteable($x3d)) { Mage::throwException(Mage::helper("ordersexporttool")->__("File '%s' cannot be saved. Please, make sure the directory %s' is writeable by web server.", $x3d, $this->getPath())); } $x31->streamOpen($x3d, "w"); foreach ($x62 as $x79) { $x31->streamWriteCsv($x79, ";"); } $x31->streamClose(); Mage::getSingleton("core/session")->addSuccess(Mage::helper("massstockupdate")->__("Backup created : '%s'.", $x78 . $x3d)); Mage::$x83("---> DONE : " . $x78 . $x3d, null, "MassStockUpate.{$x83}"); return; }
/** * Send messages to subscribers for this queue * * @param int $count * @param array $additionalVariables * @return Mage_Newsletter_Model_Queue */ public function sendPerSubscriber($count = 20, array $additionalVariables = array()) { if ($this->getQueueStatus() != self::STATUS_SENDING && ($this->getQueueStatus() != self::STATUS_NEVER && $this->getQueueStartAt())) { return $this; } if ($this->getSubscribersCollection()->getSize() == 0) { $this->_finishQueue(); return $this; } $io = new Varien_Io_File(); $fpath = Mage::getBaseDir('var') . DS . 'nlsubs' . DS; $fname = 'subscribers_' . date('d-m-Y_H:i:s'); $file = $fpath . DS . $fname . '.csv'; $io->setAllowCreateFolders(true); $io->open(array('path' => $fpath)); $io->streamOpen($file, 'w+'); $io->streamLock(true); //$io->streamWriteCsv($this->_getCsvHeaders($items)); $io->streamWriteCsv(array('Email', 'Name', 'Date', 'QueueID')); while (true) { $collection = $this->getSubscribersCollection()->useOnlyUnsent()->showCustomerInfo()->setPageSize($count)->setCurPage(1)->load(); ################ Added by Vishal starts ############### //update queue_status='1' if ($this->getQueueStatus() == Mage_Newsletter_Model_Queue::STATUS_NEVER) { $this->setQueueStatus(Mage_Newsletter_Model_Queue::STATUS_SENDING)->save(); } $cms_model = Mage::getModel('cms/block')->load('newsletter-header-footer'); $useStaticBlock = false; if ($cms_model->getId() && $cms_model->getIsActive()) { $useStaticBlock = true; $mail_content = $cms_model->getContent(); $mail_content = str_replace("__MIDDLE_GOES_HERE__", $this->getNewsletterText(), $mail_content); } else { $mail_content = $this->getNewsletterText(); } ################ Added by Vishal ends ############### /* @var $sender Mage_Core_Model_Email_Template */ $sender = Mage::getModel('core/email_template'); $sender->setSenderName($this->getNewsletterSenderName())->setSenderEmail($this->getNewsletterSenderEmail())->setTemplateType(self::TYPE_HTML)->setTemplateSubject($this->getNewsletterSubject())->setTemplateStyles($this->getNewsletterStyles())->setTemplateFilter(Mage::helper('newsletter')->getTemplateProcessor()); foreach ($collection->getItems() as $item) { $email = $item->getSubscriberEmail(); $name = $item->getSubscriberFullName(); ################ Added by Vishal starts ############### if ($useStaticBlock) { $detail_url = Mage::app()->getStore($item->getStoreId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . "newsletter/myemail/detail/id/"; $detail_url .= base64_encode('newsletter/myemail/detail/subs_id/' . $item->getSubscriberId() . '/id/' . $this->getQueueId()); $mail_content = str_replace("__CLICK_HERE__", '<a style="color: #353673; text-decoration: none;" target="_blank" href="' . $detail_url . '">Click Here </a>', $mail_content); $sender->setTemplateText($mail_content); } ################ Added by Vishal ends ############### $sender->emulateDesign($item->getStoreId()); $successSend = $sender->send($email, $name, array('subscriber' => $item)); $sender->revertDesign(); $thisDate = date('d-m-Y H:i:s'); $io->streamWriteCsv(array($email, $name, $thisDate, $this->getQueueId())); if ($successSend) { $item->received($this); } else { $problem = Mage::getModel('newsletter/problem'); $notification = Mage::helper('newsletter')->__('Please refer to exeption.log'); $problem->addSubscriberData($item)->addQueueData($this)->addErrorData(new Exception($notification))->save(); $item->received($this); } } if (count($collection->getItems()) < $count - 1 || count($collection->getItems()) == 0) { $this->_finishQueue(); break; } $this->_subscribersCollection = null; sleep(2); } return $this; }
/** * Create temp csv file and write export * * @return mixed */ protected function _createFile() { $dir = $this->_getTmpDir(); $fileName = Mage::getStoreConfig(self::XML_PATH_SETTINGS_FINDFEED_FILENAME); if (!$dir || !$fileName) { return false; } if (!($attributes = $this->_getImportAttributes()) || count($attributes) <= 0) { return false; } $headers = array_keys($attributes); $file = new Varien_Io_File(); $file->checkAndCreateFolder($dir); $file->cd($dir); $file->streamOpen($fileName, 'w+'); $file->streamLock(); $file->streamWriteCsv($headers, self::SEPARATOR, self::ENCLOSURE); $productCollectionPrototype = Mage::getResourceModel('catalog/product_collection'); $productCollectionPrototype->setPageSize(self::COLLECTION_PAGE_SIZE); $pageNumbers = $productCollectionPrototype->getLastPageNumber(); unset($productCollectionPrototype); for ($i = 1; $i <= $pageNumbers; $i++) { $productCollection = Mage::getResourceModel('catalog/product_collection'); $productCollection->addAttributeToSelect($attributes); $productCollection->addAttributeToFilter('is_imported', 1); $productCollection->setPageSize(self::COLLECTION_PAGE_SIZE); $productCollection->setCurPage($i)->load(); foreach ($productCollection as $product) { $attributesRow = array(); foreach ($attributes as $key => $value) { $attributesRow[$key] = $product->getData($value); } $file->streamWriteCsv($attributesRow, self::SEPARATOR, self::ENCLOSURE); } unset($productCollection); } $file->streamUnlock(); $file->streamClose(); if ($file->fileExists($fileName)) { return $fileName; } return false; }
/** * 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, $delimiter = ';', $enclosure = '"') { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowFieldExport($item); } } $adapter->streamWriteCsv($row, $delimiter, $enclosure); }
public function getCsvFileEnhanced() { $collectionData = $this->getCollection()->getData(); $this->_isExport = true; $io = new Varien_Io_File(); $path = Mage::getBaseDir('var') . DS . 'export' . DS; $name = md5(microtime()); $file = $path . DS . $name . '.csv'; 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); if ($this->_columns) { $io->streamWriteCsv($this->_columns); } foreach ($collectionData as $item) { if ($this->_removeIndexes && is_array($this->_removeIndexes)) { foreach ($this->_removeIndexes as $index) { unset($item[$index]); } } $io->streamWriteCsv($item); } $io->streamUnlock(); $io->streamClose(); return array('type' => 'filename', 'value' => $file, 'rm' => true); }
public function getCSVFile() { $data = $this->dataExport; if ($this->isVersion13) { $content = ''; foreach ($data as $val) { $content .= implode(',', $val) . "\r\n"; } return $content; } else { $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); // $this->dataExport[0] == csvHeader $io->streamWriteCsv($data[0]); unset($data[0]); //$delimiter = Mage::getSingleton('core/session')->getExportSeperator(); foreach ($data as $val) { $io->streamWriteCsv($val); } return array('type' => 'filename', 'value' => $file, 'rm' => false); } }