top of page

Magento 2 - Why upsell section is displaying bundle products?

I faced one strange issue, that is we didn't add any upsell rule and we didn't add any upsell products in the prodcut via admin. But somehow upsell section is displaying associated bundle products collection when we loaded simple product collection. After debugging, we found the below observer will add the bundle products in upsell section when it matches with getAllowedSelectionTypes.

vendor/magento/module-bundle/etc/frontend/events.xml
<event name="catalog_product_upsell">
    <observer name="bundle_observer" instance="Magento\Bundle\Observer\AppendUpsellProductsObserver"/>
</event>
vendor/magento/module-bundle/Observer/AppendUpsellProductsObserver.php
if (!in_array($product->getTypeId(), $this->bundleData->getAllowedSelectionTypes())) {
    return $this;
}

We can find the same observer in the Magento official GitHub codebase. I have checked the Magento official documentation and there are no clear updates about the above observer.



I feel this is the worst idea without giving any controls from admin, Magento added bundle products in the simple product upsell section. At least, it should be shown the added products in the admin upsell section. If you are looking to disable this feature, please create the below events.xml in your custom extension.

app/code/Custom/Extension/etc/frontend/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <!-- Disabling Default Observer Magento\Bundle\Observer\AppendUpsellProductsObserver -->
    <event name="catalog_product_upsell">
        <observer name="bundle_observer" disabled="true"/>
    </event>
</config>

After that, run the needed Magento commands as setup upgrade, di-compile, static content deploy, cache flush.

I hope it helps! If you have any questions/suggestions, please mention them in the comment.



 
 
 

Recent Posts

See All
Split file by line number - Ubuntu

We can run the below command to split the large file in Ubuntu. split --numeric-suffixes=1 --additional-suffix=.csv -l 100 original.csv...

 
 
 

Comments


Follow Me

  • LinkedIn
  • Twitter
  • Facebook
  • YouTube
  • Instagram

©2021 by Bilal Usean. Proudly created with Wix.com

bottom of page