在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
{
}
答案 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>