在magento2的比较页面上的颜色样本

时间:2016-08-02 12:28:23

标签: magento2

Magento2

 How can be get the color swatch on product compare page.. 

1 个答案:

答案 0 :(得分:1)

要在产品比较页面上进行颜色搭配,您需要创建自定义模块: - 创建一个名为catalog_product_compare_index.xml的布局文件,并在创建的文件中添加以下代码。

 var ur_fit = ["slim_fit", "tailored", "comfort"];
 var ur_length = ["length_short", "length_regular", "length_high"];
    if(ur_fit.indexOf(data_this)!=-1){
        alert("Value is avail in ur_fit array");
    }
    else if(ur_length.indexOf(data_this)!=-1){      
         alert("value is avail in ur_legth array"); 

    }

您需要在第63行的overriden list.phtml中添加一个函数

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="Magento_Swatches::css/swatches.css"/>
    </head>
    <body>
        <referenceContainer name="content">
            <referenceBlock name="catalog.compare.list">
                <action method="setTemplate">
                    <argument name="template" xsi:type="string">W3solver_Compareswatch::product/compare/list.phtml</argument>
                </action>
                <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                    <block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" />
                </block>
            </referenceBlock>
        </referenceContainer>

    </body>
</page>

这将在比较页面上显示色块。