public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         $file_path = Mage::getBaseDir() . '/media/enquiryform/' . str_replace(' ', "_", $data['name']) . '_' . date("d_m_Y_H_i_s") . '.csv';
         $mage_csv = new Varien_File_Csv();
         $mage_csv->saveData($file_path, $data);
         exit;
         $model = Mage::getModel('eventmanager/eventmanagercustom');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                 $model->setCreatedTime(now())->setUpdateTime(now());
             } else {
                 $model->setUpdateTime(now());
             }
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('eventmanager')->__('Custom event request was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(false);
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', array('id' => $model->getId()));
                 return;
             }
             $this->_redirect('*/*/');
             return;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('eventmanager')->__('Unable to find the request to save'));
     $this->_redirect('*/*/');
 }
 public function exportAction()
 {
     $file = 'example.csv';
     $csv = new Varien_File_Csv();
     $csvdata = array();
     $csvdata[] = array('id' => 'Id', 'website_id' => 'Website Id', 'dest_country_id' => 'Destination Country Id', 'zip_code' => 'Zip Code');
     $codZipcodes = Mage::getModel('cod/postcode')->getCollection();
     foreach ($codZipcodes as $codZipcode) {
         $cod_data = array();
         $cod_data['id'] = $codZipcode->getPk();
         $cod_data['website_id'] = $codZipcode->getWebsiteId();
         $cod_data['dest_country_id'] = $codZipcode->getDestCountryId();
         $cod_data['zip_code'] = $codZipcode->getDestZip();
         $csvdata[] = $cod_data;
     }
     $csv->saveData($file, $csvdata);
     $this->_prepareDownloadResponse($file, array('type' => 'filename', 'value' => $file));
 }
