mollie / Shopware6

47 stars 52 forks source link

Creditcard components: Missing support for multilanguage shop #16

Closed mbegerau closed 4 years ago

mbegerau commented 4 years ago

Environment

OS: Ubuntu 18.04 Apache: 2.4.29 PHP: 7.3.17 MySQL: 5.7.30 Shopware: 6.1.5 (fresh installation from production repository) Mollie: 1.0.10 Other Plugins: Shopware 6 Demo data (1.0.5)

Problem

In a multilanguage shop the creditcard components are only displayed in the main language shop.

Image: Working components in English shop en_working Image: Broken components in German shop de_not_working

Detected causes

  1. The twig template gets the customFields directly and not from the translated object.

custom/plugins/MolliePayments/src/Resources/views/storefront/component/payment/payment-fields.html.twig, lines 15-19

15    {# load mollie creditcard components #}
16    {%
17        if payment.customFields.mollie_payment_method_name == 'creditcard'
18        and page.enable_credit_card_components == true
19    %}

In a shop that is not using the main language, the payment.customFields array is empty. It should get the payment.translated.customFields array instead.

  1. Translating a payment method leaves the customFields empty. If we get the translated object in the twig as described above it works only as long as we don't translate the payment method. But obviously we want to use a german description text in the german language shop. The problem is that the new translation row in the database has no data in custom_fields.

_Image: Empty custom_fields field in database_ database_empty_custom_fields

Another problem is that the custom fields are not displayed by default in the payment method editor.

Image: No custom fields in payment method editor admin_no_custom_fields

So the only way right now to fix this is filling in the field in the database manually.

Solution suggestion

a) Change the twig and somehow automatically add the custom_fields data to new payment method translations (not recommended)

b) Use a non-translatable field for payment method check.

Current workaround

  1. In our custom plugin we extend the twig template the following way:
    
    {% sw_extends '@Storefront/storefront/component/payment/payment-fields.html.twig' %}

{% block component_payment_method_description %} {% do payment.setCustomFields(payment.translated.customFields) %}

{{ parent() }}

{% endblock %}


2. And we manually add '{"mollie_payment_method_name": "creditcard"}' to the `custom_fields` field of each creditcard method translation.

### PS
Here is a json with a german version of your snippets. Feel free to add it to your repository.

{ "molliePayments": { "components": { "creditCard": { "headLine": "Bitte die Kreditkarteninformationen eingeben", "cardHolderLabel": "Karteninhaber/in", "cardNumberLabel": "Kreditkartennummer", "cardExpiryDateLabel": "Ablaufdatum", "cardVerificationCodeLabel": "CVC", "creditCardTagLine": "Abgesichert durch and angebot von" } } } }

iamreinder commented 4 years ago

Hello, thanks for putting in the effort of providing such a full display of the issue you're experiencing. And what possible solution you see. I wasn't aware that the translation record in the database doesn't take over the custom fields. This to me feels a bit like an issue that Shopware might need to address.

I will take a moment to think about the suggestions you have given and I might have a talk with some of the developers of Shopware about this. I'll get back to you if I have more information.

iamreinder commented 4 years ago

Hello,

I now check for the translated field, look here: https://github.com/mollie/Shopware6/blob/master/src/Resources/views/storefront/component/payment/payment-fields.html.twig#L17

Hopefully this works out for you.

My kind regards, Reinder van Bochove.

mbegerau commented 4 years ago

Hey, thanks for your work! I can confirm that this is working now.

Environment changes compared to original post (completely new and clean shop): Shopware: 6.2.0 Mollie: 1.0.13