Esempio n. 1
0
 public function load(ObjectManager $manager)
 {
     $admin = new User();
     $admin->setCreatedAt(new \DateTime());
     $admin->setUpdatedAt(new \DateTime());
     $admin->setUsername('admin');
     $admin->setUsernameCanonical('admin');
     $admin->setEmail('*****@*****.**');
     $admin->setEmailCanonical('*****@*****.**');
     $admin->setEnabled(1);
     $admin->setPlainPassword('admin');
     $admin->setSuperAdmin(true);
     //$admin->addRole(static::ROLE_SUPER_ADMIN);
     $manager->persist($admin);
     $manager->flush();
     $this->addReference('admin', $admin);
 }
 /**
  * Generates a Customer with his addresses.
  *
  * @param ObjectManager $manager
  * @param int $i Random number to avoid username collision
  *
  * @return Customer
  */
 protected function generateCustomer(ObjectManager $manager, $i)
 {
     $faker = $this->getFaker();
     $firstName = $faker->firstName();
     $lastName = $faker->lastName();
     $email = $faker->email();
     $username = $faker->userName();
     if (0 === $i % 50 && $this->hasReference('customer-johndoe')) {
         return $this->getReference('customer-johndoe');
     }
     // Customer
     $customer = new Customer();
     $customer->setTitle(array_rand(array(BaseCustomer::TITLE_MLLE, BaseCustomer::TITLE_MME, BaseCustomer::TITLE_MR)));
     $customer->setFirstname($firstName);
     $customer->setLastname($lastName);
     $customer->setEmail($email);
     $customer->setBirthDate($faker->datetime());
     $customer->getBirthPlace($faker->city());
     $customer->setPhoneNumber($faker->phoneNumber());
     $customer->setMobileNumber($faker->phoneNumber());
     $customer->setFaxNumber($faker->phoneNumber());
     $customer->setLocale('fr');
     $customer->setIsFake(true);
     // Customer billing address
     $customerBillingAddress = new Address();
     $customerBillingAddress->setType(BaseAddress::TYPE_BILLING);
     $customerBillingAddress->setCustomer($customer);
     $customerBillingAddress->setCurrent(true);
     $customerBillingAddress->setName('My billing address');
     $customerBillingAddress->setFirstname($customer->getFirstname());
     $customerBillingAddress->setLastname($customer->getLastname());
     $customerBillingAddress->setAddress1($faker->address());
     $customerBillingAddress->setPostcode($faker->postcode());
     $customerBillingAddress->setCity($faker->city());
     $customerBillingAddress->setCountryCode(0 === $i % 50 ? 'FR' : $faker->countryCode());
     $customerBillingAddress->setPhone($faker->phoneNumber());
     // Customer contact address
     $customerContactAddress = new Address();
     $customerContactAddress->setType(BaseAddress::TYPE_CONTACT);
     $customerContactAddress->setCustomer($customer);
     $customerContactAddress->setCurrent(true);
     $customerContactAddress->setName('My contact address');
     $customerContactAddress->setFirstname($customer->getFirstname());
     $customerContactAddress->setLastname($customer->getLastname());
     $customerContactAddress->setAddress1($faker->address());
     $customerContactAddress->setPostcode($faker->postcode());
     $customerContactAddress->setCity($faker->city());
     $customerContactAddress->setCountryCode(0 === $i % 50 ? 'FR' : $faker->countryCode());
     $customerContactAddress->setPhone($customer->getPhoneNumber());
     // Customer delivery address
     $customerDeliveryAddress = new Address();
     $customerDeliveryAddress->setType(BaseAddress::TYPE_DELIVERY);
     $customerDeliveryAddress->setCustomer($customer);
     $customerDeliveryAddress->setCurrent(true);
     $customerDeliveryAddress->setName('My delivery address');
     $customerDeliveryAddress->setFirstname($customer->getFirstname());
     $customerDeliveryAddress->setLastname($customer->getLastname());
     $customerDeliveryAddress->setAddress1($faker->address());
     $customerDeliveryAddress->setPostcode($faker->postcode());
     $customerDeliveryAddress->setCity($faker->city());
     $customerDeliveryAddress->setCountryCode(0 === $i % 50 ? 'FR' : $faker->countryCode());
     $customerDeliveryAddress->setPhone($faker->phoneNumber());
     $customer->addAddress($customerBillingAddress);
     $customer->addAddress($customerContactAddress);
     $customer->addAddress($customerDeliveryAddress);
     // User
     if (0 === $i % 10) {
         $user = $this->getReference('user-johndoe');
         $this->setReference('customer-johndoe', $customer);
     } else {
         /** @var \Sonata\UserBundle\Model\User $user */
         $user = new User();
         $user->setUsername($i . '-' . $username);
         $user->setUsernameCanonical($i . '-' . $username);
         $user->setEmail($i . '_' . $email);
         $user->setEmailCanonical($email);
         $user->setPlainPassword('customer');
     }
     $customer->setUser($user);
     $manager->persist($customerBillingAddress);
     $manager->persist($customerContactAddress);
     $manager->persist($customerDeliveryAddress);
     $manager->persist($user);
     $manager->persist($customer);
     return $customer;
 }
 /**
  * {@inheritDoc}
  */
 public function setEmailCanonical($emailCanonical)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setEmailCanonical', array($emailCanonical));
     return parent::setEmailCanonical($emailCanonical);
 }