示例#3
0
 public function exportordersAction()
 {
     //DebugBreak();
     $file_path = Mage::getBaseDir() . '/var/export/sales_order_export.csv';
     $mage_csv = new Varien_File_Csv();
     $information_row = array();
     $area_name = $this->getRequest()->getParam('area-name');
     $from_date = $this->getRequest()->getParam('from-date');
     $to_date = $this->getRequest()->getParam('to-date');
     $data[0]['area'] = 'Area';
     $data[0]['date'] = 'Date';
     $data[0]['count'] = 'Total Orders';
     $data[0]['subtotal'] = 'Subtotal';
     $data[0]['invoiced'] = 'Invoiced';
     $data[0]['refunded'] = 'Refunded';
     $data[0]['tax_amount'] = 'Tax amount';
     $data[0]['shipping_amount'] = 'Shipping Amount';
     $data[0]['discounts'] = 'Discounts';
     $data[0]['cancelled'] = 'Cancelled';
     if ($area_name == "All Areas") {
         //DebugBreak();
         $collection = Mage::getModel('pincode/pincode')->getCollection();
         $i = 1;
         foreach ($collection as $collection_area) {
             $area_names[] = $collection_area->getData('area_name');
         }
         foreach ($area_names as $area_name) {
             $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
             $read = Mage::getSingleton('core/resource')->getConnection('core_read');
             $sql1 = "SELECT pin_code FROM pincode where area_name='" . $area_name . "'";
             $res = $read->fetchRow($sql1);
             $pincode = $res['pin_code'];
             $sql2 = "SELECT count(postcode),email FROM sales_flat_order_address where postcode in ('" . $pincode . "') and address_type='billing' group by sales_flat_order_address.postcode";
             $res1 = $read->fetchRow($sql2);
             $sql3 = "select count(sales_flat_order_address.postcode),sum(sales_flat_order.subtotal),sum(sales_flat_order.base_subtotal_invoiced),sum(sales_flat_order.subtotal_refunded),sum(sales_flat_order.base_shipping_tax_amount),sum(sales_flat_order.shipping_amount),sum(sales_flat_order.discount_amount),sum(sales_flat_order.subtotal_canceled),date(sales_flat_order.created_at) from sales_flat_order,sales_flat_order_address where sales_flat_order_address.parent_id = sales_flat_order.entity_id and sales_flat_order_address.postcode in ('" . $pincode . "')and sales_flat_order_address.address_type='billing' and date(sales_flat_order.created_at) between '" . $from_date . "' and '" . $to_date . "' group by sales_flat_order_address.postcode,date(sales_flat_order.created_at)";
             $ress2 = $read->fetchAll($sql3);
             foreach ($ress2 as $res2) {
                 //DebugBreak();
                 $data[$i]['area'] = $area_name;
                 $data[$i]['date'] = $res2['date(sales_flat_order.created_at)'];
                 $data[$i]['count'] = $res2['count(sales_flat_order_address.postcode)'];
                 $data[$i]['subtotal'] = $res2['sum(sales_flat_order.subtotal)'];
                 $data[$i]['invoiced'] = $res2['sum(sales_flat_order.base_subtotal_invoiced)'];
                 $data[$i]['refunded'] = $res2['sum(sales_flat_order.subtotal_refunded)'];
                 $data[$i]['tax_amount'] = $res2['sum(sales_flat_order.base_shipping_tax_amount)'];
                 $data[$i]['shipping_amount'] = $res2['sum(sales_flat_order.shipping_amount)'];
                 $data[$i]['discounts'] = $res2['sum(sales_flat_order.discount_amount)'];
                 $data[$i]['cancelled'] = $res2['sum(sales_flat_order.subtotal_canceled)'];
                 $orders_placed[] = $res2['count(sales_flat_order_address.postcode)'];
                 $subtotal[] = $res2['sum(sales_flat_order.subtotal)'];
                 $base_subtotal_invoiced[] = $res2['sum(sales_flat_order.base_subtotal_invoiced)'];
                 $subtotal_refunded[] = $res2['sum(sales_flat_order.subtotal_refunded)'];
                 $base_shipping_tax_amount[] = $res2['sum(sales_flat_order.base_shipping_tax_amount)'];
                 $shipping_amount[] = $res2['sum(sales_flat_order.shipping_amount)'];
                 $discount_amount[] = $res2['sum(sales_flat_order.discount_amount)'];
                 $subtotal_canceled[] = $res2['sum(sales_flat_order.subtotal_canceled)'];
                 $i++;
             }
             $data[$i]['area'] = 'Total';
             $data[$i]['date'] = ' ';
             $data[$i]['count'] = array_sum($orders_placed);
             $data[$i]['subtotal'] = array_sum($subtotal);
             $data[$i]['invoiced'] = array_sum($base_subtotal_invoiced);
             $data[$i]['refunded'] = array_sum($subtotal_refunded);
             $data[$i]['tax_amount'] = array_sum($base_shipping_tax_amount);
             $data[$i]['shipping_amount'] = array_sum($shipping_amount);
             $data[$i]['discounts'] = array_sum($discount_amount);
             $data[$i]['cancelled'] = array_sum($subtotal_canceled);
         }
         foreach ($data as $val) {
             $information_row[] = $val;
         }
     } else {
         $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
         $read = Mage::getSingleton('core/resource')->getConnection('core_read');
         $sql1 = "SELECT pin_code FROM pincode where area_name='" . $area_name . "'";
         $res = $read->fetchRow($sql1);
         $pincode = $res['pin_code'];
         $sql2 = "SELECT count(postcode),email FROM sales_flat_order_address where postcode in (" . $pincode . ") and address_type='billing' group by sales_flat_order_address.postcode";
         $res1 = $read->fetchRow($sql2);
         $sql3 = "select count(sales_flat_order_address.postcode),sum(sales_flat_order.subtotal),sum(sales_flat_order.base_subtotal_invoiced),sum(sales_flat_order.subtotal_refunded),sum(sales_flat_order.base_shipping_tax_amount),sum(sales_flat_order.shipping_amount),sum(sales_flat_order.discount_amount),sum(sales_flat_order.subtotal_canceled),date(sales_flat_order.created_at) from sales_flat_order,sales_flat_order_address where sales_flat_order_address.parent_id = sales_flat_order.entity_id and sales_flat_order_address.postcode in ('" . $pincode . "')and sales_flat_order_address.address_type='billing' and date(sales_flat_order.created_at) between '" . $from_date . "' and '" . $to_date . "' group by sales_flat_order_address.postcode,date(sales_flat_order.created_at)";
         $ress2 = $read->fetchAll($sql3);
         $i = 1;
         foreach ($ress2 as $res2) {
             $data[$i]['area'] = $area_name;
             $data[$i]['date'] = $res2['date(sales_flat_order.created_at)'];
             $data[$i]['count'] = $res2['count(sales_flat_order_address.postcode)'];
             $data[$i]['subtotal'] = $res2['sum(sales_flat_order.subtotal)'];
             $data[$i]['invoiced'] = $res2['sum(sales_flat_order.base_subtotal_invoiced)'];
             $data[$i]['refunded'] = $res2['sum(sales_flat_order.subtotal_refunded)'];
             $data[$i]['tax_amount'] = $res2['sum(sales_flat_order.base_shipping_tax_amount)'];
             $data[$i]['shipping_amount'] = $res2['sum(sales_flat_order.shipping_amount)'];
             $data[$i]['discounts'] = $res2['sum(sales_flat_order.discount_amount)'];
             $data[$i]['cancelled'] = $res2['sum(sales_flat_order.subtotal_canceled)'];
             $orders_placed[] = $res2['count(sales_flat_order_address.postcode)'];
             $subtotal[] = $res2['sum(sales_flat_order.subtotal)'];
             $base_subtotal_invoiced[] = $res2['sum(sales_flat_order.base_subtotal_invoiced)'];
             $subtotal_refunded[] = $res2['sum(sales_flat_order.subtotal_refunded)'];
             $base_shipping_tax_amount[] = $res2['sum(sales_flat_order.base_shipping_tax_amount)'];
             $shipping_amount[] = $res2['sum(sales_flat_order.shipping_amount)'];
             $discount_amount[] = $res2['sum(sales_flat_order.discount_amount)'];
             $subtotal_canceled[] = $res2['sum(sales_flat_order.subtotal_canceled)'];
             $i++;
         }
         $data[$i]['area'] = 'Total';
         $data[$i]['date'] = ' ';
         $data[$i]['count'] = array_sum($orders_placed);
         $data[$i]['subtotal'] = array_sum($subtotal);
         $data[$i]['invoiced'] = array_sum($base_subtotal_invoiced);
         $data[$i]['refunded'] = array_sum($subtotal_refunded);
         $data[$i]['tax_amount'] = array_sum($base_shipping_tax_amount);
         $data[$i]['shipping_amount'] = array_sum($shipping_amount);
         $data[$i]['discounts'] = array_sum($discount_amount);
         $data[$i]['cancelled'] = array_sum($subtotal_canceled);
         foreach ($data as $val) {
             $information_row[] = $val;
         }
     }
     //$data = array();
     $mage_csv->saveData($file_path, $information_row);
     $message = $this->__('CSV is exported');
     Mage::getSingleton('adminhtml/session')->addSuccess($message);
     $this->_redirect('*/*/salesreport');
 }
