Skip to main content

Magento2 - Get Childproducts not visible individually in collection

Source Link
alobeejay
  • 467
  • 7
  • 18

Magento2 - Get Childproducts not visible individually in collection

I have the following code to get my product collection:

$collection = $this->_productCollectionFactory->create();
$collection->setOrder('id', 'ASC');
$collection->addAttributeToSelect('*');
$collection->addWebsiteFilter($this->_storeManager->getWebsite()->getId());
$collection->addAttributeToFilter('status', ['in' => $this->_productStatus->getVisibleStatusIds()]);
$collection->setVisibility($this->_productVisibility->getVisibleInSiteIds());
$collection->addAttributeToFilter('type_id', array('neq' => 'bundle'));
$collection->addAttributeToFilter('type_id', array('neq' => 'configurable'));
$collection->addAttributeToFilter('type_id', array('neq' => 'grouped'));

I need included in this collection all child products that are set to "Not visible individually" where the parents are enabled and set to visible. Currently when the product is set to not visible it does not show up.