0

I want to know how to get visibility of product using Magento 2. I have a product that is set to "not visible individually" and want to remove it from a collection.

I have tried below methods:

$product->getVisiblility();
$product->getVisibleInCatalogStatuses();
$product->getVisibleStatuses();
$product->isVisibleInCatalog();
$product->getVisibleInSiteVisibilities();
$product->isVisibleInSiteVisibility();

But all products return the same value "1" for $product->isVisibleInCatalog visible or not.

I have reindexed via command line also and set the visibility for all stores to be not visible however still the issue persists.

  • and what's wrong with all the methods returning the same? – Philipp Sander Aug 15 '17 at 9:33
  • Well i would hope the values would change depending on visibility... – harri Aug 15 '17 at 9:34
  • aaah ok. Try reloading the product over the repository and check if the methods return correct value. – Philipp Sander Aug 15 '17 at 9:37
  • Sorry yeah bit confusing the wording after all the methods that i tried. Im not sure what you mean by reloading product over the repository however. – harri Aug 15 '17 at 9:38
  • Inject \Magento\Catalog\Api\ProductRepositoryInterface in your controller/block/service/whatever and then reload the product with $productReloaded = $this->productRepository->get($product->getSku()); – Philipp Sander Aug 15 '17 at 9:41
0

You can get it via this :

$_product->getAttributeText('visibility');

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.