示例#4
0
 public function importvalidateAction()
 {
     $this->_validateCustomerLogin();
     $session = $this->_getSession();
     $this->_initLayoutMessages('marketplace/session');
     $data = $this->getRequest()->getPost();
     $time = time();
     if ($data) {
         try {
             $marketplaceHelper = Mage::helper('marketplace');
             $customer = Mage::getSingleton('customer/session')->getCustomer();
             $productState = $customer->getSellerProductState();
             $productStatus = $customer->getSellerProductStatus();
             $newProductStatus = $productStatus ? $productStatus : $marketplaceHelper->getNewProductStatus();
             $newProductState = $productState ? $productState : $marketplaceHelper->getNewProductState();
             $newProductStateValue = Mage::getModel('eav/config')->getAttribute('catalog_product', 'marketplace_state')->getSource()->getOptionText($newProductState);
             $this->loadLayout();
             /** @var $import Mage_ImportExport_Model_Import */
             $import = Mage::getModel('importexport/import');
             $source = $import->setData($data)->uploadSource();
             // Modify CSV file
             $io = new Varien_Io_File();
             $io->streamOpen($source, 'r');
             $io->streamLock(true);
             $newCsvData = array();
             $i = 0;
             while ($data = $io->streamReadCsv()) {
                 if ($i == 0) {
                     $data[] = '_attribute_set';
                     $data[] = '_type';
                     $data[] = '_product_websites';
                     $data[] = 'tax_class_id';
                     $data[] = 'visibility';
                     $data[] = 'seller_id';
                     $data[] = 'marketplace_state';
                     $data[] = 'status';
                     $data[] = 'media_gallery';
                     $newCsvData[] = $data;
                 } else {
                     $data[] = 'Default';
                     $data[] = Mage_Catalog_Model_Product_Type::DEFAULT_TYPE;
                     $data[] = 'base';
                     $data[] = 0;
                     $data[] = $marketplaceHelper->getNewProductVisibility();
                     $data[] = $customer->getCompanyName();
                     $data[] = $newProductStateValue;
                     $data[] = $newProductStatus;
                     $data[] = ' ';
                     if ($this->validateSellerCSV($data)) {
                         $newCsvData[] = $data;
                     }
                 }
                 $i++;
             }
             $io->close();
             unlink($source);
             $checkPath = Mage::getBaseDir() . DS . 'media' . DS . 'marketplace/' . $customer->getId();
             if (!file_exists($checkPath)) {
                 mkdir($checkPath, 0777);
             }
             $newSource = $checkPath . DS . 'productimport.csv';
             $io = new Varien_File_Csv();
             $io->saveData($newSource, $newCsvData);
             $validationResult = $import->validateSource($newSource);
             if (!$import->getProcessedRowsCount()) {
                 $session->addError($this->__('File does not contain data or duplicate sku. Please upload another one'));
             } else {
                 if (!$validationResult) {
                     if ($import->getProcessedRowsCount() == $import->getInvalidRowsCount()) {
                         $session->addNotice($this->__('File is totally invalid. Please fix errors and re-upload file'));
                     } elseif ($import->getErrorsCount() >= $import->getErrorsLimit()) {
                         $session->addNotice($this->__('Errors limit (%d) reached. Please fix errors and re-upload file', $import->getErrorsLimit()));
                     } else {
                         if ($import->isImportAllowed()) {
                             $session->addNotice($this->__('Please fix errors and re-upload file or simply press "Import" button to skip rows with errors'), true);
                         } else {
                             $session->addNotice($this->__('File is partially valid, but import is not possible'), false);
                         }
                     }
                     // errors info
                     foreach ($import->getErrors() as $errorCode => $rows) {
                         $error = $errorCode . ' ' . $this->__('in rows:') . ' ' . implode(', ', $rows);
                         $session->addError($error);
                     }
                 } else {
                     if ($import->isImportAllowed()) {
                         $import->importSource();
                         //Process Images
                         $status = $this->_uploadZipImages($time);
                         if ($status !== false) {
                             if ($status[0] == 'success') {
                                 $returnVal = Mage::getModel('marketplace/image')->process($newCsvData, $customer->getId(), $time);
                                 if ($returnVal === true) {
                                     $customDir = Mage::getBaseDir() . DS . 'media' . DS . 'marketplace' . DS . $customer->getId() . DS . $time;
                                     self::delTree($customDir);
                                 }
                                 $session->addSuccess($this->__($status[1]), true);
                             } else {
                                 $session->addError($this->__($status[1]));
                             }
                         }
                         $import->invalidateIndex();
                         $session->addSuccess($this->__('Import successfully done.'), true);
                         $this->_redirect('*/*/import');
                     } else {
                         $session->addError($this->__('File is valid, but import is not possible'), false);
                     }
                 }
                 $session->addNotice($import->getNotices());
                 $session->addNotice($this->__('Checked rows: %d, checked entities: %d, invalid rows: %d, total errors: %d', $import->getProcessedRowsCount(), $import->getProcessedEntitiesCount(), $import->getInvalidRowsCount(), $import->getErrorsCount()));
             }
         } catch (Exception $e) {
             $session->addNotice($this->__('Please fix errors and re-upload file'))->addError($e->getMessage());
         }
     } elseif ($this->getRequest()->isPost() && empty($_FILES)) {
         $session->addError($this->__('File was not uploaded'));
     } else {
         $session->addError($this->__('Data is invalid or file is not uploaded'));
     }
     $this->_redirect('*/*/import');
 }
