Created
October 1, 2019 08:21
-
-
Save zaheerbadi/f4a5351fbbc0fbc4ec2afa374682f119 to your computer and use it in GitHub Desktop.
Here i am updating three meta attribute.But you can update any no of attribute as per your requirement.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
error_reporting(E_ALL); | |
ini_set('memory_limit', '512M'); | |
require 'app/Mage.php'; | |
umask(0); | |
Mage::app('default'); | |
class ImportProductMeta extends Mage_Core_Model_Abstract { | |
protected $_fileName; | |
protected $_dbSKUArray; | |
protected $_csvArray = array(); | |
public function _construct() { | |
parent::_construct(); | |
$this->_initValue(); | |
} | |
protected function _initValue() { | |
$this->_fileName = 'MorganWright.csv'; | |
return $this; | |
} | |
public function importProductMetaStart() { | |
$this->_createCSVDataArray(); | |
$productCollection = Mage::getModel('catalog/product')->getCollection(); | |
foreach ($productCollection as $product) { | |
$action = Mage::getModel('catalog/resource_product_action'); | |
$action->updateAttributes(array($product->getId()), $this->_dbSKUArray[$product->getSku()], 1); | |
echo $product->getSku().' Updated successfully.'; | |
break; | |
} | |
} | |
protected function _createCSVDataArray() { | |
$this->_readcsvfile($this->_fileName); | |
foreach ($this->_csvArray as $key => $dataArr) { | |
$this->_dbSKUArray[$dataArr['Sku']] = array('meta_keyword' => '', 'meta_title' => $dataArr['Meta Title'], 'meta_description' => $dataArr['Meta Description']); | |
} | |
} | |
protected function _readcsvfile($csvfileName) { | |
$io = new Varien_Io_File(); | |
$path = Mage::getBaseDir('var') . DS . 'import'; | |
$file = $path . DS . $csvfileName; | |
$io->open(array('path' => $path)); | |
$fileName = $io->getCleanPath($path . $file); | |
$io->streamOpen($file, 'r+'); | |
$i = 0; | |
$header = NULL; | |
if (($handle = $io->streamReadCsv(',')) !== FALSE) { | |
$handle = array_map('trim', $handle); | |
$header = $handle; | |
$this->_headers = $header; | |
while (($data = $io->streamReadCsv(',')) !== FALSE) { | |
if (!$header) { | |
$header = $data; | |
} else { | |
$itemData = array_combine($header, $data); | |
$this->_csvArray[] = $itemData; | |
} | |
$i++; | |
} | |
} | |
} | |
} | |
$importObject = new ImportProductMeta(); | |
$importObject->importProductMetaStart(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment