1

I am using the Commerce 2 plugin and I am experiencing a very odd issue. Once an order is complete I want to use the dateOrdered property to create a csv which I send through a request endpoint. That worked fine.

BUT! Since recently (somewhere this month), on the first attempt to create and save the .csv, when calling $order->dateOrdered->getTimestamp() I get dateOrdered as a string.

On the second attempt to create and save the .csv I get dateOrdered as a DateTime.

The method which I am calling is the same so I think it has something to do wiht order statuses.

I tried to trace the problem in Commerce's Order.php class but I still have no clue why this occurs or what I am doing wrong.

Any help is more than welcome. Thank you in advance!

1

The problem was occurring because the order was retrieved through the EVENT_AFTER_ORDER_PAID event. Therefore, the dateOrdered was still not processed (passed through mutations).

What we ended up doing is using $event->sender only to know what order we are looking for and then retrieve the order anew.

I hope this saves someone's life someday! I'll mark this question as solved in 2 days.

| improve this answer | |

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.