Magento:覆盖Sitemap模型类功能

时间:2014-05-05 08:52:12

标签: magento model sitemap

在Magento 1.8中,我希望覆盖Sitemap/Module/Resource/Cms/Page.php的函数,getCollection($storeId)函数从生成的站点地图中删除特定页面。

但有些东西不起作用。

local/Extender/Sitemap/etc/config.xml我有:

<?xml version="1.0"?>
<config>
    <modules>
        <Extender_Sitemap>
            <version>1.0.1</version>
        </Extender_Sitemap>
    </modules>
    <global>
        <modules>
            <sitemap_resource>
                <rewrite>
                    <sitemap_cms_page>Extender_Sitemap_Model_Resource_Cms_Page</sitemap_cms_page>
                </rewrite>
            </sitemap_resource>
        </modules>
    </global>
</config>

我的getCollection()功能位于local/Extender/Sitemap/Model/Resource/Cms/Page.php

class Extender_Sitemap_Model_Resource_Cms_Page extends Mage_Core_Model_Resource_Db_Abstract
{
    public function getCollection($storeId)
    {
        $pages = array();

        $select = $this->_getWriteAdapter()->select()
            ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName(), 'identifier AS url'))
            ->join(
                array('store_table' => $this->getTable('cms/page_store')),
                'main_table.page_id=store_table.page_id',
                array()
            )
            ->where('main_table.identifier NOT IN (?)', array('homepage')) 
            ->where('main_table.is_active=1')
            ->where('store_table.store_id IN(?)', array(0, $storeId));

        $query = $this->_getWriteAdapter()->query($select);

        while ($row = $query->fetch()) {
            if ($row['url'] == Mage_Cms_Model_Page::NOROUTE_PAGE_ID) {
                continue;
            }
            $page = $this->_prepareObject($row);
            $pages[$page->getId()] = $page;
        }

        return $pages;
    }
}

我在etc/modules/Extender_All.xml中激活了模块:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Extender_Sitemap>
            <active>true</active>
            <codePool>local</codePool>
        </Extender_Sitemap>
    </modules>
</config>

我还有以下空白页面:

local/Extender/Sitemap/Model/Sitemap.php

class Extender_Sitemap_Model_Sitemap extends Mage_Core_Model_Abstract
{

}

local/Extender/Sitemap/Model/Resource/Sitemap.php

class Extender_Sitemap_Model_Resource_Sitemap extends Mage_Core_Model_Resource_Db_Abstract
{

}

1 个答案:

答案 0 :(得分:2)

app/code/local/Yourcompany/Yourmodule/etc/config.xml

中正确覆盖您覆盖的班级
<config>
    <global>
        <models>
            <sitemap_resource>
                <rewrite>
                    <cms_page>Yourcompany_Yourmodulename_Sitemap_Model_Resource_Cms_Page</cms_page>
                </rewrite>
            </sitemap_resource>
        </models>
    </global>
</config>

然后在app/code/local/Yourcompany/Yourmodule/Sitemap/Model/Resource/Cms/Page.php中你必须像这样扩展:

class Yourcompany_Yourmodulename_Sitemap_Model_Resource_Cms_Page extends Mage_Sitemap_Model_Resource_Cms_Page { ... }

类似于etc / modules / Yourcompany_Yourmodule.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Yourcompany_Yourmodule>
            <active>true</active>
            <codePool>local</codePool>
        </Yourcompany_Yourmodule>
    </modules>
</config>