我已经创建了一个名为cloth material的自定义属性,我想在我的产品列表页面和价格下的产品详细信息页面中显示它。
有人能建议我如何实现它吗?目前的博客文章已经过时了。我使用的是Magento 2.3.3。
我还需要通过编程来完成它。当我选择在商店目录上显示时,它会在更多详细信息下显示它。
首先,在自定义主题中创建catalog_product_view.xml。(如果已经存在,则修改此文件(
app/design/frontend/Vendor/theme/Magento_Catalog/layout/Catalog_product_view.xml并在此文件中添加以下代码:
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.info.main">
<block class="MagentoCatalogBlockProductView" name="cloth.material" template="Magento_Catalog::view/cloth_material.phtml" after="product.info.price"/>
</referenceContainer>
</body>
</page>
现在创建cloth_material.html并在该文件中添加以下代码:
app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/cloth_material.phtml并在此文件中添加以下代码:
<?php
$_product = $block->getProduct();
// First method
$attribute_value = $_product->getResource()->getAttribute('your_attribute_code')->getFrontend()->getValue($_product);
// second method
$attribute_value = $_product->getAttributeText('your_attribute_code');
?>