I am not sure what exactly you are looking for but as per magecomp url you have given, you may apply following solution.
File: etc\frontend\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Controller\Category\View">
<plugin name="redirect_single_category_product" type="[Vendor]\[Module]\Plugin\CategoryView" sortOrder="10" />
</type>
</config>
File: Plugin\CategoryView.php
<?php
namespace [Vendor]\[Module]\Plugin;
class CategoryView
{
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResponseInterface $response,
\Magento\Framework\App\ActionFactory $actionFactory,
\Magento\Catalog\Model\ProductRepository $productRepository
)
{
$this->request = $request;
$this->storeManager = $storeManager;
$this->_response = $response;
$this->actionFactory = $actionFactory;
$this->productRepository = $productRepository;
}
public function afterExecute(
\Magento\Catalog\Controller\Category\View $subject,
$result
)
{
// replace your condition here
if(1)
{
// for example take first product
$productId = 1;
$current_product = $this->productRepository->getById($productId, false, $this->storeManager->getStore()->getId());
$this->_response->setRedirect($current_product->getProductUrl());
$this->request->setDispatched(true);
return $this->actionFactory->create('Magento\Framework\App\Action\Redirect');
}
return $result;
}
}
This should work. Replace [Vendor], [Module] with your vendor and module name.
Let me know if you are looking for something else or specific.