@@ 52-96 (lines=45) @@ | ||
49 | * |
|
50 | * @throws InvalidArgumentException |
|
51 | */ |
|
52 | public function askStore( |
|
53 | InputInterface $input, |
|
54 | OutputInterface $output, |
|
55 | $argumentName = 'store', |
|
56 | $withDefaultStore = false |
|
57 | ) { |
|
58 | /* @var $storeManager \Mage_Core_Model_App */ |
|
59 | $storeManager = \Mage::app(); |
|
60 | ||
61 | try { |
|
62 | if ($input->getArgument($argumentName) === null) { |
|
63 | throw new RuntimeException('No store given'); |
|
64 | } |
|
65 | /** @var $store \Mage_Core_Model_Store */ |
|
66 | $store = $storeManager->getStore($input->getArgument($argumentName)); |
|
67 | } catch (Exception $e) { |
|
68 | $stores = array(); |
|
69 | $i = 0; |
|
70 | ||
71 | foreach ($storeManager->getStores($withDefaultStore) as $store) { |
|
72 | $stores[$i] = $store->getId(); |
|
73 | $question[] = '<comment>[' . ($i + 1) . ']</comment> ' . $store->getCode() . ' - ' . $store->getName() . PHP_EOL; |
|
74 | $i++; |
|
75 | } |
|
76 | ||
77 | if (count($stores) > 1) { |
|
78 | $question[] = '<question>Please select a store: </question>'; |
|
79 | $storeId = $this->askAndValidate($output, $question, |
|
80 | function($typeInput) use ($stores) { |
|
81 | if (!isset($stores[$typeInput - 1])) { |
|
82 | throw new InvalidArgumentException('Invalid store'); |
|
83 | } |
|
84 | ||
85 | return $stores[$typeInput - 1]; |
|
86 | }); |
|
87 | } else { |
|
88 | // only one store view available -> take it |
|
89 | $storeId = $stores[0]; |
|
90 | } |
|
91 | ||
92 | $store = $storeManager->getStore($storeId); |
|
93 | } |
|
94 | ||
95 | return $store; |
|
96 | } |
|
97 | ||
98 | /** |
|
99 | * @param InputInterface $input |
|
@@ 107-144 (lines=38) @@ | ||
104 | * @throws InvalidArgumentException |
|
105 | * @throws RuntimeException |
|
106 | */ |
|
107 | public function askWebsite(InputInterface $input, OutputInterface $output, $argumentName = 'website') |
|
108 | { |
|
109 | /* @var $storeManager \Mage_Core_Model_App */ |
|
110 | $storeManager = \Mage::app(); |
|
111 | ||
112 | try { |
|
113 | if ($input->getArgument($argumentName) === null) { |
|
114 | throw new RuntimeException('No website given'); |
|
115 | } |
|
116 | /** @var $website \Mage_Core_Model_Website */ |
|
117 | $website = $storeManager->getWebsite($input->getArgument($argumentName)); |
|
118 | } catch (Exception $e) { |
|
119 | $i = 0; |
|
120 | $websites = array(); |
|
121 | foreach ($storeManager->getWebsites() as $website) { |
|
122 | $websites[$i] = $website->getId(); |
|
123 | $question[] = '<comment>[' . ($i + 1) . ']</comment> ' . $website->getCode() . ' - ' . $website->getName() . PHP_EOL; |
|
124 | $i++; |
|
125 | } |
|
126 | if (count($websites) == 1) { |
|
127 | return $storeManager->getWebsite($websites[0]); |
|
128 | } |
|
129 | $question[] = '<question>Please select a website: </question>'; |
|
130 | ||
131 | $websiteId = $this->askAndValidate($output, $question, |
|
132 | function($typeInput) use ($websites) { |
|
133 | if (!isset($websites[$typeInput - 1])) { |
|
134 | throw new InvalidArgumentException('Invalid store'); |
|
135 | } |
|
136 | ||
137 | return $websites[$typeInput - 1]; |
|
138 | }); |
|
139 | ||
140 | $website = $storeManager->getWebsite($websiteId); |
|
141 | } |
|
142 | ||
143 | return $website; |
|
144 | } |
|
145 | ||
146 | /** |
|
147 | * @param InputInterface $input |