示例#5
0
 /**
  * Synced csv file
  *
  * @param string $from
  * @param string $to
  */
 protected function syncFile($from, $to)
 {
     $basename = basename($from);
     if (!file_exists($to)) {
         $this->log("Creating file: {$to}");
         copy($from, $to);
         return;
     }
     $dataFrom = $this->getFileData($from);
     $dataTo = $this->getFileData($to);
     //compare keys to see if the file needs to be synced
     $diff = array_diff_key($dataFrom, $dataTo) || array_diff_key($dataTo, $dataFrom);
     $total = count($dataFrom);
     $translated = 0;
     $data = array();
     foreach ($dataFrom as $key => $value) {
         if (!trim($key)) {
             continue;
         }
         $value = array_key_exists($key, $dataTo) ? $dataTo[$key] : $dataFrom[$key];
         if ($this->isTranslated($key, $value)) {
             $translated++;
         }
         if ($diff) {
             $data[] = array($key, $value);
         }
     }
     $this->totalStrings += $total;
     $this->translatedStrings += $translated;
     $status = sprintf(" Status: %.2f%% (%d/%d)", $translated / $total * 100, $translated, $total);
     if ($diff) {
         $this->log(" - Synced file " . $basename . $status);
         //Additional strings added in target locale will be kept in conservative mode
         if ($this->conservative) {
             $firstExtraString = true;
             foreach ($dataTo as $key => $value) {
                 if (!trim($key) || array_key_exists($key, $dataFrom)) {
                     continue;
                 }
                 if ($firstExtraString) {
                     $this->log("   Extra strings detected", PROJECT_MSG_WARN);
                     $firstExtraString = false;
                 }
                 $this->log("   + {$key}", PROJECT_MSG_WARN);
                 $data[] = array($key, $value);
             }
         }
         $writer = new Varien_File_Csv();
         $writer->saveData($to, $data);
     } else {
         $this->log(" - Checked file " . $basename . $status);
     }
 }
示例#6
0
 public function eventRequestAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         //print_r($data);exit;
         if (isset($data['occasion_on_time']) && $data['occasion_on_time'] != '') {
             $data['occasion_on_time'] = date('H:i', strtotime($data['occasion_on_time'])) . ":00";
         }
         if (isset($data['occasion_on']) && $data['occasion_on'] != '') {
             $data['occasion_on'] = date('Y-m-d', strtotime($data['occasion_on']));
             $data['occasion_on'] = $data['occasion_on'] . " " . $data['occasion_on_time'];
         }
         $model = Mage::getModel('eventmanager/eventmanagercustom');
         try {
             if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                 $model->setCreatedTime(now())->setUpdateTime(now());
             } else {
                 $model->setUpdateTime(now());
             }
             if ($data['request'] == 'Custom Event') {
                 $data['other_occasion'] = $data['comments'] = $data['budget'] = '';
                 $data['occasion_on'] = isset($data['occasion_on']) && $data['occasion_on'] != '' ? $data['occasion_on'] : '0000-00-00 00:00:00';
                 $data['pandit'] = $data['samagri'] = $data['catering'] = $data['decoration'] = $data['venue'] = $data['technical'] = $data['event_management'] = 'no';
             }
             $data['status'] = 'new';
             $data['created'] = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
             $data['modified'] = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
             /*if(isset($data['type']) && $data['type'] > 0) {
             			$categories = Mage::getModel('catalog/category')->getCollection()
             				->addAttributeToFilter('entity_id', array('eq' => $data['type']))
             				->addAttributeToSelect('name');
             			foreach ($categories as $category) {
             				$data['category'] = $category->getName();
             			}
             		}*/
             if (isset($data['type']) && $data['type'] === "Other") {
                 $data['type'] = $data['other_puja'];
                 $data['other_occasion'] = $data['other_puja'];
                 $product_id = 0;
             } else {
                 $product_id = Mage::getModel("catalog/product")->getIdBySku($product_sku);
             }
             if (isset($data['phone_area_code']) && $data['phone_area_code'] != "") {
                 $data['phone'] = $data['phone_area_code'] . "-" . $data['phone'];
             }
             //$mobile = "";
             if (isset($data['mobile_ext']) && $data['mobile_ext'] != "") {
                 $data['mobile'] = $data['mobile_ext'] . "-" . $data['mobile'];
                 //$mobile = $data['phone']." / ".$data['mobile'];
             }
             $file_path = Mage::getBaseDir() . '/media/enquiryform/' . date("d_m_Y_H_i_s") . "_" . str_replace(' ', "_", $data['name']) . '.csv';
             $mage_csv = new Varien_File_Csv();
             $csvdata[] = array_keys($data);
             $csvdata[] = $data;
             $mage_csv->saveData($file_path, $csvdata);
             /*if(isset($data['occasion']) && $data['occasion'] > 0) {
             			$categories = Mage::getModel('catalog/category')->getCollection()
             				->addAttributeToFilter('entity_id', array('eq' => $data['occasion']))
             				->addAttributeToSelect('name', 'url');
             			foreach ($categories as $category) {
             				$data['subcategory'] = $category->getName();
             				$data['url'] = $category->getUrl();
             			}
             		}*/
             //echo "<h1>Thank you for your interest. We will contact you soon.</h1><script language='javascript'>setTimeout(function() { window.location.href = '" . str_replace('.html', '/pooja-ingredients.html', $data['url']) . "';}, 3000);</script>";
             //echo "<script language='javascript'>window.location.href = '" . str_replace('.html', '/pooja-ingredients.html', $data['url']) . "';</script>";
             $data['template'] = 'new_custom_event';
             //print_r($data);exit;
             $this->sendCustomRequestEmail($data['email'], $data['name'], $data);
             $data['template'] = 'new_custom_event_to_admin';
             $data['looking_for'] = strtolower($data['looking_for']);
             $data['cname'] = ucwords($data['name']);
             $data['cemail'] = $data['email'];
             /*$categories = Mage::getModel('catalog/category')->getCollection()
             				->addAttributeToFilter('entity_id', array('eq' => $data['type']))
             				->addAttributeToSelect('name');
             				foreach ($categories as $category) {
             					$data['category'] = $category->getName();
             				}
             
             				$subcategories = Mage::getModel('catalog/category')->getCollection()
             				->addAttributeToFilter('entity_id', array('eq' => $data['occasion']))
             				->addAttributeToSelect('name');
             				foreach ($subcategories as $subcategory) {
             					$data['subcategory'] = $subcategory->getName();
             				}*/
             $this->sendCustomRequestEmail(Mage::getStoreConfig('trans_email/ident_general/email', Mage::app()->getStore()->getStoreId()), Mage::getStoreConfig('trans_email/ident_general/name', Mage::app()->getStore()->getStoreId()), $data);
             //$this->sendCustomRequestEmail("*****@*****.**", "Ninad", $data);
             //echo "<h1>Thank you for your interest. We will contact you soon.</h1>";
             //$data['phone'] = $mobile ;
             if ($product_id) {
                 $data['type'] = $product_id;
             }
             $model->setData($data);
             $model->save();
             exit;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
 }
