0

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.

2
  • you want visible and not visible both products? Commented Dec 4, 2017 at 17:00
  • Yes. But only those not visible where the parent product is visible and enabled.
    – alobeejay
    Commented Dec 4, 2017 at 17:07

1 Answer 1

0

Change your setVisibility() function with below code.

$collection->setVisibility(null);

It should work

1
  • This returns a completely empty collection.
    – alobeejay
    Commented Dec 5, 2017 at 7:27

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.