taking utf-8 encoding into account when shortening billie line item descriptions #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In https://github.com/ozean12/shopware6-payment-module/blob/4.0/src/Components/Checkout/Service/WidgetService.php#L240 there is logic to shorten the line item descriptions to 255 chars. However this logic is not taking into account utf-8 encoding and in some cases will lead to broken characters inside the description (e.g. when the 255th character is an Umlaut).
This would not be problematic on it's own, but the data is later transformed into JSON in order to be passed to the billie widget in the checkout (https://github.com/ozean12/shopware6-payment-module/blob/4.0/src/Resources/views/storefront/billie-payment/hidden-input-field.html.twig#L10). As the data is malformed, the json_encode returns false, which breaks the checkout as the widget can't be loaded properly.
I suggest using mb_substr instead. Seems to solve the problem just fine.