Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement