[5.x]: Email subject DB column only allows 255 characters
Closed this issue · 2 comments
What happened?
Description
I want to use Twig code to conditionally change the email subject based on the shipping method.
However by doing so I exceeded the maximum amount of characters as defined in the DB column as 255.
Since Twig code for this field is allowed it would be nice to give a lot more characters for this DB column.
Steps to reproduce
- Navigate to a configured email in the craft commerce interface
- Fill in the "Email subject" field with more than 255 characters using Twig code.
Example: {% if order.shippingMethodHandle == 'afhalingInEenWinkel' %}{{ 'Order is ready' | t ('mail') }}{% elseif order.shippingMethodHandle == 'verzekerdeVerzendingViaMikropakket' %}{{ 'Your package is on its way' | t ('mail') }}{% elseif order.shippingMethodHandle == 'leveringViaPriveKoerier' %}{{ 'Confirm appointment' | t ('mail') }}{% endif %}
Expected behavior
The limit should be way higher.
Actual behavior
It blocks me from adding dynamic subjects.
Craft CMS version
5.x
Craft Commerce version
5.x
PHP version
8.2
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
For complex logic that is large, instead of using a large amount of twig code, we would prefer you use a module to add functionality.
In this case, I would recommend add an Order method with a behavior
For example:
<?php
namespace modules\sitemodule\behaviors; // replace with your namespace
use craft\elements\User;
use yii\base\Behavior;
class MyOrderBehavior extends Behavior
{
public function getMyEmailSubject() {
if($this->shippingMethodHandle == 'xxx'){
return "Order is here";
}
if($this->shippingMethodHandle == 'yyy'){
return "Package is here";
}
return "default message here";
}
}
Then add the behavior to the order element:
then in the subject, you can do:
{{ order.getMyEmailSubject() }}
Hope this helps.