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? Dec 4 '17 at 17:00
  • Yes. But only those not visible where the parent product is visible and enabled.
    – alobeejay
    Dec 4 '17 at 17:07
0

Change your setVisibility() function with below code.

$collection->setVisibility(null);

It should work

1
  • This returns a completely empty collection.
    – alobeejay
    Dec 5 '17 at 7:27

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.