2

我需要确保少数产品不在 Magento 中生成的 Sitemap.xml 文件中。

任何人都知道如何做到这一点?

4

3 回答 3

2

如果您不希望通常禁用产品以将其从站点地图中删除,但仍希望它们显示在目录中并在每次搜索时找到,但仅将它们从站点地图中隐藏,您可以Mage_Sitemap_Model_Resource_Catalog_Product::getCollection()像这样覆盖:

public function getCollection($storeId)
{
    $products = array();

    $store = Mage::app()->getStore($storeId);
    /* @var $store Mage_Core_Model_Store */

    if (!$store) {
        return false;
    }

    $urCondions = array(
        'e.entity_id=ur.product_id',
        'ur.category_id IS NULL',
        $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()),
        $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1),
    );
    $this->_select = $this->_getWriteAdapter()->select()
        ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName()))
        ->join(
            array('w' => $this->getTable('catalog/product_website')),
            'e.entity_id=w.product_id',
            array()
        )
        ->where('w.website_id=?', $store->getWebsiteId())
        // --- exclude single product by its entity_id
        ->where('e.entity_id<>152')
        // --- exclude multiple products by their entity_id's
        // ->where('e.entity_id NOT IN (?)', array(152, 156))
        ->joinLeft(
            array('ur' => $this->getTable('core/url_rewrite')),
            join(' AND ', $urCondions),
            array('url' => 'request_path')
        );

    $this->_addFilter($storeId, 'visibility', Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds(), 'in');
    $this->_addFilter($storeId, 'status', Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(), 'in');

    $query = $this->_getWriteAdapter()->query($this->_select);
    while ($row = $query->fetch()) {
        $product = $this->_prepareProduct($row);
        $products[$product->getId()] = $product;
    }

    return $products;
}

基于 Magento CE 1.7.0.2 代码,但是 afaik 的原理在所有 Magento 版本中都是相同的。

于 2013-06-07T08:10:02.433 回答
0

如果您不想在 sitemap.xml 中包含某些产品,请禁用这些产品

于 2013-06-07T04:31:31.223 回答
0

您需要创建自己的模块,并更改Mage_Sitemap_Model_Sitemap::generateXml过滤包含产品的行为。

于 2013-06-07T08:09:52.753 回答