本文整理汇总了PHP中Varien_File_Csv::getData方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Csv::getData方法的具体用法?PHP Varien_File_Csv::getData怎么用?PHP Varien_File_Csv::getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_File_Csv
的用法示例。
在下文中一共展示了Varien_File_Csv::getData方法的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: 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');
}
示例3: 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');
}
}
示例4: 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) {
}
}
}
示例5: 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;
}
}
示例6: 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;
}
示例7: _importData
protected function _importData()
{
$reviewsFile = $this->getArg('reviews');
$ratingsFile = $this->getArg('ratings');
$mapping = $this->getArg('mapping');
$baseDir = Mage::getBaseDir();
$reviewPath = $baseDir . '/' . $reviewsFile;
$ratingPath = $baseDir . '/' . $ratingsFile;
if ($mapping) {
$mapping = $this->_parseMapping($mapping);
}
if (file_exists($reviewPath) && file_exists($ratingPath)) {
$csv = new Varien_File_Csv();
$reviews = $this->_getCsvWithHeaders($csv->getData($reviewPath));
$ratings = $this->_getCsvWithHeaders($csv->getData($ratingPath));
$count = 0;
foreach ($reviews as $review) {
$reviewModel = Mage::getModel('review/review');
$reviewModel->setData(array('entity_id' => $reviewModel->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE), 'entity_pk_value' => $mapping ? $mapping[$review['entity_pk_value']] : $review['entity_pk_value'], 'status_id' => $review['status_id'], 'customer_id' => null, 'title' => $review['title'], 'nickname' => $review['nickname'], 'detail' => $review['detail'], 'store_id' => $review['store_id'], 'stores' => array($review['store_id'])))->save();
//double save because review model checks for an id and resets this on new objects - i know it sucks
$reviewModel->setCreatedAt($review['created_at'])->save();
$reviewRatings = array_filter($ratings, function ($rating) use($review) {
return $rating['review_id'] == $review['review_id'];
});
foreach ($reviewRatings as $rating) {
Mage::getModel('rating/rating')->setRatingId($rating['rating_id'])->setReviewId($reviewModel->getId())->setCustomerId($rating['customer_id'])->addOptionVote($rating['option_id'], $mapping ? $mapping[$rating['entity_pk_value']] : $rating['entity_pk_value']);
}
$reviewModel->aggregate();
$count++;
}
echo 'Successfully imported ' . $count . ' reviews';
} else {
echo "One of the files doesn't exist.";
}
return $this;
}
示例8: 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('*/*/');
}
示例9: _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));
}
示例10: 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('*/*/');
}
示例11: 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);
}
}
示例12: 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;
}
示例13: 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) {
}
}
}
示例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: import
public function import()
{
$file = $this->_path . $this->_fileName;
if (!is_file($file)) {
Mage::throwException(Mage::helper('ism_newstore_members')->__('Invalid file!'));
}
$csv = new Varien_File_Csv();
$data = $csv->getData($file);
unset($data[0]);
$skuCodes = array_column($data, 0);
$prices = array_column($data, 1);
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('sku', array('in' => $skuCodes));
$prices = array_combine($skuCodes, $prices);
foreach ($collection as $item) {
try {
$item->setIsmNewstoremembersPrice($prices[$item->getSku()])->save();
} catch (Exception $e) {
Mage::log('Error with product: ' . $item->getSku());
}
}
unlink($file);
return $this;
}