1

I have more than 500 cms pages in my Magento store, and i want to change all meta descriptions based on a CSV file. There are two columns in my csv file:

  1. Cms Page identifier
  2. Meta description
1

Copy this code and put it on your magento root directory,You need to change your file path.

<?php   
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
ini_set('memory_limit', '600M');
ini_set('max_execution_time', 1800);
umask(0);
Mage::app('admin'); 

$fileLocation = Mage::getBaseDir('media') . DS . 'metadata.csv';
$mage_csv = new Varien_File_Csv(); //mage CSV
$data = $mage_csv->getData($fileLocation); //path to csv
$cmsData = Mage::getModel('cms/page');

foreach ($data as $_data) {
    $pageTitle = Mage::getModel('cms/page')->load($_data[0], 'identifier');
    if ($pageTitle->getPageId()) {
        $pageTitle->setMetaDescription($_data[1]);
        $pageTitle->save();
    }
}

echo 'done meta';
  • 1
    this works, but it will take 1.3 eternities for 500 pages. – Marius Jul 22 '15 at 8:09
  • @kanika it's working – user28311 Jul 22 '15 at 8:27
2

The cms pages are flat entities. This means that each cms page is stored as a row in the table cms_page.
You can write a simple php script that parses the csv file and just runs queries like this:

UPDATE `cms_page` set `meta_description` = 'YOur meta description here' where `identifier` = 'identifier_here';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.