示例#7
0
 /**
  * @param string $module
  * @param array $data
  */
 protected function syncModule($module, $data)
 {
     $this->log("Syncing module {$module}");
     $file = $this->getBasedir() . DS . 'app' . DS . 'locale' . DS . $this->getTo() . DS . $module . '.csv';
     if (!file_exists($file)) {
         $this->log("File not found: {$file}", Project::MSG_WARN);
         return;
     }
     $fileData = $this->getFileData($file);
     $count = 0;
     foreach ($data as $text => $value) {
         if (isset($fileData[$text])) {
             $this->log("Updating {$text}");
             $fileData[$text] = $value;
             $count++;
         } else {
             $this->log("Entry not found: {$text}", Project::MSG_WARN);
         }
     }
     if (!$count) {
         return;
     }
     $data = array();
     foreach ($fileData as $text => $value) {
         $data[] = array($text, $value);
     }
     $writer = new Varien_File_Csv();
     $writer->saveData($file, $data);
 }
示例#8
0
 /**
  * Do the export.
  */
 public function exportAction()
 {
     Mage::log("TranslationExporter: Export started");
     $translate = Mage::getSingleton('core/translate');
     $locale = $translate->getLocale();
     $baseFolder = $locale . '_base';
     $targetDir = Mage::getBaseDir('var') . DS . 'translations' . DS . $locale;
     $localeDir = Mage::getBaseDir('locale');
     Mage::log("TranslationExporter - target directory: {$targetDir}");
     $dbtrans = $translate->getResource()->getTranslationArray(null, $locale);
     Mage::log("TranslationExporter: " . count($dbtrans) . " translation rows from DB");
     // for each module:
     // - for each CSV file in that module:
     //   1. read it to memory
     //   2. modify it according to DB translation for that module
     //   3. write it back to dest dir
     $parser = new Varien_File_Csv();
     $parser->setDelimiter(Mage_Core_Model_Translate::CSV_SEPARATOR);
     foreach ($translate->getModulesConfig() as $moduleName => $info) {
         $info = $info->asArray();
         Mage::log("TranslationExporter: Exporting module {$moduleName}");
         foreach ($info['files'] as $file) {
             $enData = array();
             $enFilePath = $localeDir . DS . 'en_US' . DS . $file;
             if (file_exists($enFilePath)) {
                 $enData = $parser->getDataPairs($enFilePath);
             }
             $baseData = array();
             $baseFilePath = $localeDir . DS . $baseFolder . DS . $file;
             if (file_exists($baseFilePath)) {
                 $baseData = $parser->getDataPairs($baseFilePath);
             }
             foreach ($baseData as $key => $val) {
                 if (isset($enData[$key]) && $enData[$key] !== $val) {
                     $enData[$key] = $val;
                 }
             }
             $data = array();
             $filePath = $localeDir . DS . $locale . DS . $file;
             Mage::log("TranslationExporter: Reading {$filePath}");
             if (file_exists($filePath)) {
                 $data = $parser->getDataPairs($filePath);
             }
             foreach ($data as $key => $val) {
                 if (isset($enData[$key]) && $enData[$key] !== $val) {
                     $enData[$key] = $val;
                 }
             }
             // 2. MODIFY
             foreach ($enData as $key => $val) {
                 $fullKey = $moduleName . '::' . $key;
                 if (isset($dbtrans[$fullKey])) {
                     $stack[] = $fullKey;
                     Mage::log("TranslationExporter: Rewrite '{$fullKey}' from '{$val}' to '{$dbtrans[$fullKey]}'");
                     $enData[$key] = $dbtrans[$fullKey];
                 }
             }
             // 3. WRITE
             if (!file_exists($targetDir)) {
                 if (!mkdir($targetDir, 0777, true)) {
                     throw new Exception("Cannot create {$targetDir}");
                 }
             }
             $targetFile = $targetDir . '/' . $file;
             $parser = new Varien_File_Csv();
             $csvdata = array();
             foreach ($enData as $key => $val) {
                 $csvdata[] = array($key, $val);
             }
             $parser->saveData($targetFile, $csvdata);
             Mage::log("TranslationExporter: wrote {$targetFile}");
         }
         Mage::log("TranslationExporter: Done.");
     }
     Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('compiler')->__("Translations has been exported to '%s'.", $targetDir));
     $this->_redirect('*/*/');
 }
 /**
  * createCSV
  * @ This is for creating csv file at given location
  * @param string $path is the path of directory
  * @param string $csvFileName is the name of csv file
  * @param string $data is the customers data
  * @ returns boolean 
  */
 function createCSV($path, $csvFileName, $data)
 {
     if ($this->checkDirectory($path)) {
         try {
             $path = $path . $csvFileName;
             $mage_csv = new Varien_File_Csv();
             //mage CSV
             //write to csv file
             $mage_csv->saveData($path, $data);
             //note $data will be two dimensional array
         } catch (Exception $ex) {
             throw new Exception($ex);
         }
     }
     return true;
 }
