I just want to load the product if that is available on the current website else not on the custom page. here is my code which is not working product still loading if that not exists in the current store...
public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager,\Magento\Catalog\Api\ProductRepositoryInterface $productRepository) {
$this->storeManager = $storeManager;
$this->productRepository = $productRepository;
}
public function getProduct($product_id){
try{
return $this->productRepository->getById($product_id,false,$this->storeManager->getStore()->getId());
}catch (\Exception $ex){
$this->log($ex->getMessage());
}
}