Model/Catalog/UrlFinder.php
public function fetchFor($product)
    {
        $product = $this->getScopedProduct($product);

        if ($product->getVisibility() == \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE &&
            $product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
        ) {
            $parentId = $this->getFirstParentId($product);
            if (isset($parentId)) {
                /** @var \Magento\Catalog\Model\Product $parentProduct */
                $parentProduct = $this->productRepository->getById($parentId, false, $product->getStoreId());
                return $parentProduct->getProductUrl();
            }
        }
        return $product->getProductUrl();
    }
public function fetchFor($product)
    {
        $product = $this->getScopedProduct($product);

        if ($product->getVisibility() == \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE &&
            $product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
        ) {
            $parentId = $this->getFirstParentId($product);
            if (isset($parentId)) {
                /** @var \Magento\Catalog\Model\Product $parentProduct */
                $parentProduct = $this->productRepository->getById($parentId, false, $product->getStoreId());
                return $parentProduct->getProductUrl();
            }
        }
        return $product->getProductUrl();
    }
public function fetchFor ( $ product ) { $ product = $ this -> getScopedProduct ( $ product ) ; if ( $ product -> getVisibility ( ) == \ Magento \ Catalog \ Model \ Product \ Visibility :: VISIBILITY_NOT_VISIBLE && $ product -> getTypeId ( ) == \ Magento \ Catalog \ Model \ Product \ Type :: TYPE_SIMPLE ) { $ parentId = $ this -> getFirstParentId ( $ product ) ; if ( isset ( $ parentId ) ) { /** @var \Magento\Catalog\Model\Product $parentProduct */ $ parentProduct = $ this -> productRepository -> getById ( $ parentId , false , $ product -> getStoreId ( ) ) ; return $ parentProduct -> getProductUrl ( ) ; } } return $ product -> getProductUrl ( ) ; }
Fetch a URL for a product depending on its visibility and type.

@param \Magento\Catalog\Model\Product $product

@return string
@throws \Magento\Framework\Exception\NoSuchEntityException
Fetch a URL for a product depending on its visibility and type .