0

I'm using magento 2.4.0 and trying to get information about products cross-sell by product id but I see some error in magento. getById causes my browser to crash, some very large object loading there

$this->productRepositoryInterface->getById ($productId)

I saw that it worked in previous magento versions, does anyone know how to fix it or when there will be improvements in magento?

My code:

 public function getCrosssellProductsList($productId)
    {
        $crossSellProduct = [];
        try {
            $product = $this->productRepositoryInterface->getById($productId);
            $crossSell = $product->getCrossSellProducts();

            if (count($crossSell)) {
                foreach ($crossSell as $productItem) {
                    $crossSellProduct[] = $productItem->getId();
                }
            }
        } catch (\Exception $exception) {
            $this->logger->error($exception->getMessage());
        }

        return $crossSellProduct;
    }

Your Answer

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

Browse other questions tagged or ask your own question.