在比较视图中显示已停用/已停用的产品

时间:2013-12-18 10:28:07

标签: php magento magento-1.8

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

在默认magento中,这似乎不可能,因为产品列表页以及产品详细信息页面中无法看到已禁用的产品。

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

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

现在,有人帮助我了解如何在比较视图中显示残疾产品吗?

3 个答案:

答案 0 :(得分:4)

可能要检查: 公共职能是启用

在 的magento \应用\代码\核心\法师\目录\助手\产品\ Flat.php

答案 1 :(得分:4)

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

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

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

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

我不是100%确定如果删除最后一段代码可以获得你想要的东西,但是在最基本的层面你可以改变集合来忽略你设置的状态。

答案 2 :(得分:4)

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

Atlast,我仅过滤了与此新属性Archive相关的所有产品详情,产品详情和主页。

我打算编写一个MVC操作,它会将所有产品status更改为enabled,同时触发Archivestatus = 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.
    }
}
相关问题