1

I'am trying to add an extension-attribute to Magento_Customer like this:

<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
    <attribute code="some_attribute" type="\DateTime" />
</extension_attributes>

The goal is to have a datetime-Column in SQL and an \DateTime-Object in PHP.

But every time I try to do this it somehow ends in an reflection error like this:

1 exception(s):
Exception #0 (InvalidArgumentException): Each getter must have a doc block. See DateTime::format()

I've tried to wrap this in an extra getter/setter-Class and not to use \DateTime directly as an extension attribute but at some point is has to return \DateTime from a getter and this will also be picked up recursively by the reflections implementation of Magento2.

What am I missing here ?

0

As far as I know you can't defined extension attribute's type as DateTime so you have to defined it as string type so your code will look like.

<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
   <attribute code="some_attribute" type="string" />
</extension_attributes>

Let me know if you need further help.

1
  • thx thats all i neede confirmed - string would work - but i added a custom interface with non getter that returns datetime - not standard but it works Nov 13 '18 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.