public function askStore(InputInterface $input, OutputInterface $output, $argumentName = 'store', $withDefaultStore = false)
{
/* @var $storeManager \Mage_Core_Model_App */
$storeManager = \Mage::app();
try {
if ($input->getArgument($argumentName) === null) {
throw new RuntimeException('No store given');
}
/** @var $store \Mage_Core_Model_Store */
$store = $storeManager->getStore($input->getArgument($argumentName));
} catch (Exception $e) {
if (!$input->isInteractive()) {
throw new RuntimeException(sprintf('Require %s parameter', $argumentName));
}
$stores = array();
$question = array();
$i = 0;
foreach ($storeManager->getStores($withDefaultStore) as $store) {
$stores[$i] = $store->getId();
$question[] = sprintf('<comment>[%d]</comment> %s - %s' . PHP_EOL, ++$i, $store->getCode(), $store->getName());
}
if (count($stores) > 1) {
$question[] = '<question>Please select a store: </question>';
$storeId = $this->askAndValidate($output, $question, function ($typeInput) use($stores) {
if (!isset($stores[$typeInput - 1])) {
throw new InvalidArgumentException('Invalid store');
}
return $stores[$typeInput - 1];
});
} else {
// only one store view available -> take it
$storeId = $stores[0];
}
$store = $storeManager->getStore($storeId);
}
return $store;
}