The custom module lists certain configurable products. I need to display the color swatches, I tried below but it returns nothing!
in myTempalte.phtml
<?php
use Magento\Framework\App\Action\Action;
// @codingStandardsIgnoreFile
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
/**
* Position for actions regarding image size changing in vde if needed
*/
$pos = $block->getPositioned();
/**
* Product list template
*
* @var $block \Magento\Catalog\Block\Product\ListProduct
*/
$_productCollection = $this->createCollection();
$blockVariant = $this->getLayout()
->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')
->setTemplate('Magento_Swatches::product/listing/renderer.phtml');
..... // in loop I have below for color div
<?php if ($_product->getTypeId() == "configurable" ):?>
<div class="product-available-variant">
<?php $blockVariant->getProductDetailsHtml($_product); ?>
</div>
<?php endif?> // and rest of the loop
How to add color swatches block to widget template, below does not work:
$blockVariant = $this->getLayout()
->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')
->setTemplate('Magento_Swatches::product/listing/renderer.phtml');