I have added few products in cross-sells but some are visible and some are not visible in the UI(frontend).
I referred to a Magento bug that only 2 items were visible in the backend
Is this related to Magento 2 bug, How can I solve this bug.
Catalog/Model/ProductLink/CollectionProvider.php
class CollectionProvider extends \Magento\Catalog\Model\ProductLink\CollectionProvider
{
/**
* @var CollectionProviderInterface[]
*/
protected $providers;
/**
* @var ConverterPool
*/
protected $converterPool;
/**
* @param ConverterPool $converterPool
* @param CollectionProviderInterface[] $providers
*/
public function __construct(ConverterPool $converterPool, array $providers = [])
{
$this->converterPool = $converterPool;
$this->providers = $providers;
}
/**
* Get product collection by link type
*
* @param \Magento\Catalog\Model\Product $product
* @param string $type
* @return array
* @throws NoSuchEntityException
*/
public function getCollection(\Magento\Catalog\Model\Product $product, $type)
{
if (!isset($this->providers[$type])) {
throw new NoSuchEntityException(__("The collection provider isn't registered."));
}
$products = $this->providers[$type]->getLinkedProducts($product);
$converter = $this->converterPool->getConverter($type);
$sorterItems = [];
foreach ($products as $item) {
$itemId = $item->getId();
$sorterItems[$itemId] = $converter->convert($item);
$sorterItems[$itemId]['position'] = $sorterItems[$itemId]['position'] ?? 0;
}
usort($sorterItems, function ($itemA, $itemB) {
$posA = intval($itemA['position']);
$posB = intval($itemB['position']);
return $posA <=> $posB;
});
return $sorterItems;
}
}
This was the fix for only a few products showing in the backend(admin panel).
How can I fix the same issue for frontend? All cross-sell products are visible in the backend now but not visible in the frontend(UI).