Pregunta

I have created a custom module, which creating an product attribute, now I need to display this attribute on the frontend, right under product SKU enter image description here

How I can I do this? Thanks everyone!

¿Fue útil?

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
scroll top