|
8 | 8 | /** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */ |
9 | 9 | ?> |
10 | 10 | <?php if ($websites = $block->getWebsites()): ?> |
11 | | -<div class="store-switcher store-view"> |
12 | | - <span class="store-switcher-label"><?= $block->escapeHtml(__('Scope:')) ?></span> |
13 | | - <div class="actions dropdown closable"> |
14 | | - <input type="hidden" name="store_switcher" id="store_switcher" |
15 | | - data-role="store-view-id" data-param="<?= $block->escapeHtmlAttr($block->getStoreVarName()) ?>" |
16 | | - value="<?= $block->escapeHtml($block->getStoreId()) ?>" |
17 | | - <?= /* @noEscape */ $block->getUiId() ?> /> |
18 | | - <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag( |
19 | | - 'onchange', |
20 | | - 'switchScope(this);', |
21 | | - '#store_switcher' |
22 | | - ) ?> |
23 | | - <input type="hidden" name="store_group_switcher" id="store_group_switcher" |
24 | | - data-role="store-group-id" data-param="<?= $block->escapeHtmlAttr($block->getStoreGroupVarName()) ?>" |
25 | | - value="<?= $block->escapeHtml($block->getStoreGroupId()) ?>" |
26 | | - <?= /* @noEscape */ $block->getUiId() ?> /> |
27 | | - <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag( |
28 | | - 'onchange', |
29 | | - 'switchScope(this);', |
30 | | - '#store_group_switcher' |
31 | | - ) ?> |
32 | | - <input type="hidden" name="website_switcher" id="website_switcher" |
33 | | - data-role="website-id" data-param="<?= $block->escapeHtmlAttr($block->getWebsiteVarName()) ?>" |
34 | | - value="<?= $block->escapeHtml($block->getWebsiteId()) ?>" |
35 | | - <?= /* @noEscape */ $block->getUiId() ?> /> |
36 | | - <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag( |
37 | | - 'onchange', |
38 | | - 'switchScope(this);', |
39 | | - '#website_switcher' |
40 | | - ) ?> |
41 | | - <button |
42 | | - type="button" |
43 | | - class="admin__action-dropdown" |
44 | | - data-mage-init='{"dropdown":{}}' |
45 | | - data-toggle="dropdown" |
46 | | - aria-haspopup="true" |
47 | | - id="store-change-button"> |
48 | | - <?= $block->escapeHtml($block->getCurrentSelectionName()) ?> |
49 | | - </button> |
50 | | - <ul class="dropdown-menu" data-role="stores-list"> |
51 | | - <?php if ($block->hasDefaultOption()): ?> |
52 | | - <li class="store-switcher-all <?php |
53 | | - if (!($block->getDefaultSelectionName() != $block->getCurrentSelectionName())): ?>disabled<?php endif; |
54 | | - ?> <?php if (!$block->hasScopeSelected()): ?>current<?php endif; ?>"> |
55 | | - <?php if ($block->getDefaultSelectionName() != $block->getCurrentSelectionName()): ?> |
56 | | - <a data-role="store-view-id" data-value="" href="#"> |
57 | | - <?= $block->escapeHtml($block->getDefaultSelectionName()) ?> |
58 | | - </a> |
59 | | - <?php else: ?> |
60 | | - <span><?= $block->escapeHtml($block->getDefaultSelectionName()) ?></span> |
61 | | - <?php endif; ?> |
62 | | - </li> |
63 | | - <?php endif; ?> |
64 | | - <?php foreach ($websites as $website): ?> |
65 | | - <?php $showWebsite = false; ?> |
66 | | - <?php foreach ($website->getGroups() as $group): ?> |
67 | | - <?php $showGroup = false; ?> |
68 | | - <?php foreach ($block->getStores($group) as $store): ?> |
69 | | - <?php if ($showWebsite == false): ?> |
70 | | - <?php $showWebsite = true; ?> |
71 | | - <li class="store-switcher-website <?php if (!($block->isWebsiteSwitchEnabled() && |
72 | | - ! $block->isWebsiteSelected($website))): ?>disabled<?php endif; ?> <?php |
73 | | -if ($block->isWebsiteSelected($website)): ?>current<?php endif; ?>"> |
74 | | - <?php if ($block->isWebsiteSwitchEnabled() && ! $block->isWebsiteSelected($website)): ?> |
75 | | - <a data-role="website-id" data-value="<?= $block->escapeHtmlAttr($website->getId()); |
76 | | - ?>" href="#"> |
77 | | - <?= $block->escapeHtml($website->getName()) ?> |
78 | | - </a> |
79 | | - <?php else: ?> |
80 | | - <span><?= $block->escapeHtml($website->getName()) ?></span> |
81 | | - <?php endif; ?> |
82 | | - </li> |
| 11 | + <div class="store-switcher store-view"> |
| 12 | + <span class="store-switcher-label"><?= $block->escapeHtml(__('Scope:')) ?></span> |
| 13 | + <div class="actions dropdown closable"> |
| 14 | + <input type="hidden" name="store_switcher" id="store_switcher" |
| 15 | + data-role="store-view-id" data-param="<?= $block->escapeHtmlAttr($block->getStoreVarName()) ?>" |
| 16 | + value="<?= $block->escapeHtml($block->getStoreId()) ?>" |
| 17 | + <?= /* @noEscape */ $block->getUiId() ?> /> |
| 18 | + <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag( |
| 19 | + 'onchange', |
| 20 | + 'switchScope(this);', |
| 21 | + '#store_switcher' |
| 22 | + ) ?> |
| 23 | + <input type="hidden" name="store_group_switcher" id="store_group_switcher" |
| 24 | + data-role="store-group-id" data-param="<?= $block->escapeHtmlAttr($block->getStoreGroupVarName()) ?>" |
| 25 | + value="<?= $block->escapeHtml($block->getStoreGroupId()) ?>" |
| 26 | + <?= /* @noEscape */ $block->getUiId() ?> /> |
| 27 | + <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag( |
| 28 | + 'onchange', |
| 29 | + 'switchScope(this);', |
| 30 | + '#store_group_switcher' |
| 31 | + ) ?> |
| 32 | + <input type="hidden" name="website_switcher" id="website_switcher" |
| 33 | + data-role="website-id" data-param="<?= $block->escapeHtmlAttr($block->getWebsiteVarName()) ?>" |
| 34 | + value="<?= $block->escapeHtml($block->getWebsiteId()) ?>" |
| 35 | + <?= /* @noEscape */ $block->getUiId() ?> /> |
| 36 | + <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag( |
| 37 | + 'onchange', |
| 38 | + 'switchScope(this);', |
| 39 | + '#website_switcher' |
| 40 | + ) ?> |
| 41 | + <button |
| 42 | + type="button" |
| 43 | + class="admin__action-dropdown" |
| 44 | + data-mage-init='{"dropdown":{}}' |
| 45 | + data-toggle="dropdown" |
| 46 | + aria-haspopup="true" |
| 47 | + id="store-change-button"> |
| 48 | + <?= $block->escapeHtml($block->getCurrentSelectionName()) ?> |
| 49 | + </button> |
| 50 | + <ul class="dropdown-menu" data-role="stores-list"> |
| 51 | + <?php if ($block->hasDefaultOption()): ?> |
| 52 | + <li class="store-switcher-all <?php |
| 53 | + if (!($block->getDefaultSelectionName() != $block->getCurrentSelectionName())): ?>disabled<?php endif; |
| 54 | + ?> <?php if (!$block->hasScopeSelected()): ?>current<?php endif; ?>"> |
| 55 | + <?php if ($block->getDefaultSelectionName() != $block->getCurrentSelectionName()): ?> |
| 56 | + <a data-role="store-view-id" data-value="" href="#"> |
| 57 | + <?= $block->escapeHtml($block->getDefaultSelectionName()) ?> |
| 58 | + </a> |
| 59 | + <?php else: ?> |
| 60 | + <span><?= $block->escapeHtml($block->getDefaultSelectionName()) ?></span> |
83 | 61 | <?php endif; ?> |
84 | | - <?php if ($showGroup == false): ?> |
85 | | - <?php $showGroup = true; ?> |
86 | | - <li class="store-switcher-store <?php if (!($block->isStoreGroupSwitchEnabled() && |
87 | | - ! $block->isStoreGroupSelected($group))): ?>disabled<?php endif; ?> <?php |
88 | | -if ($block->isStoreGroupSelected($group)): ?>current<?php endif; ?>"> |
89 | | - <?php if ($block->isStoreGroupSwitchEnabled() && |
90 | | - ! $block->isStoreGroupSelected($group)): ?> |
91 | | - <a data-role="store-group-id" |
92 | | - data-value="<?= $block->escapeHtmlAttr($group->getId()) ?>" href="#"> |
93 | | - <?= $block->escapeHtml($group->getName()) ?> |
| 62 | + </li> |
| 63 | + <?php endif; ?> |
| 64 | + <?php foreach ($websites as $website): ?> |
| 65 | + <?php $showWebsite = false; ?> |
| 66 | + <?php foreach ($website->getGroups() as $group): ?> |
| 67 | + <?php $showGroup = false; ?> |
| 68 | + <?php foreach ($block->getStores($group) as $store): ?> |
| 69 | + <?php if ($showWebsite == false): ?> |
| 70 | + <?php $showWebsite = true; ?> |
| 71 | + <li class="store-switcher-website <?php if (!($block->isWebsiteSwitchEnabled() && |
| 72 | + ! $block->isWebsiteSelected($website))): ?>disabled<?php endif; ?> <?php |
| 73 | + if ($block->isWebsiteSelected($website)): ?>current<?php endif; ?>"> |
| 74 | + <?php if ($block->isWebsiteSwitchEnabled() && ! $block->isWebsiteSelected($website)): ?> |
| 75 | + <a data-role="website-id" data-value="<?= $block->escapeHtmlAttr($website->getId()); |
| 76 | + ?>" href="#"> |
| 77 | + <?= $block->escapeHtml($website->getName()) ?> |
| 78 | + </a> |
| 79 | + <?php else: ?> |
| 80 | + <span><?= $block->escapeHtml($website->getName()) ?></span> |
| 81 | + <?php endif; ?> |
| 82 | + </li> |
| 83 | + <?php endif; ?> |
| 84 | + <?php if ($showGroup == false): ?> |
| 85 | + <?php $showGroup = true; ?> |
| 86 | + <li class="store-switcher-store <?php if (!($block->isStoreGroupSwitchEnabled() && |
| 87 | + ! $block->isStoreGroupSelected($group))): ?>disabled<?php endif; ?> <?php |
| 88 | + if ($block->isStoreGroupSelected($group)): ?>current<?php endif; ?>"> |
| 89 | + <?php if ($block->isStoreGroupSwitchEnabled() && |
| 90 | + ! $block->isStoreGroupSelected($group)): ?> |
| 91 | + <a data-role="store-group-id" |
| 92 | + data-value="<?= $block->escapeHtmlAttr($group->getId()) ?>" href="#"> |
| 93 | + <?= $block->escapeHtml($group->getName()) ?> |
| 94 | + </a> |
| 95 | + <?php else: ?> |
| 96 | + <span><?= $block->escapeHtml($group->getName()) ?></span> |
| 97 | + <?php endif; ?> |
| 98 | + </li> |
| 99 | + <?php endif; ?> |
| 100 | + <li class="store-switcher-store-view <?php if (!($block->isStoreSwitchEnabled() && |
| 101 | + !$block->isStoreSelected($store))): ?>disabled<?php endif; ?> <?php |
| 102 | + if ($block->isStoreSelected($store)):?>current<?php endif; ?>"> |
| 103 | + <?php if ($block->isStoreSwitchEnabled() && ! $block->isStoreSelected($store)): ?> |
| 104 | + <a data-role="store-view-id" |
| 105 | + data-value="<?= $block->escapeHtmlAttr($store->getId()) ?>" href="#"> |
| 106 | + <?= $block->escapeHtml($store->getName()) ?> |
94 | 107 | </a> |
95 | 108 | <?php else: ?> |
96 | | - <span><?= $block->escapeHtml($group->getName()) ?></span> |
| 109 | + <span><?= $block->escapeHtml($store->getName()) ?></span> |
97 | 110 | <?php endif; ?> |
98 | 111 | </li> |
99 | | - <?php endif; ?> |
100 | | - <li class="store-switcher-store-view <?php if (!($block->isStoreSwitchEnabled() && |
101 | | - !$block->isStoreSelected($store))): ?>disabled<?php endif; ?> <?php |
102 | | -if ($block->isStoreSelected($store)):?>current<?php endif; ?>"> |
103 | | - <?php if ($block->isStoreSwitchEnabled() && ! $block->isStoreSelected($store)): ?> |
104 | | - <a data-role="store-view-id" |
105 | | - data-value="<?= $block->escapeHtmlAttr($store->getId()) ?>" href="#"> |
106 | | - <?= $block->escapeHtml($store->getName()) ?> |
107 | | - </a> |
108 | | - <?php else: ?> |
109 | | - <span><?= $block->escapeHtml($store->getName()) ?></span> |
110 | | - <?php endif; ?> |
111 | | - </li> |
| 112 | + <?php endforeach; ?> |
112 | 113 | <?php endforeach; ?> |
113 | 114 | <?php endforeach; ?> |
114 | | - <?php endforeach; ?> |
115 | | - <?php if ($block->getShowManageStoresLink() && |
116 | | - $block->getAuthorization()->isAllowed('Magento_Backend::store')): ?> |
117 | | - <li class="dropdown-toolbar"> |
118 | | - <a href="<?= /* @noEscape */ $block->getUrl('*/system_store'); |
119 | | - ?>"><?= $block->escapeHtml(__('Stores Configuration')) ?></a> |
120 | | - </li> |
121 | | - <?php endif; ?> |
122 | | - </ul> |
| 115 | + <?php if ($block->getShowManageStoresLink() && |
| 116 | + $block->getAuthorization()->isAllowed('Magento_Backend::store')): ?> |
| 117 | + <li class="dropdown-toolbar"> |
| 118 | + <a href="<?= /* @noEscape */ $block->getUrl('*/system_store'); |
| 119 | + ?>"><?= $block->escapeHtml(__('Stores Configuration')) ?></a> |
| 120 | + </li> |
| 121 | + <?php endif; ?> |
| 122 | + </ul> |
| 123 | + </div> |
| 124 | + <?= $block->getHintHtml() ?> |
123 | 125 | </div> |
124 | | - <?= $block->getHintHtml() ?> |
125 | | -</div> |
126 | | - |
127 | | - <?php |
128 | | - $useConfirm = (int)$block->getUseConfirm(); |
129 | | - $scriptString = <<<script |
130 | | -require([ |
131 | | - 'jquery', |
132 | | - 'Magento_Ui/js/modal/confirm' |
133 | | -], function(jQuery, confirm){ |
134 | | -
|
135 | | - (function($) { |
136 | | - var storesList = $('[data-role=stores-list]'); |
137 | | - storesList.on('click', '[data-value]', function(event) { |
138 | | - var val = $(event.target).data('value'); |
139 | | - var role = $(event.target).data('role'); |
140 | | - var switcher = $('[data-role='+role+']'); |
141 | | -
|
142 | | - event.preventDefault(); |
143 | | -
|
144 | | - if (!switcher.val() || val != switcher.val()) { |
145 | | - switcher.val(val).trigger('change'); // Set the value & trigger event |
146 | | - } |
147 | | - }); |
148 | | - })(jQuery); |
149 | | -
|
150 | | - var scopeSwitcherHandler; |
151 | 126 |
|
152 | | - function switchScope(obj) { |
153 | | - var switcher = jQuery(obj); |
154 | | - var scopeId = switcher.val(); |
155 | | - var scopeParams = ''; |
156 | | - if (scopeId) { |
157 | | - scopeParams = switcher.data('param') + '/' + scopeId + '/'; |
158 | | - } |
159 | | -
|
160 | | - if (obj.switchParams) { |
161 | | - scopeParams += obj.switchParams; |
162 | | - } |
163 | | -
|
164 | | - if ((typeof scopeSwitcherHandler) != 'undefined') { |
165 | | - var switcherParams = { |
166 | | - scopeId: scopeId, |
167 | | - scopeParams: scopeParams, |
168 | | - useConfirm: {$useConfirm} |
169 | | - }; |
170 | | - scopeSwitcherHandler(switcherParams); |
171 | | - } else { |
172 | | -script; |
173 | | - if ($block->getUseConfirm()) { |
174 | | - $scriptString .= ' |
175 | | - confirm({ |
176 | | - content: "' . $block->escapeJs(__( |
177 | | - 'Please confirm scope switching. All data that hasn\'t been saved will be lost.' |
178 | | - )) . '", |
179 | | - actions: { |
180 | | - confirm: function() { |
181 | | - reload(); |
182 | | - }, |
183 | | - cancel: function() { |
184 | | - obj.value = \'' . $block->escapeJs($block->getStoreId()) . '\'; |
185 | | - } |
| 127 | + <script type="text/x-magento-init"> |
| 128 | + { |
| 129 | + "*": { |
| 130 | + "Magento_Backend/js/store-switcher": { |
| 131 | + "useConfirm": <?= /* @noEscape */ (int)$block->getUseConfirm(); ?>, |
| 132 | + "isUsingIframe": <?= /* @noEscape */ (int)$block->isUsingIframe(); ?>, |
| 133 | + "switchUrl": "<?= $block->escapeUrl($block->getSwitchUrl()); ?>", |
| 134 | + "storeId": <?= /* @noEscape */ (int)$block->getStoreId(); ?> |
186 | 135 | } |
187 | | - }); |
188 | | -'; |
189 | | - } else { |
190 | | - $scriptString .= 'reload();'; |
191 | | - } |
192 | | - $scriptString .= ' |
193 | | - } |
194 | | -
|
195 | | - function reload() { |
196 | | - '; |
197 | | - if (!$block->isUsingIframe()) { |
198 | | - $scriptString .= ' |
199 | | - var url = \'' . $block->escapeJs($block->getSwitchUrl()) . '\' + scopeParams; |
200 | | - setLocation(url); |
201 | | -'; |
202 | | - } else { |
203 | | - $scriptString .= <<<'script' |
204 | | - jQuery('#preview_selected_store').val(scopeId); |
205 | | - jQuery('#preview_form').submit(); |
206 | | -
|
207 | | - jQuery('.store-switcher .dropdown-menu li a').each(function() { |
208 | | - var $this = jQuery(this); |
209 | | -
|
210 | | - if ($this.data('role') === 'store-view-id' && $this.data('value') == scopeId) { |
211 | | - jQuery('#store-change-button').html($this.text()); |
212 | | - } |
213 | | - }); |
214 | | -
|
215 | | - jQuery('#store-change-button').click(); |
216 | | -script; |
217 | | - } |
218 | | - $scriptString .= <<<script |
| 136 | + } |
219 | 137 | } |
220 | | - } |
221 | | -
|
222 | | - window.scopeSwitcherHandler = scopeSwitcherHandler; |
223 | | - window.switchScope = switchScope; |
224 | | -
|
225 | | -}); |
226 | | -script; |
227 | | - ?> |
228 | | - <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false); ?> |
| 138 | + </script> |
229 | 139 | <?php endif; ?> |
0 commit comments