Feat: Updating Shipping Method with new variables, for correct box env vars

This commit is contained in:
2026-09-18 00:52:38 +03:00
parent a55697ce82
commit dcdc998eee
4 changed files with 83 additions and 11 deletions
@@ -12,11 +12,15 @@ use Lunar\Shipping\Filament\Resources\ShippingMethodResource;
/**
* ListShippingMethod::getDefaultHeaderActions() builds its CreateAction's
* form inline (calling ShippingMethodResource::getDriverFormComponent()
* directly, a hardcoded 2-option Select) rather than through the resource's
* own extendForm() pipeline, so ShippingMethodResourceExtension's driver
* fix never reaches it. Re-declares the same create-action form with a
* dynamic driver Select instead.
* form inline (calling ShippingMethodResource::getDriverFormComponent()/
* getNameFormComponent() directly, hardcoded vendor components) rather
* than through the resource's own extendForm() pipeline, so neither
* ShippingMethodResourceExtension's driver Select nor its translated
* `name` field ever reached this action — `name`'s plain-string TextInput
* in particular used to insert a raw string into the now-JSON `name`
* column, crashing with a Postgres "invalid input syntax for type json"
* error on every create. Re-declares the same create-action form with
* both fixes reapplied instead.
*/
class ShippingMethodListExtension extends BaseExtension
{
@@ -25,7 +29,7 @@ class ShippingMethodListExtension extends BaseExtension
foreach ($actions as $action) {
if ($action instanceof CreateAction) {
$action->schema([
ShippingMethodResource::getNameFormComponent(),
ShippingMethodResourceExtension::translatedNameField(),
Group::make([
ShippingMethodResource::getCodeFormComponent(),
$this->driverSelect(),
@@ -43,7 +43,7 @@ class ShippingMethodResourceExtension extends ResourceExtension
{
return array_map(function (Component $component) {
if (method_exists($component, 'getName') && $component->getName() === 'name') {
return $this->translatedNameField();
return self::translatedNameField();
}
if (in_array(HasChildComponents::class, class_uses_recursive($component), true)) {
@@ -68,14 +68,28 @@ class ShippingMethodResourceExtension extends ResourceExtension
* the model attribute is a string on the way in and out, only ever
* an array while Filament's schema state holds it.
*/
private function translatedNameField(): TranslatedText
/**
* Also called directly by Modules\Core\Shipping\Extensions\
* ShippingMethodListExtension — the create action's form is built
* inline by the vendor's ListShippingMethod page rather than through
* this class's own extendForm() pipeline, so it needs the same
* translated field wired in separately.
*/
public static function translatedNameField(): TranslatedText
{
$field = TranslatedText::make('name')
->label('Name')
->required()
->afterStateHydrated(function (TranslatedText $component, $state) {
$decoded = json_decode((string) $state, true);
$component->state(is_array($decoded) ? $decoded : []);
// On create there is no record yet, so Filament hydrates
// this from the field's own default/current state — already
// an array (or null), never the raw JSON string edit gets
// from the model attribute. Only decode when it's a string.
if (is_string($state)) {
$state = json_decode($state, true);
}
$component->state(is_array($state) ? $state : []);
})
->dehydrateStateUsing(fn ($state) => json_encode(is_array($state) ? $state : []));