Shopware 6: logo automatically in documents - shopware

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.

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.

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
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.

Related

Which twig template to extend for a custom theme?

I apologise before for a long explanation - I have a hard time explaining it to myself.
I run Shopware 6 locally and using the development template. I needed to remove the product number from the product detail page. So, I override the twig template "buy-widget.html.twig":
{% sw_extends '#Storefront/storefront/page/product-detail/buy-widget.html.twig' %}
{% block page_product_detail_ordernumber_container %}
{% endblock %}
Works as expected - if I have not change the layout template for the product, but using the Shopware default.
But, when I change the layout to a custom layout (the only difference is that the image thumbs is bellow the main image) the product number is back?!
Checking with the Symfony Profiler, I can see that it's now another twig template (from a folder "component/.." responsible for displaying the product number.
Question: Am I correct to assume that I should extend the twig template from this component folder if I'm using a custom layout? I have not find anything in the docs about these "small" details. And if one need to be sure that a custom theme works in every case, you must make the changes (using sw_extends) in two files?
/ Magnus

How to save custom input field from checkout page to order in Shopware6 app?

I add custom input field to checkout page like this:
% sw_extends '#Storefront/storefront/page/checkout/confirm/confirm-shipping.html.twig' %}
{% block page_checkout_confirm_shipping_form %}
{{ parent() }}
<input type="text" id="some_info_text" name="some_info_text">
{% endblock %}
I need to save information from this input field to order. This is not plugin, it's an app integration.
It seems app doesn't have event subscribers.
How can I implement this field saving?
I've checked Shopware 6 app docs, but I haven't found right solution.
I think there is no way to do that. From Shopware App you can't influence which data Shopware will send.

Shopware 6: How to display product name in breadcrumbs

We want to add the product name to the breadcrumb list when current page matches a product detail page.
Unfortunately, it doesn't seem like the product is loaded yet when the breadcrumb is rendered. We have tried using dump() to see what variables are available and nothing related to the product.
Where should I look in order to include the product name in our breadcrumbs?
Have a look at storefront/base.html.twig. There you will see, that currently the breadcrumb-template gets passed the context and the category. If you want to also use some product-information, you have to overwrite this block like this:
{% block base_breadcrumb %}
{% sw_include '#Storefront/storefront/layout/breadcrumb.html.twig' with {
context: context,
category: page.product.seoCategory,
product: page.product
} only %}
{% endblock %}
Then you can use product in the breadcrumb-template.

Grav CMS: how to show/hide parts of the page depending on conditions?

The Grav's documentation clearly describes how a whole page or a folder could be hidden from unregistered users. It also describes how a whole page could be seen only by particular user groups.
But what about pieces of a page, let's say, some links or a private info I want to show on some conditions?
Ok, for registered users I found a snippet at Login plugin docs:
{% if grav.user.authenticated %}
content for registered users goes here
{% endif %}
But going wider - how can I show/hide pieces of a particular page depending on some custom logic in PHP code, i.e. not necessarily user related?
I'm thinking about a twig/shortcode plugin, something like:
{% if some.custom.condition.or.PHP.function %}
hidden content goes here
{% endif %}
or
[hidden_if_something] hidden content goes here [/hidden_if_something]
But not sure how exactly this should be implemented. So working examples would be appreciated. Thanks.
There is a recipe in the Grav documentation here. This provides an example of how to render the output of a PHP code result in a twig template.
In the example they create a plugin, and implement a twig extension providing access to a php function. They can then simply call that php function like in a twig template.
{{ example() }}
Following that example, you can implement whatever logic you would like in php, and call the function in a twig if statement.
{% if example() == true %}
your conditional output
{% endif %

Membership Level issue in NationBuilder

I have a website built in NationBuilder. There I needed to make another Membership level. I have done that. But the issue is that it is not showing in "Who can view this page" dropdown in page settings. Anyone has any idea how to do that.?
Thanks in advance
It seems you can't control who can view this page via membership levels.
From a NationBuilder FAQ, How do I set up a five-tier membership site:
In NationBuilder... being a member is a binary state: you either are
or you are not a member. While NationBuilder allows you to sell
various membership levels, the database doesn't recognize those
various levels as distinct and different from a permissions level.
That means that if you make a page viewable to "Members" it will be
viewable to all members, equally.
There's really no good workaround for this that's based on membership
level of which I am aware. You can, however, use conditional liquid
tags to display different content on a given page to logged-in users
depending on what tags their NationBuilder profile has. Since each
membership level can be configured to automatically tag people, this
method could be employed to display different content to individuals
who have different membership levels (or none at all).
You can accomplish this by editing the page template. For instance, suppose you wished to restrict a page to only users with MEMBER_A membership.
{% assign hasPagePermission = false %}
{% for membership in request.current_signup.memberships %}
{% if membership.membership_type_name == "MEMBER_A" and (membership.status == "active" or membership.status == "grace period") %}
{% assign hasPagePermission = true %}
{% endif %}
{% endfor %}
{% if hasPagePermission == true %}
{{ page.basic.content }}
{% else %}
{% include 'access_denied' %}
{% endif %}
I realise that your original post was six years ago, however I post this in the hope that it will be helpful to others (or indeed me when I forget how to do this and end up searching for this again!)

Resources