2

I want to add a selector for date during order process in checkout. In which step should the custom field of an order be updated? And how is the custom field update done for order or other entity? I want to add the fields as it is shown in official docs.

$this->customFieldSetRepository->create([
    [
        'name' => 'swag_example',
        'customFields' => [
            ['name' => 'swag_example_size', 'type' => CustomFieldTypes::INT],
            ['name' => 'swag_example_color', 'type' => CustomFieldTypes::TEXT]
        ]
    ]
], $context);
David
  • 553
  • 6
  • 21
  • I can not see that you added a date field. Please update your code example. Why do you want to have a date selector during the checkout? Should it be related to the order or the basket? – Roman Mar 05 '21 at 11:01

1 Answers1

2

Where exactly do you want to add that data during the order process?

One example would be from confirm to finish -> the cart is converted to an order. You just need to create a Subscriber for that:

<?php

class OrderProcessSubscriber implements EventSubscriberInterface
{

    public static function getSubscribedEvents()
    {
        return [
            CartConvertedEvent::class => 'addCustomFieldsToConvertedCart',
        ];
    }

    public function addCustomFieldsToConvertedCart(CartConvertedEvent $event)
    {
        $convertedCart['customFields']['my_custom_field'] =  'test';
        $event->setConvertedCart($convertedCart);
    }
}

?>
Ezycod
  • 392
  • 2
  • 12
  • And If I have input fields in checkout/confirm, how can I pass the value of those fields inside of the addCustomFieldsToConvertedCart function. Are they available through the event variable? – David Mar 10 '21 at 09:22