2

Working on a site that has multiple stores and their own homepages. Im trying to update all of these homepages with new data via a data-upgrade script.

Here what i have so far:

 $stores = Mage::app()->getStores();

foreach ($stores as $store){   
    Mage::app()->setCurrentStore($store->getStoreId());   
    $page = Mage::getModel('cms/page')->load('homepage-2012');    
    $page_content = file_get_contents(__DIR__ . '/markup-0.0.2/homepage/content.html');
    $page->setContent($page_content)
        ->setRootTemplate('one_column_notcontained')
        ->save();
}   
unset($page_content,$page,$stores);

The problem is the pages content and root template aren't updating on the stores.

I have used breakpoints to check the store ids are correct and the loop is working as it should and it seems to be doing what it should -> getting the store id, setting that store id as currentStore being used and then loading the cms homepage related to that store is and using the identifier set.

Any ideas why this might not be working?

Cheers

  • are you want data installer or installer? – Amit Bera Sep 9 '14 at 11:02
  • I just want to update the content of the CMS pages so at the moment its in the form of a data-upgrade. The upgrade proccess is working and i can see the version numbers change from 0.0.1 to 0.0.2 in core_resource – Tom Burman Sep 9 '14 at 11:08
  • then what the issue – Amit Bera Sep 9 '14 at 11:09
  • That the script isn't actually doing the upgrade, it runs with no errors hence why the resource updates to latest version number but the actual function of the script isn't working – Tom Burman Sep 9 '14 at 11:11
2

The first thing that I noticed is that your loading is wrong (not discussing a fact of loading in the loop).

$page = Mage::getModel('cms/page')->load('homepage-2012');    

If load method is used w/ a single argument it is supposed to be an entity ID. If you would like to use page identifier for loading the second argument has to be passed to the method specifying the property which has to be used:

$page = Mage::getModel('cms/page')->load('homepage-2012', 'identifier');    
  • Thanks, i updated the code to include what you said, still doesn't work though :/ – Tom Burman Sep 9 '14 at 11:17
  • And you sure $page->getId() returns value after the load? Because you told that if did before while it actually can't be true. – user487772 Sep 9 '14 at 11:43

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.