src/EventListener/FixturesLoadedListener.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XCart\EventListener;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use XCart\Event\Service\FixturesPostLoadEvent;
  9. use XLite\Core\QuickData as QuickDataCore;
  10. use XLite\Model\Category;
  11. final class FixturesLoadedListener
  12. {
  13.     public function __construct(
  14.         private EntityManagerInterface $entityManager
  15.     ) {
  16.     }
  17.     public function handlePostLoad(FixturesPostLoadEvent $event): void
  18.     {
  19.         \XLite\Core\Database::getRepo(Category::class)?->correctCategoriesStructure();
  20.         if ($event->getType() === 'install') {
  21.             $this->quickDataRecalculate();
  22.         }
  23.     }
  24.     private function quickDataRecalculate(): void
  25.     {
  26.         $quickData QuickDataCore::getInstance();
  27.         $batchSize QuickDataCore::CHUNK_LENGTH;
  28.         do {
  29.             $products $this->entityManager
  30.                 ->createQuery('SELECT p from XLite\Model\Product p WHERE p.needProcess = 1 order by p.product_id ASC')
  31.                 ->setMaxResults($batchSize)
  32.                 ->getResult();
  33.             foreach ($products as $product) {
  34.                 $quickData->updateProductDataInternal($product);
  35.             }
  36.             $this->entityManager->flush();
  37.         } while (count($products) > 0);
  38.     }
  39. }