Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. ini_set('memory_limit', '512M');
  6. require 'app/Mage.php';
  7. umask(0);
  8. Mage::app('default');
  9.  
  10. class ImportProductMeta extends Mage_Core_Model_Abstract {
  11. protected $_fileName;
  12. protected $_dbSKUArray;
  13. protected $_csvArray = array();
  14. public function _construct() {
  15. parent::_construct();
  16. $this->_initValue();
  17.  
  18. }
  19.  
  20. protected function _initValue() {
  21. $this->_fileName = 'MorganWright.csv';
  22. return $this;
  23. }
  24.  
  25. public function importProductMetaStart() {
  26. $this->_createCSVDataArray();
  27. $productCollection = Mage::getModel('catalog/product')->getCollection();
  28.  
  29. foreach ($productCollection as $product) {
  30. $action = Mage::getModel('catalog/resource_product_action');
  31. $action->updateAttributes(array($product->getId()), $this->_dbSKUArray[$product->getSku()], 1);
  32. echo $product->getSku().' Updated successfully.';
  33. break;
  34.  
  35. }
  36.  
  37. }
  38. protected function _createCSVDataArray() {
  39. $this->_readcsvfile($this->_fileName);
  40. foreach ($this->_csvArray as $key => $dataArr) {
  41. $this->_dbSKUArray[$dataArr['Sku']] = array('meta_keyword' => '', 'meta_title' => $dataArr['Meta Title'], 'meta_description' => $dataArr['Meta Description']);
  42. }
  43. }
  44.  
  45. protected function _readcsvfile($csvfileName) {
  46. $io = new Varien_Io_File();
  47.  
  48. $path = Mage::getBaseDir('var') . DS . 'import';
  49. $file = $path . DS . $csvfileName;
  50. $io->open(array('path' => $path));
  51. $fileName = $io->getCleanPath($path . $file);
  52. $io->streamOpen($file, 'r+');
  53.  
  54. $i = 0;
  55.  
  56. $header = NULL;
  57. if (($handle = $io->streamReadCsv(',')) !== FALSE) {
  58. $handle = array_map('trim', $handle);
  59. $header = $handle;
  60. $this->_headers = $header;
  61. while (($data = $io->streamReadCsv(',')) !== FALSE) {
  62. if (!$header) {
  63. $header = $data;
  64. } else {
  65. $itemData = array_combine($header, $data);
  66. $this->_csvArray[] = $itemData;
  67. }
  68. $i++;
  69. }
  70. }
  71. }
  72.  
  73. }
  74.  
  75. $importObject = new ImportProductMeta();
  76. $importObject->importProductMetaStart();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement