Skip to main content
added 2 characters in body
Source Link
fmsthird
  • 4.6k
  • 4
  • 18
  • 42

Try this one:
null will be returnreturned if the object is null.

public function canShow($product, $where = 'catalog')
    {
        if (is_int($product)) {
            try {
                $product = $this->productRepository->getById($product);
            } catch (NoSuchEntityException $e) {
                return false;
            }
        } else {
                return $product ? $product->getId() : null;
        }
        return $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility();
    }

Try this one:
null will be return if the object is null.

public function canShow($product, $where = 'catalog')
    {
        if (is_int($product)) {
            try {
                $product = $this->productRepository->getById($product);
            } catch (NoSuchEntityException $e) {
                return false;
            }
        } else {
                return $product ? $product->getId() : null;
        }
        return $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility();
    }

Try this one:
null will be returned if the object is null.

public function canShow($product, $where = 'catalog')
    {
        if (is_int($product)) {
            try {
                $product = $this->productRepository->getById($product);
            } catch (NoSuchEntityException $e) {
                return false;
            }
        } else {
                return $product ? $product->getId() : null;
        }
        return $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility();
    }
Source Link
fmsthird
  • 4.6k
  • 4
  • 18
  • 42

Try this one:
null will be return if the object is null.

public function canShow($product, $where = 'catalog')
    {
        if (is_int($product)) {
            try {
                $product = $this->productRepository->getById($product);
            } catch (NoSuchEntityException $e) {
                return false;
            }
        } else {
                return $product ? $product->getId() : null;
        }
        return $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility();
    }