Using the below code or equivelant I want to get all products regardless of visiblity or status etc. This however does not seem to return products that are "Not Visible Individually".

$category = $this->categoryFactory->create()->load($catid);
$collection = $this->_productCollectionFactory->create();

How can this be achieved?

1 Answer 1


Try this below code :

My Advice is please don't use objectManager

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $current_category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');

$categoryId = NULL;
if($current_category) {
    $categoryId = $current_category->getEntityId();

    $category = $objectManager->get('Magento\Catalog\Model\CategoryFactory')->create()->load($categoryId);
    $collection = $objectManager->get('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create();
    $collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
    echo "<pre>";print_r($collection->getData());

return $collection;
  • did u get the result?
    – chris
    Aug 9, 2018 at 13:15
  • Just tried it however didn't seem to work again i did try something like that earlier and same thing happened.
    – harri
    Aug 9, 2018 at 13:41
  • Ill just double check everyhing
    – harri
    Aug 9, 2018 at 13:42
  • Even filtering to: $collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE); shows no products when i can clearly see about 90 products not visible in my category it is strange.
    – harri
    Aug 9, 2018 at 13:52

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.