Ejemplo n.º 1
0
 /**
  * @param ObjectManager|EntityManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $settingsProvider = $this->container->get('orocrm_channel.provider.settings_provider');
     $lifetimeSettings = $settingsProvider->getLifetimeValueSettings();
     if (!array_key_exists(ChannelType::TYPE, $lifetimeSettings)) {
         return;
     }
     $magentoChannelSettings = $lifetimeSettings[ChannelType::TYPE];
     $customerIdentityClass = $magentoChannelSettings['entity'];
     $lifetimeField = $magentoChannelSettings['field'];
     $accountClass = $this->container->getParameter('orocrm_account.account.entity.class');
     $channelClass = $this->container->getParameter('orocrm_channel.entity.class');
     /** @var LifetimeHistoryRepository $lifetimeRepo */
     $lifetimeRepo = $manager->getRepository('OroCRMChannelBundle:LifetimeValueHistory');
     $brokenAccountQb = $this->getBrokenAccountsQueryBuilder($customerIdentityClass, $lifetimeField, $lifetimeRepo);
     $brokenAccountsData = new BufferedQueryResultIterator($brokenAccountQb);
     $toOutDate = [];
     foreach ($brokenAccountsData as $brokenDataRow) {
         /** @var Account $account */
         $account = $manager->getReference($accountClass, $brokenDataRow['account_id']);
         /** @var Channel $channel */
         $channel = $manager->getReference($channelClass, $brokenDataRow['channel_id']);
         $lifetimeAmount = $lifetimeRepo->calculateAccountLifetime($customerIdentityClass, $lifetimeField, $account, $channel);
         $history = new LifetimeValueHistory();
         $history->setAmount($lifetimeAmount);
         $history->setDataChannel($channel);
         $history->setAccount($account);
         $manager->persist($history);
         $toOutDate[] = [$account, $channel, $history];
     }
     $manager->flush();
     foreach (array_chunk($toOutDate, self::MAX_UPDATE_CHUNK_SIZE) as $chunks) {
         $lifetimeRepo->massStatusUpdate($chunks);
     }
 }
Ejemplo n.º 2
0
 public function testPrePersist()
 {
     $this->assertNull($this->entity->getCreatedAt());
     $this->entity->prePersist();
     $result = $this->entity->getCreatedAt();
     $this->assertInstanceOf('DateTime', $result);
     $this->assertLessThan(3, $result->diff(new \DateTime())->s);
     $this->entity->prePersist();
     $this->assertSame($result, $this->entity->getCreatedAt());
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $handle = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'history_data.csv', 'r');
     $headers = fgetcsv($handle, 1000, ',');
     while (($data = fgetcsv($handle, 1000, ',')) !== false) {
         $combined = array_combine($headers, $data);
         $logDate = new \DateTime($combined['Created Date UTC'], new \DateTimeZone('UTC'));
         $historyEntry = new LifetimeValueHistory();
         $historyEntry->setAccount($this->ensureAccountCreated($manager, $combined['Account name']));
         $historyEntry->setDataChannel($this->ensureChannelCreated($manager, $combined['Channel name'], $logDate));
         $historyEntry->setCreatedAt($logDate);
         $historyEntry->setStatus($combined['Status']);
         $historyEntry->setAmount($combined['Amount']);
         $manager->persist($historyEntry);
     }
     $manager->flush();
     fclose($handle);
 }
Ejemplo n.º 4
0
 /**
  * @param string  $customerIdentity
  * @param Account $account
  * @param Channel $channel
  *
  * @return LifetimeValueHistory
  */
 protected function createHistoryEntry($customerIdentity, Account $account, Channel $channel)
 {
     $lifetimeAmount = $this->lifetimeRepo->calculateAccountLifetime($customerIdentity, $this->customerIdentities[$customerIdentity], $account, $channel);
     $history = new LifetimeValueHistory();
     $history->setAmount($lifetimeAmount);
     $history->setDataChannel($channel);
     $history->setAccount($account);
     return $history;
 }