Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. namespace AppBundle\Command;
  2.  
  3. use AppBundle\Entity\User;
  4. use AppBundle\Services\ElasticSearchService;
  5. use AppBundle\Services\TaxonomyManager;
  6. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  7. use Symfony\Component\Console\Input\InputArgument;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Input\InputOption;
  10. use Symfony\Component\Console\Output\Output;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12.  
  13. use League\Csv\Reader;
  14. use League\Csv\Statement;
  15.  
  16. class BuildProductIndexCommand extends ContainerAwareCommand
  17. {
  18.     protected function configure()
  19.     {
  20.         $this
  21.             ->setName('index:products')
  22.         ;
  23.     }
  24.  
  25.     protected function execute(InputInterface $input, OutputInterface $output)
  26.     {
  27.         define('tradeSubdomain', 'hagebau');
  28.  
  29.         $container = $this->getContainer();
  30.         $output->writeln('Building index...');
  31.  
  32.         /** @var TaxonomyManager $taxonomyManager */
  33.         $taxonomyManager = $container->get('manager.taxonomy');
  34.  
  35.         /** @var ElasticSearchService $elasticSearchService */
  36.         $elasticSearchService = $container->get('service.elastic_search');
  37.         $products = $taxonomyManager->findAllTaxonomyItems('products');
  38.  
  39.         foreach ($products as $product) {
  40.             if ((String) $product->lookup('root_product') != '') {
  41.                 continue;
  42.             }
  43.  
  44.             if ((String) $product->lookup('category') == '') {
  45.                 continue;
  46.             }
  47.  
  48.             $elasticSearchService->buildProductIndex($product);
  49.             $output->writeln(sprintf('Product with id: %s has been indexed.', $product->getId()));
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement