はこれを試してみてください。カスタム商品属性(保証)を表示する場合は、まずファイルcatalog_product_view.xml
を編集し、次のコンテンツを更新する必要があります。このセクションは、product.info.mainコンテナ内に追加できます。ブロックをproduct.info.overviewブロックの隣に追加できます。したがって、短い説明属性の隣に表示されます。
<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.demo" template="product/view/demo.phtml" after="-">
<arguments>
<argument name="at_call" xsi:type="string">getWarranty</argument>
<argument name="at_code" xsi:type="string">warranty</argument>
<argument name="css_class" xsi:type="string">warranty </argument>
<argument name="at_label" xsi:type="string">warranty </argument>
<argument name="add_attribute" xsi:type="string">itemprop="warranty "</argument>
</arguments>
</block>
次の内容のmageno2root/vendor/magento/module-catalog/view/frontend/templates/product/view
の下に新しいファイルwarranty.phtml
を作成します。
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();
if ($_attributeLabel && $_attributeLabel == 'default') {
$_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel();
}
$_attributeValue =$_product->getResource()->getAttribute($_code)->getFrontend()->getValue($_product);
?>
<?php if ($_attributeValue): ?>
<div class="product attibute <?php echo $_className?>">
<?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php echo $_attributeLabel?></strong><?php endif; ?>
<div class="value" <?php echo $_attributeAddAttribute;?>><?php echo $_attributeValue; ?></div>
</div>
<?php endif; ?>
希望すると助かります。