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

Php 从Magento sitemap.xml生成中排除某些产品,php,magento,sitemap,Php,Magento,Sitemap,我需要确保Magento中生成的Sitemap.xml文件中没有一些产品 有人知道如何做到这一点吗?如果您不想在sitemap.xml中包含某些产品,请禁用这些产品您需要创建自己的模块,并更改Mage_Sitemap_Model_Sitemap::generateXml的行为以筛选包含的产品。如果您不希望通常禁用产品以将其从站点地图中删除,但仍希望它们显示在目录中并在每次搜索中找到,但仅从站点地图中隐藏它们,您可以覆盖Mage\u Sitemap\u Model\u Resource\u Cat

我需要确保Magento中生成的Sitemap.xml文件中没有一些产品


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

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

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

如果您不希望通常禁用产品以将其从站点地图中删除,但仍希望它们显示在目录中并在每次搜索中找到,但仅从站点地图中隐藏它们,您可以覆盖Mage\u Sitemap\u Model\u Resource\u Catalog\u 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版本中都是相同的

非常感谢你的帮助。Magento与我以前见过的任何建筑都不一样。现在我需要实际增强这一点,以便管理员可以从ProductMeta选项卡中选择和选项来隐藏产品。然后,在这段代码中,我可以很有希望地提取该值并构建我的ID列表。我将发布一个关于这一点的新问题,感谢您迄今为止的帮助,我们如何为缺货产品添加条件。我们只希望sitemap.xml中有库存产品