0

I have enabled my products visibility for both list page and search. But when I use

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

the products does not displayed.

What does addVisibleInSiteFilterToCollection do?

Thanks

EDIT

I have installed a module. I think that module checks the products visibility with function addVisibleInSiteFilterToCollection. But no products are displayed. I have checked my all products are visible in both catalog and search. I am curious what exactly this function does? Because when I comment this function I can see my products.

1

What happens in the function addVisibleInSiteFilterToCollection is that the appropriate visibility filters are added to the collection.

When calling addVisibleInSiteFilterToCollection you need to pass in a collection. This collection then gets used as follows.

$collection->setVisibility($this->getVisibleInSiteIds());

The function getVisibleInSiteIds returns an array containing the constants for each type of visibility.

return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH);

Now the function setVisibility us slightly more complex. What it does is set these values to a protected array of all collection limitations and then sets all limitations against the collection.

$this->_productLimitationFilters['visibility'] = $visibility;
$this->_applyProductLimitations();

But what this really boils down to is simply adding a filter to the collection.

if (isset($filters['visibility']) && !isset($filters['store_table'])) {
    $conditions[] = $this->getConnection()
        ->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
}
0

Puiysh,Please use the below

$collection->setVisibility(Mage::getSingleton('catalog/product_visibility') ->getVisibleInSiteIds());

I Suggestion please set current product collection Visibility using ;

Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds();

Which will only filter ('Catalog, Search') and ('Search') visibility status Products

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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