Placed time return string but should be int

Created on 5 November 2024, 9 months ago

Problem

$order->getPlacedTime() return string, but should be int (via OrderInterface)

If you try to use this value in php date function, you get the error

$placed_date_only = date('Y-m-d', $order->getPlacedTime());

Proposed solution

return (int) $this->get('placed')->value;

🐛 Bug report
Status

Active

Version

3.0

Component

Order

Created by

ivnish Kazakhstan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ivnish
  • Pipeline finished with Failed
    9 months ago
    Total: 755s
    #329838
  • 🇮🇱Israel jsacksick

    But then we have the same problem with the created and completed timestamps right?
    Ideally we'd change the return type as well, but that could break code decorating the order entity class.

  • ivnish Kazakhstan

    Do you have a good idea? Change OrderInterface?

  • 🇮🇱Israel jsacksick

    hm... First of all, the value can be NULL... When the order isn't placed, with this, 0 is going to be returned, which is not the same behavior.

  • ivnish Kazakhstan

    Yes. You are right. Lets change interface from

    /**
    * Gets the order placed timestamp.
    *
    * @return int
    * The order placed timestamp.
    */
    public function getPlacedTime();

    to

    /**
    * Gets the order placed timestamp.
    *
    * @return string
    * The order placed timestamp.
    */
    public function getPlacedTime();

  • 🇮🇱Israel jsacksick

    No! This isn't the change I'm suggesting, the placed time returned should be an int, not a string. But what I'm saying is that we shouldn't return 0 if it's NULL.
    And whatever we do, we should replicate it to other entity types / fields returning timestamps...
    Note that we don't do anything different than the Node entity type defined by Drupal core here, which doesn't cast the return value...

  • ivnish Kazakhstan

    Okay, my skills end here. I fixed my project by "(int)". Will be cool if you fix it

  • Pipeline finished with Failed
    7 months ago
    Total: 163s
    #383660
Production build 0.71.5 2024