1

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

https://github.com/magento/magento2/issues/13720

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).

  • If you are working with configurable products, check if their Stock Status attribute are up to date and also the simple products. – Jonathan Ribas Sep 9 '19 at 17:37
0

Please verify with below points :

check stock options - check your stock availability is 'In stock' or not...

clear cache

reindex data -

check xml files - may be something wrong with your xml file.

| improve this answer | |
0

First make sure

All Product Visible (visibility set to Catalog and Search )

All Products Status Enable and In stock

and if above is OK then run index command

php bin/magento indexer:reindex
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.