/**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $user = $this->getUser($manager);
     $requests = $this->getRequests($manager);
     $organization = $user->getOrganization();
     $accounts = $this->getAccounts($manager);
     for ($i = 0; $i < 20; $i++) {
         /* @var $account Account */
         $account = $accounts[rand(0, count($accounts) - 1)];
         if (!$account) {
             $accountUser = null;
         } else {
             $accountUsers = array_merge([null], $account->getUsers()->getValues());
             /* @var $accountUser AccountUser */
             $accountUser = $accountUsers[rand(0, count($accountUsers) - 1)];
         }
         // set date in future
         $validUntil = new \DateTime('now');
         $addDays = sprintf('+%s days', rand(10, 100));
         $validUntil->modify($addDays);
         $quote = new Quote();
         $quote->setOwner($user)->setOrganization($organization)->setValidUntil($validUntil)->setAccountUser($accountUser)->setAccount($account)->setLocked(rand(0, 1));
         if (1 === rand(1, 3)) {
             $quote->setRequest($requests[rand(1, count($requests) - 1)]);
         }
         $this->processQuoteProducts($quote, $manager);
         $manager->persist($quote);
     }
     $manager->flush();
 }
Exemplo n.º 2
0
 /**
  * @param int $ownerId
  * @param QuoteProduct[] $items
  * @return Quote
  */
 protected function getQuote($ownerId, array $items = [])
 {
     $quote = new Quote();
     $quote->setOwner($this->getEntity('Oro\\Bundle\\UserBundle\\Entity\\User', $ownerId));
     foreach ($items as $item) {
         $quote->addQuoteProduct($item);
     }
     return $quote;
 }
 public function testPersistQuote()
 {
     /* @var $em EntityManager */
     $em = static::getContainer()->get('doctrine')->getManagerForClass('OroB2BSaleBundle:Quote');
     $quote = new Quote();
     $quote->setOwner($this->getReference(LoadUserData::USER1));
     $this->assertNull($quote->getQid());
     $em->persist($quote);
     $this->assertEquals(null, $quote->getQid());
     $em->flush();
     $this->assertNotNull($quote->getId());
     $em->clear();
     $quote = $em->getRepository('OroB2BSaleBundle:Quote')->find($quote->getId());
     $this->assertEquals($quote->getId(), $quote->getQid());
 }
Exemplo n.º 4
0
 /**
  * @param int $ownerId
  * @param int $accountUserId
  * @param int $accountId
  * @param QuoteProduct[] $items
  * @param bool $locked
  * @return Quote
  */
 protected function getQuote($ownerId, $accountUserId = null, $accountId = null, array $items = [], $locked = false)
 {
     $quote = new Quote();
     $quote->setOwner($this->getEntity('Oro\\Bundle\\UserBundle\\Entity\\User', $ownerId));
     if (null !== $accountUserId) {
         $quote->setAccountUser($this->getEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\AccountUser', $accountUserId));
     }
     if (null !== $accountId) {
         $quote->setAccount($this->getEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\Account', $accountId));
     }
     foreach ($items as $item) {
         $quote->addQuoteProduct($item);
     }
     $quote->setLocked($locked);
     return $quote;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $user = $this->getUser($manager);
     $requests = $this->getRequests($manager);
     $organization = $user->getOrganization();
     for ($i = 0; $i < 20; $i++) {
         // set date in future
         $validUntil = new \DateTime('now');
         $addDays = sprintf('+%s days', rand(10, 100));
         $validUntil->modify($addDays);
         $quote = new Quote();
         $quote->setOwner($user)->setOrganization($organization)->setValidUntil($validUntil);
         if (1 === rand(1, 3)) {
             $quote->setRequest($requests[rand(1, count($requests) - 1)]);
         }
         $this->processQuoteProducts($quote, $manager);
         $manager->persist($quote);
     }
     $manager->flush();
 }