/**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $internalRatings = $manager->getRepository(ExtendHelper::buildEnumValueClassName(Account::INTERNAL_RATING_CODE))->findAll();
     /** @var \Oro\Bundle\UserBundle\Entity\User $accountOwner */
     $accountOwner = $manager->getRepository('OroUserBundle:User')->findOneBy([]);
     foreach ($this->accounts as $accountName => $accountData) {
         /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountGroup $accountGroup */
         $accountGroup = $this->getReference(LoadAccountGroupDemoData::ACCOUNT_GROUP_REFERENCE_PREFIX . $accountData['group']);
         $account = new Account();
         $account->setName($accountName)->setGroup($accountGroup)->setParent(null)->setOrganization($accountOwner->getOrganization())->setOwner($accountOwner)->setInternalRating($internalRatings[array_rand($internalRatings)]);
         $manager->persist($account);
         $this->addReference(static::ACCOUNT_REFERENCE_PREFIX . $account->getName(), $account);
         if (isset($accountData['subsidiaries'])) {
             foreach ($accountData['subsidiaries'] as $subsidiaryName => $subsidiaryData) {
                 /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountGroup $subsidiaryGroup */
                 $subsidiaryGroup = $this->getReference(LoadAccountGroupDemoData::ACCOUNT_GROUP_REFERENCE_PREFIX . $subsidiaryData['group']);
                 $subsidiary = new Account();
                 $subsidiary->setName($subsidiaryName)->setGroup($subsidiaryGroup)->setParent($account)->setOrganization($accountOwner->getOrganization())->setOwner($accountOwner)->setInternalRating($internalRatings[array_rand($internalRatings)]);
                 $manager->persist($subsidiary);
                 $this->addReference(static::ACCOUNT_REFERENCE_PREFIX . $subsidiary->getName(), $subsidiary);
             }
         }
     }
     $manager->flush();
 }
 /**
  * @param ObjectManager $manager
  */
 protected function loadAccounts(ObjectManager $manager)
 {
     $defaultUser = $this->getUser($manager);
     $organization = $defaultUser->getOrganization();
     foreach ($this->accounts as $item) {
         $account = new Account();
         $account->setName($item['name'])->setOrganization($organization);
         $manager->persist($account);
         $this->addReference($item['name'], $account);
     }
     $manager->flush();
 }
 protected function setUp()
 {
     $this->form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $this->request = new Request();
     $this->manager = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock();
     $this->converter = $this->getMockBuilder('OroB2B\\Bundle\\SaleBundle\\Model\\QuoteToOrderConverter')->disableOriginalConstructor()->getMock();
     $account = new Account();
     $account->setName('account');
     $this->accountUser = new AccountUser();
     $this->accountUser->setEmail('*****@*****.**')->setAccount($account);
     $this->handler = new QuoteToOrderHandler($this->form, $this->request, $this->manager, $this->converter, $this->accountUser);
 }
 /**
  * @param ObjectManager $manager
  * @param string $name
  * @param Account $parent
  * @param AccountGroup $group
  * @return Account
  */
 protected function createAccount(ObjectManager $manager, $name, Account $parent = null, AccountGroup $group = null)
 {
     $account = new Account();
     $account->setName($name);
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $account->setOrganization($organization);
     if ($parent) {
         $account->setParent($parent);
     }
     if ($group) {
         $account->setGroup($group);
     }
     $manager->persist($account);
     $this->addReference($name, $account);
     return $account;
 }
 /**
  * @param string $accountName
  * @return AccountUser
  */
 protected function createAccountUser($accountName)
 {
     $accountUser = new AccountUser();
     $accountUser->setFirstName($accountName . ' first')->setLastName($accountName . ' last')->setSalt(null);
     $account = new Account();
     $account->setName($accountName)->addUser($accountUser);
     return $accountUser;
 }
 /**
  * @ORM\PrePersist
  */
 public function createAccount()
 {
     if (!$this->account) {
         $this->account = new Account();
         $this->account->setOrganization($this->organization);
         $this->account->setName(sprintf('%s %s', $this->firstName, $this->lastName));
         if ($this->getOwner() && !$this->account->getOwner()) {
             $this->account->setOwner($this->getOwner(), false);
         }
     }
 }