Error: Call to a member function getShowSwatchTooltip() on null

I keep o getting the above method error, because I have added color swatches for related products.

How do I solve this error?

Code for adding swatches

if($_item->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE){

$swatchBlock = $this->getLayout()->createBlock("Magento\Swatches\Block\Product\Renderer\Listing\Configurable")->setTemplate("Magento_Swatches::product/listing/renderer.phtml");
 echo $swatchBlock->setProduct($_item)->toHtml();                           

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.