Andreas Reinhard
Andreas Reinhard

Reputation: 11

Shopware 6: logo automatically in documents

Is there a way to automatically output the logo of a sales channel in the documents (invoice, delivery bill, etc.) without having to create a separate document for each sales channel?

Thanks for your help :-)

Unfortunately, I have not found an approach so far.

Upvotes: 0

Views: 467

Answers (2)

Oliver
Oliver

Reputation: 41

Here is a video how to change Shopwares Document Logos the easy way using the WYSIWYG Document Editor: https://youtu.be/fGBMDmVMPvA?t=162

The easiest way to change your documents is by customizing them with the WYSIWYG Document Editor. The live preview will save you a lot of time and money in comparison to going back and forth 1000 times between making adjustments in your Twig Templates and generating new PDFs for testing.

Check it out: https://store.shopware.com/appli81810362453/wysiwyg-dokumenten-editor-pdf-rechnungen-lieferscheine-gutschriften-stornos-designen.html

Change document logo in Shopware 6 with the WYSIWYG Document Editor

I am the developer, which created the WYSIWYG Document Editor Shopware 6 App. Feel free to ask me any questions about the App. I am happy to help you.

Upvotes: 0

dneustadt
dneustadt

Reputation: 13201

I think it currently isn't possible to differentiate between sales channels with the document settings in the administration.

You could create a media custom field for the sales channel, upload the logo there and then use the custom field in the document template.

  • Go to Settings > System > Custom Fields
  • Add a new set and assign it to Sales Channels
  • Within the new set create a new custom field
  • As type choose Media and think of a unique technical name
  • In the sidebar to the left go to the sales channel you want to upload a logo for
  • Scroll down to the custom fields of the sales channel and upload the logo with the new media custom field
  • Save the sales channel

Then you'll need a plugin to extend the document template. Within your plugin create the template extension e.g. at {pluginRoot}/src/Resources/views/documents/base.html.twig with the content:

{% sw_extends '@Framework/documents/base.html.twig' %}

{% block document_header %}
    {% if context.salesChannel.customFields.custom_test_media is defined %}
        {% set media = searchMedia([context.salesChannel.customFields.custom_test_media], context.context) %}
        {# @var item \Shopware\Core\Content\Media\MediaEntity #}
        {% for item in media %}
            <img src="{{ item.url }}" class="logo"/>
        {% endfor %}
    {% endif %}
{% endblock %}

with custom_test_media being the technical name of the media custom field you created earlier.

Upvotes: 1

Related Questions