I need to show related products block on configurable product page (as it is by deflault), but instead of related products of configurable product i need to show related products of simple products which are included in that configurable product.

  • ok but you can display only the products under configurable products that are visible and in stock with inventory will show. what you want here ? Sep 10, 2018 at 10:40
  • i need that when i select simple product for any configurable product that simple product related product data should also be shown as related product in configurable product
    – Arjun
    Sep 10, 2018 at 11:01
  • so if you select any simple product it should be visibility should be catalog,search to front-end ,in stock and have inventory too then can list down in related products Sep 10, 2018 at 11:22
  • Ok let me recorrect myself when i redirect to any configurable product page i need to see related products on that page but that related products should not be of that configurable product but of all the simple products attach to that configurable product
    – Arjun
    Sep 10, 2018 at 12:25

1 Answer 1


If you want to display related products of child items instead of the related products of the parent item in a configurable product structure, then

Create a new module and override _prepareData function the main block file


Something like

protected function _prepareData() {
    $product = $this->_coreRegistry->registry('product');
    /* @var $product \Magento\Catalog\Model\Product */

    // GET TYPE
    $productType = $product->getTypeId();

    if ($productType == 'configurable') {
        $childrenProducts = $product->getTypeInstance()->getUsedProducts($product);
        if ($childrenProducts) {
            $this->_itemCollection = array();
            foreach ($childrenProducts as $singleChild) {
                $relatedProductCollection = $singleChild->getRelatedProductCollection()->addAttributeToSelect(

                if ($this->moduleManager->isEnabled('Magento_Checkout')) {
                foreach ($relatedProductCollection as $singleProduct) {
                    $this->_itemCollection[] = $singleProduct;
    } else {
        // IF OTHERS

        // main FUNCITON CODE

    return $this;

and then override the items.phtml file


under case 'related' change the if condition

if ($exist = $block->getItems()->getSize())


if ($exist = count($block->getItems()))

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.