We are also dealing with that same problem. We want to extend the register form with a custom field, which was set up in backend. Have you already found a solution for that? We tried a lot of combinations in the register form, but none worked. From my point of view, the mapping function for custom_fields in the registration service isn´t implemented yet?
I am also struggling in this part. I am adding a text in the Custom field, and I want to do Data mapping with this field in the administration. Did anyone find a solution to that?
Thank you for sharing your code, what saved us a lot of time! For the sake of completeness, you need to mention, that the subscriber needs to be added in an extended services.xml ([yourPlugin]/src/Resources/config/services.xml) like:
If you use CustomerEvents::MAPPING_CUSTOMER_PROFILE_SAVE => ‘addCustomField’ too in getSubscribedEvents() the thinggi works in customer account profile save, too! Thanks for your tipps.
In Shopware 6.4.15 saving a custom field to a customer worked without the need for a subscriber:
In the registration form just add a field with follwing name:
name=“customFields[my_custom_field]”
I’ve tried this with the customer entity and having a checkbox on the profile page but it did not work. I’ve added the input to the form as per documentation (as well as my custom field modifieable by the store api) and the value gets transmitted with the post request but unfortunately, the value does not update.
I’ve tried this with the customer entity and having a checkbox on the profile page but it did not work. I’ve added the input to the form as per documentation (as well as my custom field modifieable by the store api) and the value gets transmitted with the post request but unfortunately, the value does not update.
This was because of a validation error the api did not communicate to me. My apologies
I have a similar problem: I created my own custom fields in the Admin backend and assigned them to orders. In the checkout, I integrated them via Twig (e.g., directly under the additional block), and the fields can be filled in there.
The problem: after completing the order, the fields are empty. When I open the order details in the Admin, I don’t see any values in the custom fields.
So far, I’ve managed to get the field values correctly attached to the order form, and they are also included in the POST /checkout/order. But Shopware does not automatically save them into order.customFields. That’s why I wrote a subscriber to catch the fields during checkout and write them into the order — but somehow it’s not working.
You need to share your code otherwise, everyone can only guess what the problem might be. Shopware doesn’t automatically persist data from the objects customfields. You need to call the orderRepository and upsert the customfield data. Did you do that?
<?php
namespace CryptoCustomField\Subscriber;
use Shopware\Core\Checkout\Order\Event\OrderPlacedEvent;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class EndkundeOrderPlacedSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly EntityRepository $orderRepository,
private readonly RequestStack $requestStack
) {}
public static function getSubscribedEvents(): array
{
return [
OrderPlacedEvent::class => 'onOrderPlaced',
];
}
public function onOrderPlaced(OrderPlacedEvent $event): void
{
$request = $this->requestStack->getCurrentRequest();
if (!$request) {
return;
}
$values = $request->getSession()->get('custom_endkunde');
if (!\is_array($values) || !$values) {
return;
}
$orderId = $event->getOrderId();
$context = $event->getContext();
$update = [
'id' => $orderId,
'customFields' => [
'custom_endkunde_name' => (string)($values['custom_endkunde_name'] ?? ''),
'custom_endkunde_mail' => (string)($values['custom_endkunde_mail'] ?? ''),
'custom_endkunde_strasse' => (string)($values['custom_endkunde_strasse'] ?? ''),
'custom_endkunde_plz' => (string)($values['custom_endkunde_plz'] ?? ''),
'custom_endkunde_stadt' => (string)($values['custom_endkunde_stadt'] ?? ''),
'custom_endkunde_walletid' => (string)($values['custom_endkunde_walletid'] ?? ''),
'custom_endkunde_miningpool' => (string)($values['custom_endkunde_miningpool'] ?? ''),
],
];
$this->orderRepository->update([$update], $context);
$request->getSession()->remove('custom_endkunde');
}
}
The POST request is sent (visible in the network tab), but the server returns HTTP 500. My troubleshooting hasn’t produced any leads so far. I suspect the event subscriber is crashing. Any ideas what might be causing this?