|
10 | 10 | use Magento\Store\Api\StoreRepositoryInterface; |
11 | 11 | use Magento\Store\Api\Data\WebsiteInterface; |
12 | 12 | use Magento\Store\Api\Data\StoreInterface; |
| 13 | +use Magento\Store\Model\ScopeInterface; |
13 | 14 |
|
14 | 15 | class ConfigFieldPlugin |
15 | 16 | { |
@@ -59,17 +60,24 @@ public function afterGetTooltip(Subject $subject, $result) |
59 | 60 | { |
60 | 61 | $lines = [$result]; |
61 | 62 | foreach($this->websiteRepository->getList() as $website) { |
62 | | - if (!$this->isWebsiteSelected($website)) { |
63 | | - if ($scopeLine = $this->getScopeHint($this->getPath($subject), self::SCOPE_TYPE_WEBSITES, $website)) { |
64 | | - $lines[] = $scopeLine; |
65 | | - } |
| 63 | + if ($this->getWebsiteParam() || $this->getStoreParam()) { |
| 64 | + continue; |
| 65 | + } |
| 66 | + // Only show website specific values in default scope |
| 67 | + if ($scopeLine = $this->getScopeHint($subject, self::SCOPE_TYPE_WEBSITES, $website)) { |
| 68 | + $lines[] = $scopeLine; |
66 | 69 | } |
67 | 70 | } |
68 | 71 | foreach($this->storeRepository->getList() as $store) { |
69 | | - if (!$this->isStoreSelected($store)) { |
70 | | - if ($scopeLine = $this->getScopeHint($this->getPath($subject), self::SCOPE_TYPE_STORES, $store)) { |
71 | | - $lines[] = $scopeLine; |
72 | | - } |
| 72 | + if ($this->getStoreParam($store)) { |
| 73 | + continue; |
| 74 | + } |
| 75 | + if (($websiteId = $this->getWebsiteParam()) && ($store->getWebsiteId() != $websiteId)) { |
| 76 | + continue; |
| 77 | + } |
| 78 | + // Only show store specific values in default scope and in parent website scope |
| 79 | + if ($scopeLine = $this->getScopeHint($subject, self::SCOPE_TYPE_STORES, $store)) { |
| 80 | + $lines[] = $scopeLine; |
73 | 81 | } |
74 | 82 | } |
75 | 83 | return implode('<br />', array_filter($lines)); |
@@ -111,44 +119,78 @@ private function getPath(Subject $subject) |
111 | 119 | } |
112 | 120 |
|
113 | 121 | /** |
114 | | - * @param WebsiteInterface $website |
115 | | - * @return bool |
116 | | - */ |
117 | | - private function isWebsiteSelected($website) |
118 | | - { |
119 | | - return $website->getId() == $this->request->getParam('website'); |
120 | | - } |
121 | | - |
122 | | - /** |
123 | | - * @param StoreInterface $store |
124 | | - * @return bool |
125 | | - */ |
126 | | - private function isStoreSelected($store) |
127 | | - { |
128 | | - return $store->getId() == $this->request->getParam('store'); |
129 | | - } |
130 | | - |
131 | | - /** |
132 | | - * @param string $path |
| 122 | + * @param Subject $field |
133 | 123 | * @param string $scopeType |
134 | 124 | * @param WebsiteInterface|StoreInterface $scope |
135 | 125 | * @return string |
136 | 126 | */ |
137 | | - private function getScopeHint($path, $scopeType, $scope) |
| 127 | + private function getScopeHint(Subject $field, $scopeType, $scope) |
138 | 128 | { |
| 129 | + $path = $this->getPath($field); |
139 | 130 | $scopeLine = ''; |
140 | | - $currentValue = $this->scopeConfig->getValue($path); |
141 | | - $scopeValue = $this->scopeConfig->getValue($path, $scopeType, $scope->getId()); |
| 131 | + if ($websiteId = $this->getWebsiteParam()) { |
| 132 | + $currentValue = (string) $this->scopeConfig->getValue( |
| 133 | + $path, |
| 134 | + ScopeInterface::SCOPE_WEBSITE, |
| 135 | + $websiteId |
| 136 | + ); |
| 137 | + } else { |
| 138 | + $currentValue = (string) $this->scopeConfig->getValue($path); |
| 139 | + } |
| 140 | + $scopeValue = (string) $this->scopeConfig->getValue($path, $scopeType, $scope->getId()); |
| 141 | + |
142 | 142 | if ($scopeValue != $currentValue) { |
143 | 143 | $scopeValue = $this->escaper->escapeHtml($scopeValue); |
144 | 144 |
|
145 | 145 | switch($scopeType) { |
146 | 146 | case self::SCOPE_TYPE_STORES: |
147 | | - return __('Store <code>%1</code>: "%2"', $scope->getCode(), $scopeValue); |
| 147 | + return __( |
| 148 | + 'Store <code>%1</code>: "%2"', |
| 149 | + $scope->getCode(), |
| 150 | + $this->getValueLabel($field, $scopeValue) |
| 151 | + ); |
148 | 152 | case self::SCOPE_TYPE_WEBSITES: |
149 | | - return __('Website <code>%1</code>: "%2"', $scope->getCode(), $scopeValue); |
| 153 | + return __( |
| 154 | + 'Website <code>%1</code>: "%2"', |
| 155 | + $scope->getCode(), |
| 156 | + $this->getValueLabel($field, $scopeValue) |
| 157 | + ); |
150 | 158 | } |
151 | 159 | } |
152 | 160 | return $scopeLine; |
153 | 161 | } |
| 162 | + |
| 163 | + private function getValueLabel(Subject $field, string $scopeValue): string |
| 164 | + { |
| 165 | + $scopeValue = trim($scopeValue); |
| 166 | + if ($field->hasOptions()) { |
| 167 | + if ($field->getType() === 'multiselect' && strpos($scopeValue, ',') !== false) { |
| 168 | + return implode( |
| 169 | + ', ', |
| 170 | + array_map( |
| 171 | + function ($key) use ($field) { |
| 172 | + return $this->getValueLabel($field, $key); |
| 173 | + }, |
| 174 | + explode(',', $scopeValue) |
| 175 | + ) |
| 176 | + ); |
| 177 | + } |
| 178 | + foreach ($field->getOptions() as $option) { |
| 179 | + if ($option['value'] == $scopeValue) { |
| 180 | + return $option['label']; |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + return $scopeValue; |
| 185 | + } |
| 186 | + |
| 187 | + private function getWebsiteParam(): ?string |
| 188 | + { |
| 189 | + return $this->request->getParam('website'); |
| 190 | + } |
| 191 | + |
| 192 | + private function getStoreParam(): ?string |
| 193 | + { |
| 194 | + return $this->request->getParam('store'); |
| 195 | + } |
154 | 196 | } |
0 commit comments