diff --git a/Console/Command/StoreCreateCommand.php b/Console/Command/StoreCreateCommand.php index a571608..579a142 100644 --- a/Console/Command/StoreCreateCommand.php +++ b/Console/Command/StoreCreateCommand.php @@ -1,6 +1,6 @@ websiteFactory = $websiteFactory; $this->groupFactory = $groupFactory; $this->storeFactory = $storeFactory; $this->filterManager = $filterManager; @@ -88,15 +79,12 @@ protected function configure() 0 ) ; - $groups = $this->getStoreGroups(); - $defaultGroup = current($groups); $this->addOption( self::INPUT_OPTION_GROUP, 'g', InputOption::VALUE_OPTIONAL, - 'Group ID (php bin/magento store:list).', - $defaultGroup + 'Group ID (php bin/magento store:list).' ); parent::configure(); @@ -110,14 +98,18 @@ protected function execute(InputInterface $input, OutputInterface $output) $io = new SymfonyStyle($input, $output); try { - $groupId = (int) $input->getOption(self::INPUT_OPTION_GROUP); + $groupId = $input->getOption(self::INPUT_OPTION_GROUP); $storeViewName = $input->getArgument(self::INPUT_ARGUMENT_NAME); $storeViewCode = $input->getArgument(self::INPUT_ARGUMENT_CODE); $isActive = (bool) $input->getArgument(self::INPUT_ARGUMENT_IS_ACTIVE); $sortOrder = (int) $input->getArgument(self::INPUT_ARGUMENT_SORT_ORDER); + if ($groupId === null) { + $groupId = $this->getDefaultStoreGroupId(); + } + $data = [ - self::INPUT_OPTION_GROUP => $groupId, + self::INPUT_OPTION_GROUP => (int) $groupId, self::INPUT_ARGUMENT_NAME => $storeViewName, self::INPUT_ARGUMENT_CODE => $storeViewCode, self::INPUT_ARGUMENT_IS_ACTIVE => $isActive, @@ -152,23 +144,13 @@ protected function execute(InputInterface $input, OutputInterface $output) } /** - * Retrieve list of store groups - * - * @return array + * @return int|null */ - private function getStoreGroups() + private function getDefaultStoreGroupId() { - $websites = $this->websiteFactory->create()->getCollection(); - $allgroups = $this->groupFactory->create()->getCollection(); - $groups = []; - foreach ($websites as $website) { - foreach ($allgroups as $group) { - if ($group->getWebsiteId() == $website->getId()) { - $groups[$group->getWebsiteId() . '-' . $group->getId()] = $group->getId(); - } - } - } - - return $groups; + return $this->groupFactory->create()->getCollection() + ->setPageSize(1) + ->getFirstItem() + ->getId(); } }