0

I have a User entity. One user can buy a product. After the form validation I want to store the user data (ID, name, mail, password, address, ..) in $session, and only after the success payment retrieve this data from session and store it to the db.

This is what I'm doing: (if the from is valid)

        $session = new Session();
        $serialized_user = serialize($user);
        $session->set('myuser', ($serialized_user));

Then, after the payment check:

        $test = ($this->get('session')->get('myuser'));
        $test_unserialized = unserialize($test);

        $em = $this->getDoctrine()->getManager();
        $em->persist($test_unserialized);
        $em->flush();
        return $this->render('UserBundle:Account:buyedOk.php');

What I got is this error:

An exception occurred while executing 'INSERT INTO user (user, passw, email, is_active, is_locked, date_expire, date_registration, last_visit, name, surname, address, zipcode, city, province, country, vat, tel, fax, contact_name, contact_role, contact_email, contact_tel, email_hex, email_confirmed, validated,id_currency) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["March", "$2y$13$hTBP0ANwRlwgcfX19OtsTubn6ctI64lz5GVQ3JF3nZtD0GDPK8rTC", null, 0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'email' cannot be null

Suggestions?

ZugZwang
  • 418
  • 1
  • 5
  • 14
  • where do you get your `$user` in `serialize($user)` from ? – Tomasz Madeyski Sep 26 '16 at 14:11
  • `if ($form->isValid()) { $registration = $form->getData(); $user = $registration->getUser(); $user->setPassword($this->encodePassword($user, $user->getPassword())); if ($user->getIsActive() === null) $user->setIsActive(0); and so on ` – ZugZwang Sep 26 '16 at 14:25
  • You asked this question before and chose not to respond to any of the comments or answers. Why exactly should someone spend the time answering this one? – Cerad Sep 26 '16 at 14:37
  • @Cerad I answered to all of the questions. – ZugZwang Sep 26 '16 at 14:42
  • It is way easier to create a "activated" flag at the `User` and set that to true after the payment was completed. That way you don't have to think about the serialization overhead. – Rvanlaak Sep 26 '16 at 15:00
  • If you say so: http://stackoverflow.com/questions/39640807/accessing-session-data-in-symfony – Cerad Sep 26 '16 at 16:18
  • @Cerad Yes, you're right, I completely forgot this one. Sorry – ZugZwang Sep 27 '16 at 07:03
  • You can find the answer to this question here https://stackoverflow.com/a/11017173/5224379 – murilosandiego Feb 18 '18 at 16:29

0 Answers0