0

Ok so been trying for a couple of days now, I have written a small module to include a dropdown for CMS PAGES in magento.

The dropdown is to allow me to include and exclude pages from a sitemap.

So my scripts are as such: /app/code/local/Damian/CMS/etc/config.xml

<?xml version="1.0"?>
<config>
     <modules>
        <damian_cms>
            <version>0.1.0</version>    <!-- Version of module -->
        </damian_cms>
    </modules>
    <global>
        <models>
            <damiancms>
                <class>Damian_CMS_Model</class>
            </damiancms>
        </models>
        <events>
            <adminhtml_cms_page_edit_tab_content_prepare_form>
                <observers>
                    <damian_page_edit_tab_content>
                        <type>singleton</type>
                        <class>Damian_CMS_Model_Observer</class>
                        <method>cmsField</method>
                    </damian_page_edit_tab_content>
                </observers>
            </adminhtml_cms_page_edit_tab_content_prepare_form>


<cms_page_prepare_save>
    <observers>
        <damian_cms_save_page>
            <type>singleton</type>
            <class>Damian_CMS_Model_Observer</class>
            <method>savePage</method>
        </damian_cms_save_page>
    </observers>
</cms_page_prepare_save>

<cms_page_save_after>
    <observers>
        <damian_cms_save_page_after>
            <type>singleton</type>
            <class>Damian_CMS_Model_Observer</class>
            <method>savePage</method>
        </damian_cms_save_page_after>
    </observers>
</cms_page_save_after>


        </events>


<!--         <resources>
                <setup>
                    <module>Damian_CMS</module>
                                <class>Damian_CMS_Model_Resource_Mysql4_Setup</class>
                </setup>
                        <connection>
            <use>core_setup</use>
        </connection>
        </resources> -->

    <resources>  
        <cms_setup>
            <setup>
                <module>damiancms</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </cms_setup>
        <cms_write>
            <connection>
                <use>core_write</use>
            </connection>
        </cms_write>
        <cms_read>
            <connection>
                <use>core_read</use>
            </connection>
        </cms_read>
    </resources>



    </global>
</config>

/app/code/local/Damian/CMS/Model/Observer.php

<?php

class Damian_CMS_Model_Observer extends Varien_Event_Observer
{
    public function cmsField($observer)
    {
        $model = Mage::registry('cms_page');
        $form = $observer->getForm();
        $fieldset = $form->addFieldset('damian_content_fieldset', array('legend'=>Mage::helper('cms')->__('Include in Sitemap'),'class'=>'fieldset-wide'));


$fieldset->addField('cms_sitemap', 'select', array(
          'label'     => Mage::helper('cms')->__('Select'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'cms_sitemap',
          'onclick' => "",
          'onchange' => "",
          'value'  => '1',
          'values' => array('-1'=>'Please Select..','1' => 'Yes','2' => 'No'),
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => '<small>Select "No" to not include in sitemap</small>',
          'tabindex' => 1
        ));
    }


public function cms_page_prepare_save(Varien_Event_Observer $observer) {
        $requestParams = $observer->getRequest()->getParams(); 
        $page = $observer->getPage();
        $page->setData('cms_sitemap',$requestParams); // save the request data to the page model. This will not intevere with normal model functionality as it will be ignored by anything else.
        echo "is this working?";
        print_r("test before save:::: ".$this);

        return $this;
    }


public function cms_page_save_after(Varien_Event_Observer $observer) { 
        $page = $observer->getObject();
        $requestParams = $page->getRequestParams();
           echo "is working?";

        print_r("test after save:::: ".$this);
                return $this;
    }

}
?>

/app/code/local/Damian/CMS/sql/cms_setup/mysql4-install-0.1.0.php

<?php
$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */

echo 'Running This Upgrade: '.get_class($this)."\n <br /> \n";
die("Exit for now");    

$installer->startSetup();

$conn = $installer->getConnection();

$installer->getConnection()->addColumn($installer->getTable('cms_page'),'cms_sitemap', array(
        'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
        'nullable'  => false,
        'length'    => 255,
        'comment'   => '1= yes 2=no'
        ));   




$installer->endSetup();

/app/etc/modules/Damian_CMS.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Damian_CMS>
            <active>true</active>
            <codePool>local</codePool>
            <version>0.1.0</version>
        </Damian_CMS>
    </modules>
</config>

Ok so i think that is everything, this is my first module and your help is much appreciated...

1
  • Anybody out there who can help? Commented Dec 17, 2015 at 8:33

1 Answer 1

0

For now i have manually updated the CMS_PAGE table and played around with updating the data, which it works, I just had to add this to the first link in the observer (class Damian_CMS_Model_Observer extends Varien_Event_Observer)

But i am still not sure how to do an update script, anyone can help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.