本文整理汇总了PHP中Varien_File_Csv类的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Csv类的具体用法?PHP Varien_File_Csv怎么用?PHP Varien_File_Csv使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Varien_File_Csv类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getExtensions
public function getExtensions()
{
$data = array();
try {
$file = 'http://d52ndf1ixk2tu.cloudfront.net/media/featured_product.csv';
/* https does not work */
$content = $this->urlGetContents($file);
if ($content == false) {
$file = 'https://www.iwdagency.com/extensions/media/featured_product.csv';
$content = $this->urlGetContents($file);
if ($content == false) {
return "";
}
}
$path = Mage::getBaseDir('media') . DS . 'import' . DS . 'featured_product.csv';
if (!file_exists(Mage::getBaseDir('media') . DS . 'import')) {
mkdir(Mage::getBaseDir('media') . DS . 'import');
}
file_put_contents($path, $content);
$csv = new Varien_File_Csv();
$data = $csv->getData($path);
@unlink($path);
} catch (Exception $e) {
Mage::logException($e);
}
return $data;
}
示例2: saveAction
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('*/*/');
}
示例3: importMotorsDataAction
public function importMotorsDataAction()
{
$helper = Mage::helper('M2ePro/Component_Ebay_Motors');
$motorsType = $this->getRequest()->getPost('motors_type');
if (!$motorsType || empty($_FILES['source']['tmp_name'])) {
$this->getSession()->addError(Mage::helper('M2ePro')->__('Some of required fields are not filled up.'));
return $this->_redirect('*/*/index');
}
$csvParser = new Varien_File_Csv();
$tempCsvData = $csvParser->getData($_FILES['source']['tmp_name']);
$csvData = array();
$headers = array_shift($tempCsvData);
foreach ($tempCsvData as $csvRow) {
$csvData[] = array_combine($headers, $csvRow);
}
$added = 0;
$existedItems = $this->getExistedMotorsItems();
$connWrite = Mage::getSingleton('core/resource')->getConnection('core/write');
$tableName = $helper->getDictionaryTable($motorsType);
foreach ($csvData as $csvRow) {
if (!($insertsData = $this->getPreparedInsertData($csvRow, $existedItems))) {
continue;
}
$added++;
$connWrite->insert($tableName, $insertsData);
}
$this->_getSession()->addSuccess("Successfully added '{$added}' compatibility records.");
return $this->_redirect('*/*/index');
}
示例4: importDataAction
public function importDataAction()
{
try {
if ($this->getRequest()->getPost()) {
if (isset($_FILES['import_file']['name']) && $_FILES['import_file']['name'] != '') {
$uploaderFile = new Varien_File_Uploader('import_file');
$uploaderFile->setAllowedExtensions(array('csv'));
$uploaderFile->setAllowRenameFiles(true);
$uploaderFile->setFilesDispersion(false);
$uploaderFilePath = Mage::getBaseDir('cache') . DS . 'mgs' . DS . 'brand' . DS . 'import' . DS . 'csv' . DS;
$uploaderFile->save($uploaderFilePath, $_FILES['import_file']['name']);
$filePath = $uploaderFilePath . $uploaderFile->getUploadedFileName();
$csv = new Varien_File_Csv();
$brands = $csv->getData($filePath);
$i = 0;
foreach ($brands as $brand) {
if ($i > 0) {
Mage::helper('brand')->import($brand);
}
$i++;
}
$urlRewriteCollection = Mage::getModel('core/url_rewrite')->getCollection()->addFieldToFilter('id_path', 'brand/index/');
foreach ($urlRewriteCollection as $url) {
$url->delete();
}
$urlRewrite = Mage::getModel('core/url_rewrite')->loadByIdPath('brand/index')->setIdPath('brand/index');
if (Mage::helper('brand')->urlKey() != '') {
$urlRewrite->setRequestPath(Mage::helper('brand')->urlKey());
} else {
$urlRewrite->setRequestPath('brand');
}
$urlRewrite->setTargetPath('brand/index/index');
$urlRewrite->setIsSystem(1);
$urlRewrite->save();
$collection = Mage::getModel('brand/brand')->getCollection();
foreach ($collection as $brand) {
$urlRewriteCollection = Mage::getModel('core/url_rewrite')->getCollection()->addFieldToFilter('id_path', 'brand/view/' . $brand->getId());
foreach ($urlRewriteCollection as $url) {
$url->delete();
}
$urlRewrite = Mage::getModel('core/url_rewrite')->loadByIdPath('brand/view/' . $brand->getId())->setIdPath('brand/view/' . $brand->getId());
if (Mage::helper('brand')->urlKey() != '') {
$urlRewrite->setRequestPath(Mage::helper('brand')->urlKey() . '/' . $brand->getUrlKey());
} else {
$urlRewrite->setRequestPath('brand/' . $brand->getUrlKey());
}
$urlRewrite->setTargetPath('brand/index/view/id/' . $brand->getId());
$urlRewrite->setIsSystem(1);
$urlRewrite->save();
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('brand')->__('All brands were successfully imported.'));
$this->_redirect('*/*/index');
}
}
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/import');
}
}
示例5: importproductAction
public function importproductAction()
{
if (isset($_FILES['fileToUpload']['name']) && $_FILES['fileToUpload']['name'] != '') {
try {
$types = explode('.', $_FILES['fileToUpload']['name']);
$fileType = $types[count($types) - 1];
if ($fileType != 'csv') {
echo Mage::helper('inventoryplus')->__("Wrong file's format");
return;
}
$fileName = $_FILES['fileToUpload']['tmp_name'];
$Object = new Varien_File_Csv();
$dataFile = $Object->getData($fileName);
$receiptstockProduct = array();
$receiptstockProducts = array();
$fields = array();
$count = 0;
$receiptstockHelper = Mage::helper('inventoryreceipt');
$url = Mage::getUrl('inventoryreceiptadmin/adminhtml_receipt/index');
if (count($dataFile)) {
foreach ($dataFile as $col => $row) {
if ($col == 0) {
if (count($row)) {
foreach ($row as $index => $cell) {
$fields[$index] = (string) $cell;
}
}
} elseif ($col > 0) {
if (count($row)) {
foreach ($row as $index => $cell) {
if (isset($fields[$index])) {
$receiptstockProduct[$fields[$index]] = $cell;
}
}
}
$receiptstockProducts[] = $receiptstockProduct;
}
}
} else {
if (count($dataFile) == 0) {
echo Mage::helper('inventoryreceipt')->__("File is empty");
return;
}
}
if (count($receiptstockProducts) > 0) {
$receiptstockHelper->importProduct($receiptstockProducts);
} else {
echo Mage::helper('inventoryreceipt')->__("Wrong information's structure");
return;
}
} catch (Exception $e) {
}
}
}
示例6: getLanguageCsvData
public function getLanguageCsvData()
{
$website = $this->getWebsite();
$file = $website->getLanguageDirFile();
try {
$csv = new Varien_File_Csv();
$data = $csv->getData($file);
return $data;
} catch (Exception $e) {
return NULL;
}
}
示例7: saveAction
public function saveAction()
{
$data = $this->getRequest()->getParams();
$uploader = new Mage_Core_Model_File_Uploader('file');
$uploader->setAllowedExtensions(array('csv'));
$uploader->setAllowRenameFiles(true);
$path = Mage::getBaseDir('var') . DS . 'import';
if (!file_exists($path)) {
mkdir($path, 0777);
}
try {
$result = $uploader->save($path);
$fullPath = $result['path'] . DS . $result['file'];
$csv = new Varien_File_Csv();
$data = $csv->getData($fullPath);
$items = array();
if (count($data) > 1) {
for ($i = 1; $i < count($data); $i++) {
$item = array();
for ($j = 0; $j < count($data[0]); $j++) {
if (isset($data[$i][$j]) && trim($data[$i][$j]) != '') {
$item[strtolower($data[0][$j])] = $data[$i][$j];
}
}
$items[] = $item;
}
}
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$table = $resource->getTableName('seo/redirect');
$table2 = $resource->getTableName('seo/redirect_store');
$i = 0;
foreach ($items as $item) {
pr($item);
if (!isset($item['url_from']) || !isset($item['url_to'])) {
continue;
}
$item = new Varien_Object($item);
$query = "REPLACE {$table} SET\n url_from = '" . addslashes($item->getUrlFrom()) . "',\n url_to = '" . addslashes($item->getUrlTo()) . "',\n is_redirect_only_error_page = '" . addslashes($item->getIsRedirectOnlyErrorPage()) . "',\n comments = '" . addslashes($item->getComments()) . "',\n is_active = '" . addslashes($item->getIsActive()) . "';\n REPLACE {$table2} SET\n store_id = 0,\n redirect_id = LAST_INSERT_ID();\n ";
$writeConnection->query($query);
$i++;
}
Mage::getSingleton('adminhtml/session')->addSuccess('' . $i . ' records were inserted or updated');
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
$this->_redirect('*/*/');
}
示例8: _importStopwords
protected function _importStopwords($file)
{
$csv = new Varien_File_Csv();
$data = $csv->getData(Mage::getBaseDir('var') . DS . 'import' . DS . $file);
$result = array();
foreach ($data as $value) {
$result[] = array('stopword' => $value[0]);
}
if (strlen(serialize($result)) < 65535) {
$config = new Mage_Core_Model_Config();
$config->saveConfig('searchsphinx/advanced/stopwords', serialize($result), 'default', 0);
} else {
return 'File too long';
}
return sprintf('Imported %s lines', count($result));
}
示例9: saveAction
public function saveAction()
{
$data = $this->getRequest()->getParams();
$uploader = new Mage_Core_Model_File_Uploader('file');
$uploader->setAllowedExtensions(array('csv'));
$uploader->setAllowRenameFiles(true);
$path = Mage::getBaseDir('var') . DS . 'import';
if (!file_exists($path)) {
mkdir($path, 0777);
}
try {
$result = $uploader->save($path);
$fullPath = $result['path'] . DS . $result['file'];
$csv = new Varien_File_Csv();
$data = $csv->getData($fullPath);
$items = array();
if (count($data) > 1) {
for ($i = 1; $i < count($data); $i++) {
$item = array();
for ($j = 0; $j < count($data[0]); $j++) {
if (isset($data[$i][$j]) && trim($data[$i][$j]) != '') {
$item[strtolower($data[0][$j])] = $data[$i][$j];
}
}
$items[] = $item;
}
}
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$table = $resource->getTableName('seoautolink/link');
$table2 = $resource->getTableName('seoautolink/link_store');
$i = 0;
foreach ($items as $item) {
if (!isset($item['keyword'])) {
continue;
}
$item = new Varien_Object($item);
$query = "REPLACE {$table} SET\n keyword = '" . addslashes($item->getKeyword()) . "',\n url = '" . addslashes($item->getUrl()) . "',\n url_title = '" . addslashes($item->getUrlTitle()) . "',\n url_target = '" . addslashes($item->getUrlTarget()) . "',\n is_nofollow = '" . (int) $item->getIsNofollow() . "',\n max_replacements = '" . (int) $item->getMaxReplacements() . "',\n sort_order = '" . (int) $item->getSortOrder() . "',\n occurence = '" . (int) $item->getOccurence() . "',\n is_active = '" . (int) $item->getIsActive() . "',\n created_at = '" . now() . "',\n updated_at = '" . now() . "';\n REPLACE {$table2} SET\n store_id = '" . (int) $item->getStoreId() . "',\n link_id = LAST_INSERT_ID();\n ";
$writeConnection->query($query);
$i++;
}
Mage::getSingleton('adminhtml/session')->addSuccess('' . $i . ' records were inserted or updated');
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
$this->_redirect('*/*/');
}
示例10: importFilesRelations
public function importFilesRelations($csvPath, $uploadedFiles)
{
$csv = new Varien_File_Csv();
$data = $csv->getData($csvPath);
foreach ($data as $line) {
if (!is_array($line) || count($line) != 2) {
continue;
}
$files = explode(';', $line[1]);
$fileIds = array();
foreach ($files as $path) {
$fileIds[] = array_search(Mage::getBaseDir('media') . '/downloads_import/' . $path, $uploadedFiles);
}
$skus = explode(';', $line[0]);
$this->_assignFiles($fileIds, $skus);
}
}
示例11: getExtensions
public function getExtensions()
{
$data = array();
try {
$file = 'http://dg8i44zfacfed.cloudfront.net/featured_product.csv';
$content = $this->urlGetContents($file);
$path = Mage::getBaseDir('media') . DS . 'import' . DS . 'featured_product.csv';
if (!file_exists(Mage::getBaseDir('media') . DS . 'import')) {
mkdir(Mage::getBaseDir('media') . DS . 'import');
}
file_put_contents($path, $content);
$csv = new Varien_File_Csv();
$data = $csv->getData($path);
@unlink($path);
} catch (Exception $e) {
Mage::logException($e);
}
return $data;
}
示例12: getImportCsvAction
public function getImportCsvAction()
{
if (isset($_FILES['fileToUpload']['name']) && $_FILES['fileToUpload']['name'] != '') {
try {
$fileName = $_FILES['fileToUpload']['tmp_name'];
$Object = new Varien_File_Csv();
$dataFile = $Object->getData($fileName);
$warehouseProduct = array();
$warehouseProducts = array();
$fields = array();
$count = 0;
$helper = Mage::helper('inventorywarehouse/warehouse');
if (count($dataFile)) {
foreach ($dataFile as $col => $row) {
if ($col == 0) {
if (count($row)) {
foreach ($row as $index => $cell) {
$fields[$index] = (string) $cell;
}
}
} elseif ($col > 0) {
if (count($row)) {
foreach ($row as $index => $cell) {
if (isset($fields[$index])) {
$warehouseProduct[$fields[$index]] = $cell;
}
}
}
$source = $this->getRequest()->getParam('source');
$productId = Mage::getModel('catalog/product')->getIdBySku($warehouseProduct['SKU']);
$warehouseproduct = Mage::getModel('inventoryplus/warehouse_product')->getCollection()->addFieldToFilter('warehouse_id', $source)->addFieldToFilter('product_id', $productId);
if (!$warehouseproduct->getSize()) {
$warehouseProducts[] = $warehouseProduct;
}
}
}
}
$helper->importProduct($warehouseProducts);
} catch (Exception $e) {
}
}
}
示例13: exportTableratesAction
/**
* Export the eParcel table rates as a CSV file.
*/
public function exportTableratesAction()
{
$rates = Mage::getResourceModel('australia/shipping_carrier_eparcel_collection');
$response = array(array('Country', 'Region/State', 'Postcodes', 'Weight from', 'Weight to', 'Parcel Cost', 'Cost Per Kg', 'Delivery Type', 'Charge Code Individual', 'Charge Code Business'));
foreach ($rates as $rate) {
$countryId = $rate->getData('dest_country_id');
$countryCode = Mage::getModel('directory/country')->load($countryId)->getIso3Code();
$regionId = $rate->getData('dest_region_id');
$regionCode = Mage::getModel('directory/region')->load($regionId)->getCode();
$response[] = array($countryCode, $regionCode, $rate->getData('dest_zip'), $rate->getData('condition_from_value'), $rate->getData('condition_to_value'), $rate->getData('price'), $rate->getData('price_per_kg'), $rate->getData('delivery_type'), $rate->getData('charge_code_individual'), $rate->getData('charge_code_business'));
}
$csv = new Varien_File_Csv();
$temp = tmpfile();
foreach ($response as $responseRow) {
$csv->fputcsv($temp, $responseRow);
}
rewind($temp);
$contents = stream_get_contents($temp);
$this->_prepareDownloadResponse('tablerates.csv', $contents);
fclose($temp);
}
示例14: saveAction
public function saveAction()
{
if (!isset($_FILES['csv_store'])) {
Mage::getSingleton('core/session')->addError('Not selected file!');
$this->_redirect('*/*/importstore');
return;
}
$oFile = new Varien_File_Csv();
$data = $oFile->getData($_FILES['csv_store']['tmp_name']);
$store = Mage::getModel('storepickup/store');
$storeData = array();
try {
$total = 0;
foreach ($data as $col => $row) {
if ($col == 0) {
$index_row = $row;
} else {
for ($i = 0; $i < count($row); $i++) {
$storeData[$index_row[$i]] = $row[$i];
}
$store->setData($storeData);
$store->setId(null);
if ($store->import()) {
$total++;
}
}
}
$this->_redirect('*/adminhtml_store/index');
if ($total != 0) {
Mage::getSingleton('core/session')->addSuccess('Imported successful total ' . $total . ' stores');
} else {
Mage::getSingleton('core/session')->addSuccess('Stores exist');
}
} catch (Exception $e) {
Mage::getSingleton('core/session')->addError($e->getMessage());
$this->_redirect('*/*/importstore');
}
}
示例15: getPendingList
public function getPendingList()
{
$csv = new Varien_File_Csv();
$pendingList = array();
try {
$todoList = $csv->getData($this->_helper->getStoragePath() . $this->_helper->getAllActionsFilename());
$doneList = $csv->getData($this->_helper->getStoragePath() . $this->_helper->getExecutedActionsFilename());
$todo = array();
$done = array();
foreach ($todoList as $k => $v) {
$todo[$k] = implode('|', $v);
}
foreach ($doneList as $k => $v) {
$done[$k] = implode('|', $v);
}
foreach (array_diff($todo, $done) as $k => $v) {
$pendingList[$k] = $todoList[$k];
}
} catch (Exception $e) {
$this->_helper->log($e->getMessage());
}
return $pendingList;
}