示例#10
0
 public function downloadAction()
 {
     $user = Mage::getSingleton('core/session')->getData('usermanagement_user');
     if (!$user) {
         $this->_redirect('usermanagement/configuration');
     }
     $website = $user->getWebsite();
     if ($website->getLanguageFile()) {
         $data = $website->getDefaultLanguage(false);
         $oldData = $website->getLanguageData();
         $languageTotal = count($oldData[0]) - 1;
         $newLanguages[0] = $oldData[0];
         foreach ($data as $key => $value) {
             $newRow = array();
             $newRow[] = $key;
             foreach ($oldData as $oldItem) {
                 if ($oldItem[0] == $key) {
                     unset($oldItem[0]);
                     foreach ($oldItem as $lang) {
                         $newRow[] = $lang;
                     }
                     break;
                 }
             }
             if (count($newRow) == 1) {
                 // not has old data
                 for ($i = 0; $i < $languageTotal; $i++) {
                     $newRow[] = '';
                 }
             }
             $this->addComment($key, $newLanguages);
             $newLanguages[] = $newRow;
         }
         $file = Mage::getBaseDir('media') . DS . 'simicart' . DS . 'languages' . DS . $website->getLanguageFile();
         $csv = new Varien_File_Csv();
         $csv->saveData($file, $newLanguages);
     }
     $this->_redirectUrl($website->getLanguageFileUrl());
 }