php - 从 Magento sitemap.xml 生成中排除某些产品

标签 php magento sitemap

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

有人知道如何做到这一点吗?

最佳答案

如果您通常不想禁用产品以将其从站点地图中删除,但仍希望它们显示在目录中并在每次搜索时找到,但仅在站点地图中隐藏它们,则可以覆盖 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 代码,但据我所知,所有 Magento 版本的原理都是相同的。

关于php - 从 Magento sitemap.xml 生成中排除某些产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16972558/

相关文章:

seo - 是否有必要为SEO显示站点地图

seo - 向 sitemap.xml 添加类别是否有效?

javascript - PHP 将文件中的图像添加到产品页面

php - 将 Magento 的 var 目录放入 RAM

angularjs - 将动态站点地图添加到 angularJS 应用程序

magento - 在 Amazon EC2 上不断收到 redis 错误

php - Magento 获取属性

php - SQL 行回显到 Javascript 时出现问题,错误 SyntaxError : unterminated string literal

php - 在 codeigniter 中显示来自两个表的数组数据

javascript - 数据没有进入 MySql 数据库