7

I am trying to show a product in comparison view, which is set as status = disabled through admin panel.

In default magento, this seems not possible as the disabled products are not visible in product listing page as well as product details page.

Somehow, I managed to show the disabled products in product listing page and product details page by overriding Mage_Catalog_Helper_Product. In that I commented the following code:

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

Now, please someone help me on how to show up the disabled product even in comparison view?

Mr_Green
  • 40,727
  • 45
  • 159
  • 271

3 Answers3

4

Might want to check: public function isEnabled

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

Justin.OMC
  • 95
  • 5
  • You might want to be careful as this relies on the store using flat tables. Not all stores have this enabled for one reason or another. – James Cowie Dec 20 '13 at 21:06
4

I have taken a quick look into what block is creating the list. A good place to start would be the following file:

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

There is a function getItems that is responsible for getting the items ready to display on the front end. At the end of this function it passes the items through the visibility method:

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

Im not 100% sure if removing this final section of code gets you what you want, but at a very basic level you can change the collection to ignore the status you have set.

James Cowie
  • 464
  • 3
  • 5
  • If I comment/remove the above code, I can get `simple products` in my compare section. I mean that code is for enabling `simple products` not `discontinued/disabled` products. I am 100% sure because I have done this recently in my project :) – Mr_Green Dec 21 '13 at 05:44
4

After searching for a long time and failing to extract a solution from mage core files, I created an attribute which does the same as status attribute. I named that attribute as Archive (Yes/No). This new attribute will justify whether a product is discontinued or not.

Atlast, I filter all my product listing, product details and home page related to this new attribute Archive only.

I am planning to write a MVC action, which will change all the products status as enabled and at the same time triggering the Archive as yes for the status = disabled products. I will share the code here soon.

Code:

Write a dummy controller which runs the following code when the url is called:

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.
    }
}
Mr_Green
  • 40,727
  • 45
  • 159
  • 271