Пример #1
0
 /**
  * Init synonym model
  *
  * @return \Mirasvit\Search\Model\Synonym
  */
 protected function initModel()
 {
     $model = $this->synonymFactory->create();
     if ($this->getRequest()->getParam('id')) {
         $model->load($this->getRequest()->getParam('id'));
     }
     $this->registry->register('current_model', $model);
     return $model;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('remove')) {
         $store = $input->getOption('store');
         $collection = $this->synonymFactory->create()->getCollection();
         if ($store) {
             $collection->addFieldToFilter('store_id', $store);
         }
         $cnt = 0;
         foreach ($collection as $item) {
             $item->delete();
             $cnt++;
             if ($cnt % 1000 == 0) {
                 $output->writeln("<info>{$cnt} synonyms are removed...</info>");
             }
         }
         $output->writeln("<info>{$cnt} synonyms are removed.</info>");
         return;
     }
     if ($input->getOption('file') && $input->getOption('store')) {
         $file = $this->config->getSynonymDirectoryPath() . DIRECTORY_SEPARATOR . $input->getOption('file');
         $store = $input->getOption('store');
         $result = $this->synonymFactory->create()->import($file, $store);
         $output->writeln("<info>Imported {$result['synonyms']} synonyms</info>");
     } else {
         $output->writeln('<info>Available files:</info>');
         foreach ($this->synonymFactory->create()->getAvailableFiles() as $file) {
             $info = pathinfo($file);
             $output->writeln("    {$info['basename']}");
         }
         $output->writeln('<info>Available stores:</info>');
         foreach ($this->storeManager->getStores(true) as $store) {
             $output->writeln("    {$store->getId()} [{$store->getCode()}]");
         }
     }
 }