7

我正在尝试在比较视图中显示产品,该视图是status = disabled通过管理面板设置的。

在默认的 magento 中,这似乎是不可能的,因为禁用的产品在产品列表页面产品详细信息页面中不可见。

不知何故,我设法通过覆盖在产品列表页面产品详细信息页面Mage_Catalog_Helper_Product中显示禁用的产品。在那我评论了以下代码:

    // if (!$this->canShow($product)) {
    //     return false;
    // }

现在,请有人帮助我如何在比较视图中显示禁用的产品?

4

3 回答 3

4

可能要检查:公共功能 isEnabled

在 magento\app\code\core\Mage\Catalog\Helper\Product\Flat.php

于 2013-12-20T20:13:25.013 回答
4

我快速查看了创建列表的块。一个好的起点是以下文件:

app / code / core / Mage / Catalog / Block / Product / Compare / List.php

有一个函数 getItems 负责让项目准备好在前端显示。在此函数的末尾,它通过可见性方法传递项目:

Mage::getSingleton('catalog/product_visibility')
                ->addVisibleInSiteFilterToCollection($this->_items);

我不是 100% 确定删除这最后一段代码是否能得到你想要的,但在一个非常基本的级别上,你可以更改集合以忽略你设置的状态。

于 2013-12-20T21:09:23.063 回答
4

在搜索了很长时间并且未能从法师核心文件中提取解决方案后,我创建了一个与属性相同的status属性。我将该属性命名为Archive(是/否)。这个新属性将证明产品是否停产。

Atlast,我只过滤与此新属性相关的所有产品列表、产品详细信息和主页Archive

我计划编写一个 MVC 操作,它将更改所有产品statusenabled同时触发产品的Archiveas yes status = disabled。我很快就会在这里分享代码。

代码

编写一个虚拟控制器,在调用 url 时运行以下代码:

public function updateproductsAction() {
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

    $collectionConfigurable = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            ->addAttributeToFilter('entity_id', array('gt' => 0));      // This line should be removed to affect all the configurable products. (to avoid execution time-out)

    echo 'Total are ' . count($collectionConfigurable) . '<br/>';
    $i = 1;                         
    foreach($collectionConfigurable as $p) {
        $product = Mage::getModel('catalog/product')->load($p->getId());
        $product->save();
        echo $i++ . ') The product Id with ' . $p->getId() . " is done...." . "<br/>";  // if the execution time-out occurs, note down the last product id and change the value above in addAttributeToFilter. so the execution runs from the last stopped product.
    }
}
于 2013-12-22T06:31:47.000 回答