Changing the product title to custom field

Our shopware is connected to our winstore through API which is why our product name is inherited from the stock system. This sometimes causes for names like „934919da“ which is confusing for the customer.

I created a custom field for product type to add a custom name. Changing the code to anything „lorem ipsum“ works, but when I try to retrieve the custom field, it doesn’t work.

{% block page_product_detail_headline_inner %}
    {% block page_product_detail_name_container %}
        <div class="col product-detail-name-container">
            {% block page_product_detail_name %}
                <h1 class="product-detail-name"
                    itemprop="name">
     {{ page.product.customFields.custom_productname_|default(page.product.translated.name) }}
                </h1>
            {% endblock %}
        </div>
    {% endblock %}

    {% block page_product_detail_manufacturer %}
        {% if page.product.manufacturer %}
            <div class="col-md-auto product-detail-manufacturer">
                {% block page_product_detail_manufacturer_inner %}
                    {% block page_product_detail_manufacturer_link %}
                        <a href="{{ page.product.manufacturer.link }}"
                           class="product-detail-manufacturer-link"
                           rel="noreferrer noopener"
                           target="_blank"
                           title="{{ page.product.manufacturer.translated.name }}">
                            {% if page.product.manufacturer.media %}
                                {% block page_product_detail_manufacturer_logo %}
                                    <img src="{{ page.product.manufacturer.media|sw_encode_media_url }}"
                                         class="product-detail-manufacturer-logo"
                                         alt="{{ page.product.manufacturer.translated.name }}"/>
                                {% endblock %}
                            {% else %}
                                {% block page_product_detail_manufacturer_text %}
                                    {{ page.product.manufacturer.translated.name }}
                                {% endblock %}
                            {% endif %}
                        </a>
                    {% endblock %}
                {% endblock %}
            </div>
        {% endif %}
    {% endblock %}
{% endblock %}

'm really new to shopware, only have basic limited knowledge of coding but usually know my way around. I hope anyone can tell me what’s going wrong. I double checked the correct technical name. the custom field is a text field, connected to Product entity.

I tried Changing the default {{ page.product.translated.name }} to {{ page.product.customFields.custom_productname_|default(page.product.translated.name) }}

I also tried {{ page.product.translated.customFields.custom_productname_|default(page.product.translated.name) }}

1 „Gefällt mir“

Do you found a solution ?

I would recommend to set the product name to a variable and then use the null-coalescing operator (??) or is not null call from twig to check if the custom field has a value and only use product.translated.name as a fallback

{% block page_product_detail_headline_inner %}
    {% set productName = page.product.translated.name %}
    {% if page.product.customFields is defined and page.product.customFields.custom_productname_ is not null %}
        {% set productName = page.product.customFields.custom_productname_ %}
    {% endif %}

    {# use the variable where ever you need it: {{ productName }} #}
{% endblock %}

Maybe also the naming of the customField (with trailing „_“) is a problem.
You can alternatively try to get the custom field’s value with the array key notation:

{% block page_product_detail_headline_inner %}
    {% set productName = page.product.translated.name %}
    {% if page.product.customFields is defined and page.product.customFields['custom_productname_'] is not null %}
        {% set productName = page.product.customFields['custom_productname_'] %}
    {% endif %}

    {# use the variable where ever you need it: {{ productName }} #}
{% endblock %}