Magento – how to hide a product programmatically on frontend without disabling it, using an event or overriding core classes

magento-1.8productproduct-collectionproducts-management

I'm trying to "hide" a product for a specific country without disabling it from the store.
For now i used two events one is for updating collection on product listing using event (catalog_block_product_list_collection) and the other is before load product page (catalog_product_load_before).

Now it works fine, but the issue is that what if the store owner likes to show the product as featured product on home page or other using a block or else, the above process won't work.

I prefer using event but it doesn't seem to be a reliable solution but before i proceed with overriding core classes, I'd want to be sure that this is the best way.

please guide.
really appreciate your time.

thanks,

Best Answer

Why don't you create an override of Mage_Catalog_Model_Product and add some logic into the isVisibleInCatalog() function to stop the product showing up in the category?

/**
 * Check Product visilbe in catalog
 *
 * @return bool
 */
public function isVisibleInCatalog()
{
    // Custom logic to disable product
    if(LOGICHERE) {
        return false;
    }
    return in_array($this->getStatus(), $this->getVisibleInCatalogStatuses());
}

This will then cause initProduct() within the product helper to return false which should in turn stop it from being disabled.

This is untested but the theory should work.

Related Topic