Zend certified PHP/Magento developer

Magento 2: Issue with double configurable swatches on related product tab

I am having an issue with double configurable swatches on the related product tab. It is working properly with single swatches such as color swatches only but it creates an issue on products with double swatches such as color and size.

When I choose any option from the main product above

enter image description here

the swatches on the product in the related tab should display the label of the options selected above. But it doesn’t. It shows th selected label on both the options.

enter image description here

Can someone help me with this?

This is my items.phtml

< ?php $objectManager = MagentoFrameworkAppObjectManager::getInstance(); ?>
< ?php
$stockRegistry = $objectManager->create(MagentoCatalogInventoryApiStockRegistryInterface::class);
$product = $block->getCurrentProduct();
$currencySymbol = $block->getCurrencySymbol();
$items = [];
$packageTitle = $block->getGeneralConfig('display_title');
switch ($type = $block->getType()) {
case 'related':
/** @var TekglidePackageProductsBlockProductProductListRelated $block */
if ($exist = $block->getItems()->getSize()) {
$type = 'related';
$class = $type;
$image = 'related_products_list';
$title = __($packageTitle);
$items = $block->getItems();
$limit = 0;
$shuffle = 0;
$canItemsAddToCart = $block->canItemsAddToCart();
$showAddTo = false;
$showCart = true;
$templateType = null;
$description = false;
}
break;
case 'other':
$exist = false;
break;
}
/** @var TekglidePackageProductsBlockProductProductListRelated $block */
?>
< ?php if ($exist):?>
< ?php if ($type == 'related'): ?>
< ?php if ($type == 'related'): ?>
< ?php else: ?>
< ?php endif; ?> < ?php else: ?>
< ?php endif; ?>

< ?= /* @noEscape */ $title; ?>

< ?php if ($type == 'related'):?>< ?php endif; ?> < ?php $iterator = 1; $citemCount = 0; $childSimpleCount = 0; $outOfStockCount = 0; $ifBothEqual = 0; ?> < ?php foreach ($items as $_item): $citemCount++; $childSimpleCount++; $productId = $_item->getId(); $parentId = $block->getChildProductOfConfigurable($productId); $linkToSelectedOption = ''; if ($type == 'related' && $parentId) { $parentProduct = $block->getProductById($parentId); $productUrl = $block->getProductUrl($parentProduct); $linkToSelectedOption = $block->getLinkToSelectedOption($parentId, $productId, 'size'); } else { $productUrl = $block->getProductUrl($_item); } ?> < ?php $available = ''; ?> < ?php if (!$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?> < ?php if (!$_item->getRequiredOptions()): ?> < ?php $available = 'related-available'; ?> < ?php endif; ?> < ?php endif; ?> < ?php if ($type == 'related' || $type == 'upsell'): ?> < ?= /* @noEscape */($iterator++ == 1) ? '
' : '
< ?php if ($childSimpleCount > 0 && $outOfStockCount > 0 && $childSimpleCount == $outOfStockCount) { $ifBothEqual = 1; }?> < ?php if ($type == 'related'): ?>

Total price for 1 product(s):

< ?php if ($product->isSaleable()): ?>
< ?php else: ?>
< ?php endif; ?>
< ?php endif; ?>
< ?php endif;?>