Magento 2 - How to display a programmatically created attribute under SKU on the frontend?
-
16-02-2021 - |
Solución
create a layout file in your extension
NameSpace/ModuleName/view/frontend/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="Magento\Catalog\Block\Product\View\Description" name="product.info.product_vendor"
template="Magento_Catalog::product/view/attribute.phtml" after="product.info.sku">
<arguments>
<argument name="at_call" xsi:type="string">getProductVendor</argument>
<argument name="at_code" xsi:type="string">product_vendor</argument>
<argument name="css_class" xsi:type="string">product_vendor</argument>
<argument name="at_label" xsi:type="string">default</argument>
<argument name="add_attribute" xsi:type="string">itemprop="product_vendor"</argument>
</arguments>
</block>
</referenceContainer>
</body>
Otros consejos
Create a catalog_product_view.xml
<referenceContainer name="product.info.stock.sku">
<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.cutom.attribute" template="Magento_Catalog::product/view/attribute.phtml" after="product.info.sku">
<arguments>
<argument name="at_call" xsi:type="string">getYourAttribute</argument>
<argument name="at_code" xsi:type="string">your_attribute_code</argument>
<argument name="css_class" xsi:type="string">custom_css_class</argument>
<argument name="at_label" xsi:type="string">default</argument>
<argument name="add_attribute" xsi:type="string">itemprop="your_attribute_code"</argument>
</arguments>
</block>
</referenceContainer>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange