Hi eveyone I am facing an issue with something I want to achieve. The system version is 6.4.18.1
My goal
I need to save customFields of type Json on address upsert this to store some data that will be retrieved afterwards.
What i have already done
plugin configuration
created custom fields (with „allowCustomerWrite“ = true) and custom fields set
$customerAddressPrefix = [
'name' => 'customer_prefix',
'config' => [
'label' => [
'de-DE' => ' '
],
],
"relations" => [
[
"entityName" => CustomerAddressDefinition::ENTITY_NAME,
],
],
'customFields' => [
[
'name' => 'customer_address_prefix',
'type' => CustomFieldTypes::JSON,
"allowCustomerWrite" => true,
'config' => [
'label' => [
'de-DE' => '',
],
'helpText' => [
'de-DE' => '',
],
'customFieldPosition' => 1,
],
],
],
];
UpsertAddressRouteDecorator
Added customFields to DataBag as follows
$address= $data->get("address");
$address->set(
"customFields",
new RequestDataBag([
"customer_address_prefix" =>
// THIS DID NOT WORK -> result in {"customer_address_prefix" => {}}
// [[
// 'type' => "aaaa",
// 'prefix' => "bbbb",
// 'id' => $genericAddress->get("id"),
// ]],
// NEITHER THIS WORKED -> result in {"customer_address_prefix" => {}}
// RequestDataBag([
// 'type' => "aaaa",
// 'prefix' => "bbbb",
// 'id' => $genericAddress->get("id"),
// ]),
json_encode([
'type' => $billingOrShipping,
'prefix' => $cleanPhonePrefix,
'id' => $genericAddress->get("id"),
], JSON_THROW_ON_ERROR),
])
);
Actual problem
I cannot store customFields in Json format other that passing it with json_encode(). But having so can lead to problem afterwards. Therefore I wanted to know whether anyone knows a way to store it (via DataBag) in Json format.
Thanks for you time and patience