Home » Php » php – Show deactivated/disabled products in comparison view

php – Show deactivated/disabled products in comparison view

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

How to&Answers:

Might want to check:
public function isEnabled

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

Answer:

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.

Answer:

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.
    }
}