dNovoNielsdNovoNiels MitgliedKommentare: 8 Danke erhalten: 0 Mitglied seit: 4. Mai

Hello Shopware community,

 

Me and my colleague followed the backend components guide to create our own backend module to add information to the database through a custom model. so far so good. Untill we get to the part where we want to add a new record to the database.

When we want to add the a new record we get the message "Column 'datedAt' cannot be null" which is weird because when we check the body of the info we want to post it has the date we set with the datepicker in it.

The 2 screenshots below show the info that's being set in the backend module and body that is getting POSTed. Apparently shopware changed the date format from dd.mm.yyyy to dd/mm/yy somewhere down the line.

Event SettingsBody

 

After some more troubleshooting i found out that if you follow the guides example to the letter, you will get the same problem. using the example plugin to add data to your database works, but the date column will be set to null. below is a screenshot of the s_product table in the database, which shows the added product added through the backend module, but with the createDate set to NULL.

 

My question is: why is the date set as null in the database and how do i fix it so it actually adds the date to the database?

any help is greatly appreciated :)

Antworten

  • dNovoNielsdNovoNiels MitgliedKommentare: 8 Danke erhalten: 0 Mitglied seit: 4. Mai

    Found the problem.
    In my table, the column is named datedAt, but in my model i had the get and set method named getDate() and setDate(). Apparently shopware links those method names to the name of the column in the table so i had to rename the methods to getDatedAt() and setDatedAt().

    so this was wrong

    /**
    * @return \DateTime
    */
    public function getDate()
    {
        return $this->datedAt;
    }
    
    /**
    * @param \DateTime $value
    */
    public function setDate($value)
    {
        $this->datedAt = $value;
    }

     

    and this is correct

    /**
    * @return \DateTime
    */
    public function getDatedAt()
    {
        return $this->datedAt;
    }
    
    /**
    * @param \DateTime $value
    */
    public function setDatedAt($value)
    {
        $this->datedAt = $value;
    }

     

Anmelden oder Registrieren, um zu kommentieren.