Search code examples
magentocontent-management-systemmagento-1.5

Magento. Save static block from custom form. Can't save stores


I have a task:

save from frontend static block.

The code which i tried was

public function savebannerAction(){
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $post = $this->getRequest()->getPost();
    $block_id = $post['block_id'];
    $content = $post['content'];    

    $data = Mage::getModel('cms/block')->load($block_id)->getData();            
    $data['content'] = $content;
    Mage::getModel('cms/block')->load($block_id)->setData($data)->save();       
    $this->_redirectUrl($_SERVER['HTTP_REFERER']);
}

And simply

public function savebannerAction(){
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $post = $this->getRequest()->getPost();
    $block_id = $post['block_id'];
    $content = $post['content'];    
    Mage::getModel('cms/block')->load($block_id)->setContent($content)->save();         
    $this->_redirectUrl($_SERVER['HTTP_REFERER']);
}

But in both ways what I get is: Content is saved, BUT stores are droped to empty. So block removed from currently selected shops. Or I should also include form_key into data?


Solution

  • The thing is that saving function expects 'stores' key, but not 'store_id'.

    $model->setData('stores',$model['store_id']);