WebsiteListCommand.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Store\Console\Command;
  8. use Symfony\Component\Console\Helper\Table;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. use Symfony\Component\Console\Command\Command;
  12. /**
  13. * Class WebsiteListCommand
  14. *
  15. * Command for listing the configured websites
  16. */
  17. class WebsiteListCommand extends Command
  18. {
  19. /**
  20. * @var \Magento\Store\Api\WebsiteManagementInterface
  21. */
  22. private $manager;
  23. /**
  24. */
  25. public function __construct(
  26. \Magento\Store\Api\WebsiteRepositoryInterface $websiteManagement
  27. ) {
  28. $this->manager = $websiteManagement;
  29. parent::__construct();
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function configure()
  35. {
  36. $this->setName('store:website:list')
  37. ->setDescription('Displays the list of websites');
  38. parent::configure();
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function execute(InputInterface $input, OutputInterface $output)
  44. {
  45. try {
  46. $table = new Table($output);
  47. $table->setHeaders(['ID', 'Default Group Id', 'Name', 'Code', 'Sort Order', 'Is Default']);
  48. foreach ($this->manager->getList() as $website) {
  49. $table->addRow([
  50. $website->getId(),
  51. $website->getDefaultGroupId(),
  52. $website->getName(),
  53. $website->getCode(),
  54. $website->getData('sort_order'),
  55. $website->getData('is_default'),
  56. ]);
  57. }
  58. $table->render();
  59. return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
  60. } catch (\Exception $e) {
  61. $output->writeln('<error>' . $e->getMessage() . '</error>');
  62. if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
  63. $output->writeln($e->getTraceAsString());
  64. }
  65. return \Magento\Framework\Console\Cli::RETURN_FAILURE;
  66. }
  67. }
  68. }