0

My site in Magento 2.3.5 does not display color samples on the category page.

Instead, they appear on the home page and on the product page.

In the backend I set everything correctly to display the color samples on the category page but they are not seen.

In my custom theme taken by Luma there is this code in list.phtml:

<?php if ($_product->isAvailable()) :?>
        <?= $block->getProductDetailsHtml($_product) ?>
<?php endif; ?>

But it doesn't work and I return null

Why?

4
  • 1
    you are set this Used in Product Listing = Yes in your attribute properties from Admin >> Catalog >> Attributes >> Manage Attributes ??? Commented Jun 12, 2020 at 11:33
  • Thanks for the reply. Yes man, i set Product Listing = Yes but not works...
    – Jackom
    Commented Jun 12, 2020 at 12:31
  • check this link --- magento.stackexchange.com/questions/197287/… Commented Jun 12, 2020 at 12:36
  • I have seen but this question is for Magento 1.9 and i have 2.3.5 version
    – Jackom
    Commented Jun 12, 2020 at 13:19

1 Answer 1

2

I FOUND SOLUTION!

I hope it can help someone:

Copy and paste this code in app/design/frontend/ParentTheme/YourTheme/Magento_Catalog/layout/catalog_category_view.xml (After category.product.type.details.renderers block)

<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable"
                     name="category.product.type.details.renderers.configurable"
                     template="Magento_Swatches::product/listing/renderer.phtml"
                     ifconfig="catalog/frontend/show_swatches_in_product_list">
                        <arguments>
                            <argument name="configurable_view_model"
                                xsi:type="object">Magento\Swatches\ViewModel\Product\Renderer\Configurable</argument>
                        </arguments>
                </block>

Finally copy and paste this code into the file app/design/frontend/ParentTheme/YourTheme/Magento_Catalog/templates/product/list.phtml

                    <?php 
                    $blocks = $this->getLayout()->getBlock('category.product.type.details.renderers.configurable');
                    echo $blocks->setProduct($_product)->toHtml();
                    ?>

Enjoy!! ;)

2
  • Not working in Magento 2.4
    – Zudian
    Commented May 12, 2021 at 9:56
  • also not working for me. i'm using magento 2.3.6. in fact, using this code, all my configurable products turned into simple products :-) Commented Sep 30, 2021 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.