---
title: "How to Get Cross Sell Products Collection using Root Script in Magento 2?"
url: "https://magecomp.com/blog/get-cross-sell-products-collection-using-root-script-magento-2/"
date: "2023-02-17T11:57:29+00:00"
modified: "2025-02-13T12:33:05+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 282
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Learn How to Get Cross Sell Products Collection using Root Script in Magento 2"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2 : How to Add New Column In The Customer Grid"
    url: "https://magecomp.com/blog/magento-2-add-new-column-customer-grid/"
  - title: "Steps to Add Product Image ALT Text to All Product Images in Magento 2"
    url: "https://magecomp.com/blog/set-product-name-as-default-alt-text-to-product-images-magento-2/"
  - title: "Ultimate Guide to the Best Magento 2 Extensions for 2026"
    url: "https://magecomp.com/blog/best-magento-2-extensions/"
---

# How to Get Cross Sell Products Collection using Root Script in Magento 2?

_Published: February 17, 2023_  
_Author: Dhiren Vasoya_  

![How to Get Cross Sell Products Collection using Root Script in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/02/How-to-Get-Cross-Sell-Products-Collection-using-Root-Script-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

Today I am here with another solution, How to Get Cross Sell Products Collection using Root Script in Magento 2?
To boost sales, website owners can display Cross-sell, Up-sell, and related products to customers. Learn [**How to Setup Cross-Sell, Up-Sell, and Related products in Magento 2**](https://magecomp.com/blog/setup-cross-sell-up-sell-and-related-products-in-magento-2/).
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-3.webp)](https://magecomp.com/services/hire-magento-programmer/)

Cross-sell products are displayed with tags like “more choices”, “people also buy”, etc. Cross-sell products are displayed in the shopping cart before checkout. If you want to get the collection of cross-selling products in Magento 2, you can get it using the root script.
Let’s take a closer look at How to Get Cross Sell Products Collection using Root Script in Magento 2?
## Steps to Get Cross Sell Products Collection using Root Script in Magento 2:
**Step 1:** Create a root script for cross-sell product collection as follows.
```
<?php

use MagentoFrameworkAppInterface;

try
{
   require '../app/bootstrap.php';
}
catch (Exception $e)
{
    echo 'Autoload error: ' . $e->getMessage();
    exit(1);
}
try
{
	$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
	$objectManager = $bootstrap->getObjectManager();
	$appState = $objectManager->get('MagentoFrameworkAppState');
	$appState->setAreaCode('frontend');
        $productId = 3; // Product Id
        $crossSellProduct = [];
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $product = $objectManager->create('MagentoCatalogApiProductRepositoryInterface')->getById($productId);
        $crossSell = $product->getCrossSellProducts();
        if (count($crossSell))
        {
                foreach ($crossSell as $productItem)
                {
                     $crossSellProduct[] = $productItem->getSku() . '<br />';
                     print_r($crossSellProduct);
                }
        }
}
catch(Exception $e)
{
    print_r($e->getMessage());
}
```

## [![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-3.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Conclusion:
Therefore, the above method can effortlessly help you get a collection of cross-selling products in Magento 2. If you cannot get the desired results, let me know through the comment section. Share the tutorial with your friends, and stay in touch with us for more Magento 2 solutions.
[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-2.webp)](https://magecomp.com/magento-malware-removal.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/get-cross-sell-products-collection-using-root-script-magento-2/](https://magecomp.com/blog/get-cross-sell-products-collection-using-root-script-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-12 11:10:04 UTC_  
