up sell – Magento2, how you can use the object manager to get an upsell product on the category list

Note: First, it is not recommended to use the Object Manager directly on a file. Use only the Magento standard

The following code is only intended to show how we can easily get the upsell product on the category list page.

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category');
$categoryId = $category->getId();
$categoryFactory = $objectManager->get('MagentoCatalogModelCategoryFactory');

$category = $categoryFactory->create()->load($categoryId);
$categoryProducts = $category->getProductCollection()
                         ->addAttributeToSelect('*');

foreach ($categoryProducts as $product) {
    $current_product_id = $product->getId();
    $current_product = $objectManager->create('MagentoCatalogModelProduct')->load($current_product_id);
    if ($current_product) {
    $upSellProducts = $current_product->getUpSellProducts();

    if (!empty($upSellProducts)) {
        foreach ($upSellProducts as $upSellProduct) {
                $productId = $upSellProduct->getId();
                $product = $objectManager->create('MagentoCatalogModelProduct')->load($productId); 
                echo 'Upsell Product name---'.$product->getName().'

'; } } } }

[GET] Home work and digital marketing for seniors [PLR] FE + UPSELL

FE:

http://launch.plrsalesfunnels.net/work-at-home-digital-marketing-for-seniors

UPSELL:

http://launch.plrsalesfunnels.net/work-at-home-digital-marketing-for-seniors-upsell

DOWNLOAD:

FE:

Modul01: Training manual
Modul02: Cheat sheet
Module 03: MindMap
Modul04: ResourceReport …

[GET] Home work and digital marketing for seniors [PLR] FE + UPSELL

magento 1 – Edit up-sell block to view more than 1 product

Some of your previous answers have not been well received and you run the risk of being blocked from answering.

Please note the following notes exactly:

  • Please be sure answer the question, Enter details and share your research!

But avoid

  • Ask for help, clarification or answering other answers.
  • Make statements based on opinions; secure them with references or personal experiences.

For more information, see our tips for writing great answers.