Magento: Display disabled products on frontend [cl

2019-08-28 18:32发布

问题:

I want to show disabled products on front end. But how can I do it??

Although I don't want them to be appeared in catalog or search, but I do want them to be appeared when accessed by direct url saying "Product is Disabled".

Right now view.phtml in catalog/product is not triggering and giving a 404 page.

How can I do this.

回答1:

Try this one for only disabled products within a category

$products = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
    'status',
    array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
);

Status Enabled = 1 and Status Disabled = 2

$products = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
    'status',
    array('eq' => '2')
);


回答2:

Instead of disabling a product, just remove it from the categories, set it out of stock, set it visible only in catalog, and add a new yes/no attribute called 'is_discontinued' (or something like that). Then, in the product view page check the value of that attribute. If it's 1 the display your message Product is disabled. This is how I used to do it and it worked just fine.