2

By default Magento does not allow the product which has 'not visibility in frontend' mode to avoid showing the product in listing and detail page. When user hit the previously loaded url, it redirects to 404 since it is not visibility in front end mode. I am in situation to load this product in its detail page only.(catalog_product_view).

I am extending Mage_Catalog_Block_Product_View to check. I am stuck now on how to get url and view page for non visibility product. kindly advice

8
  • I'm not sure what you want to achieve. You have products that are "not visible" and still want to be able to see them? Oct 1, 2014 at 11:57
  • @JulienLachal actually my need is , item should not be in listing page and only want to show item in detail page. Oct 1, 2014 at 11:59
  • but how would people be able to find them? Oct 1, 2014 at 12:02
  • @JulienLachal Doing jewellery site in which one item will have matched item called upsell collection. I extend upsell class and show the non visibility matched item.here i want to give url for non visibility item to know their details. Oct 1, 2014 at 12:05
  • Correct me if I'm wrong, but what you need is to display upsell products on specific product. Then when a customer clicks on it, they should be redirected to the upsell product page, but this products shouldn't be listed in categories nor search? Am I right? Oct 1, 2014 at 12:10

2 Answers 2

3

Don't make it too complicated, you should not need to rewrite any core files. If I understand your issue correct, you need to make the products "Visible in Catalog" but do not assign them to any category.

7
  • fentabulous ! yes this will work. My solution is complicated but will work for sure now. But this is the best solution ever for this issue. I AM A FOOL ! Oct 1, 2014 at 13:58
  • but if he needs to keep visibility in "not visible individually", then this will not work. Only my solution will do the trick. :) don't you have any other suggestion on that point ? Oct 1, 2014 at 14:03
  • @fab thanks now items is not shown in detail page and coming in detail page. only thing is how to restrict that item in search page ? Oct 1, 2014 at 14:06
  • change visibility to "search" Oct 1, 2014 at 14:07
  • I don't undersand "Visible in Catalog" does not make them visible in search, only "Visible in Catalog AND Search" does. Oct 1, 2014 at 14:08
1

Disclaimer : I don't understand why do you need this ? But I will give you some hint to sort out the issue.

For catalog product view page, product visibility checking is actually takes place in a helper class. Most specifically it happens in Mage_Catalog_Helper_Product. Take look on the initProduct method there. You can see that it checks for product's visibility as like this.

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

If you further investigate, we can conclude that we will get a no found page for two conditions.

  1. If the status of your product is disable.

  2. Product is not assign with current website/store that is viewing.

In order to change this default behaviour, my recommendation is to create a new attribute with name visibility_in_product_view for every product and then make it a select option with value 1 for yes and 2 for no. Now set this value to yes, for every product that you need this exception.

Now rewrite the helper class method Mage_Catalog_Helper_Product::canShow() as like this.

<?php
class Namespace_Modulename_Helper_Product extends Mage_Catalog_Helper_Product
{
    //use to check product view visibility status
    const VISIBILITY_IN_PRODUCT_VIEW_PAGE = 1;

    public function canShow($product, $where = 'catalog')
    {
        if (is_int($product)) {
            $product = Mage::getModel('catalog/product')->load($product);
        }

        /* @var $product Mage_Catalog_Model_Product */

        if (!$product->getId()) {
            return false;
        }
        if ($product->isVisibleInCatalog()) {
            if ($product->isVisibleInSiteVisibility()) {
                return true;
            } else {
                 $frontname = Mage::app()->getFrontController()->getRequest()->getModuleName();
                 $controller = Mage::app()->getFrontController()->getRequest()->getControllerName();
                 $action = Mage::app()->getFrontController()->getRequest()->getActionName();
                if ($frontname.$controller.$action == 'catalogproductview' && Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE == $product->getVisibility()) {
                    if ($product->getVisibilityInProductView() == self::VISIBILITY_IN_PRODUCT_VIEW_PAGE) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        }
        else {
            return false;
        }
    }  
}

This is the part that do the trick here

        if ($product->isVisibleInCatalog()) {
            if ($product->isVisibleInSiteVisibility()) {
                return true;
            } else {
                $frontname = Mage::app()->getFrontController()->getRequest()->getModuleName();
                 $controller = Mage::app()->getFrontController()->getRequest()->getControllerName();
                 $action = Mage::app()->getFrontController()->getRequest()->getActionName();
                if ($frontname.$controller.$action == 'catalogproductview' && Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE == $product->getVisibility()) {
                    if ($product->getVisibilityInProductView() == self::VISIBILITY_IN_PRODUCT_VIEW_PAGE) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        }
        else {
            return false;
        }

Here first it check whether product is enabled or not. If enabled, it will check whether product is visible or not. If product is not visible, then it will check whether not visible individually is the real cause the previous condition. If that is yes, then we will check whether exception is provided for view page by inspecting the status of our custom attribute. If exception enabled, then it will show in product view page.

Hence problem solved

14
  • thanks.Doing jewellery site in which one item will have matched item called upsell collection. I extend upsell class and shown the non visibility matched item.here i want to give url for non visibility item to show their detail page Oct 1, 2014 at 12:21
  • 1
    yes. Make a custom attribute to do this. Then set that custom attribute to yes for all those matched products. It will be the most elegant way. Then rewrite the above helper class. Go through the answer. You will get much more idea. Ask me if you have any doubts Oct 1, 2014 at 12:25
  • $product->getVisibilityInProductView() is custom function ? Oct 1, 2014 at 12:25
  • its a magic method. It is equivalent to $product->getData('visibility_in_product_view'). In order to work it properly you need to create a custom attribute with attribute code visibility_in_product_view. Oct 1, 2014 at 12:27
  • 1
    check @fab answer. It will work. use my answer only if you need to set visibility to "not visible individually" and yet you need to do some exception for some product. Oct 1, 2014 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.