Ooworx_ScopesExplorer - Version 0.1.0

Version Notes

Initial package

Download this release

Release Info

Developer Ooworx
Extension Ooworx_ScopesExplorer
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Ooworx/ScopesExplorer/Block/Catalog/Form/Renderer/Fieldset/Element.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Copyright (C) 2015 Ooworx
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ class Ooworx_ScopesExplorer_Block_Catalog_Form_Renderer_Fieldset_Element extends Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element
19
+ {
20
+ /**
21
+ * Retrieve label of attribute scope
22
+ *
23
+ * GLOBAL | WEBSITE | STORE
24
+ *
25
+ * @return string
26
+ */
27
+ public function getScopeLabel()
28
+ {
29
+ $html = '';
30
+ $attribute = $this->getElement()->getEntityAttribute();
31
+ if (!$attribute || Mage::app()->isSingleStoreMode() || $attribute->getFrontendInput()=='gallery') {
32
+ return $html;
33
+ }
34
+
35
+ /*
36
+ * Check if the current attribute is a 'price' attribute. If yes, check
37
+ * the config setting 'Catalog Price Scope' and modify the scope label.
38
+ */
39
+ $isGlobalPriceScope = false;
40
+ if ($attribute->getFrontendInput() == 'price') {
41
+ $priceScope = Mage::getStoreConfig('catalog/price/scope');
42
+ if ($priceScope == 0) {
43
+ $isGlobalPriceScope = true;
44
+ }
45
+ }
46
+
47
+ if ($attribute->isScopeGlobal() || $isGlobalPriceScope) {
48
+ $html .= Mage::helper('adminhtml')->__('[GLOBAL]');
49
+ } elseif ($attribute->isScopeWebsite()) {
50
+ $html .= Mage::helper('adminhtml')->__('[WEBSITE]');
51
+ } elseif ($attribute->isScopeStore()) {
52
+ $html .= Mage::helper('adminhtml')->__('[STORE VIEW]');
53
+ }
54
+
55
+ // Rewrite scopehelper
56
+ $html .= Mage::helper("scopesexplorer")->getProductCategoryScopesHtml($this->getElement(), $this->getDataObject());
57
+
58
+ return $html;
59
+ }
60
+ }
app/code/community/Ooworx/ScopesExplorer/Block/System/Config/Form.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Copyright (C) 2015 Ooworx
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ class Ooworx_ScopesExplorer_Block_System_Config_Form extends Mage_Adminhtml_Block_System_Config_Form
19
+ {
20
+ /**
21
+ * Retrieve label for scope
22
+ *
23
+ * @param Mage_Core_Model_Config_Element $element
24
+ * @return string
25
+ */
26
+ public function getScopeLabel($element)
27
+ {
28
+ // Dirty hack to fetch parents params (section, group, fieldPrefix)
29
+ $parent_args = debug_backtrace()[1]["args"];
30
+ // Avoid to override initFields and break compatibility
31
+
32
+ /**
33
+ * Look for custom defined field path
34
+ */
35
+ $path = (string)$element->config_path;
36
+ if (empty($path)) {
37
+ $path = $parent_args[2]->getName() . '/' . $parent_args[1]->getName() . '/' . $parent_args[3] . $element->getName();
38
+ }
39
+
40
+ // Original code
41
+ $html = '';
42
+ if ($element->show_in_store == 1) {
43
+ $html .= $this->_scopeLabels[self::SCOPE_STORES];
44
+ } elseif ($element->show_in_website == 1) {
45
+ $html .= $this->_scopeLabels[self::SCOPE_WEBSITES];
46
+ } else {
47
+ $html .= $this->_scopeLabels[self::SCOPE_DEFAULT];
48
+ }
49
+ $html .= Mage::helper("scopesexplorer")->getConfigScopesHtml($path);
50
+ return $html;
51
+ }
52
+
53
+ }
app/code/community/Ooworx/ScopesExplorer/Helper/Data.php ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Copyright (C) 2015 Ooworx
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ class Ooworx_ScopesExplorer_Helper_Data extends Mage_Core_Helper_Abstract
19
+ {
20
+ /*
21
+ * Return additionnal html for config scopes
22
+ *
23
+ */
24
+ public function getConfigScopesHtml($path) {
25
+ // Init html
26
+ $html = "";
27
+
28
+ // Check empty path
29
+ if (empty($path)) {
30
+ return $html;
31
+ }
32
+
33
+ // Fetch config_data informations for stores
34
+ $config_data_stores = Mage::getModel('core/config_data')
35
+ ->getCollection()
36
+ ->addFieldToFilter("path", $path)
37
+ ->addFieldToFilter("scope", "stores");
38
+
39
+ // Fetch config data informations for website
40
+ $config_data_websites = Mage::getModel('core/config_data')
41
+ ->getCollection()
42
+ ->addFieldToFilter("path", $path)
43
+ ->addFieldToFilter("scope", "websites");
44
+
45
+ // Count rows availables
46
+ $stores_count = $config_data_stores->count();
47
+ $websites_count = $config_data_websites->count();
48
+
49
+ // Generate html
50
+ if ($stores_count > 0 || $websites_count > 0) {
51
+ // Generate header
52
+ $html .= "<span> (<b>Overridden scopes : ";
53
+ // Websites
54
+ if ($websites_count > 0) {
55
+ $desc = 'Overridden in ' . $websites_count . ' websites : \n';
56
+ foreach ($config_data_websites as $config) {
57
+ $website = Mage::getModel("core/website")->load($config->getScopeId());
58
+ $desc .= '- [' . $website->getName() . ']\n';
59
+ }
60
+ $html .= '<a href="#" onclick="alert(\'' . $desc . '\');return false;">Websites: ' . $websites_count . '</a>';
61
+ }
62
+ // Stores
63
+ if ($stores_count > 0) {
64
+ if ($websites_count > 0) {
65
+ $html .= " / ";
66
+ }
67
+ $desc = 'Overridden in ' . $stores_count . ' stores : \n';
68
+ foreach ($config_data_stores as $config) {
69
+ $store = Mage::getModel("core/store")->load($config->getScopeId());
70
+ $desc .= '- [' . $store->getName() . ']\n';
71
+ }
72
+ $html .= '<a href="#" onclick="alert(\'' . $desc . '\');return false;">Stores: ' . $stores_count . '</a>';
73
+ }
74
+ // End
75
+ $html .= "</b>)</span>";
76
+ }
77
+ return $html;
78
+ }
79
+
80
+ public function getProductCategoryScopesHtml($element, $data_object) {
81
+ $html = "";
82
+ // Generate html for category and product form
83
+ if (is_null($data_object) || $data_object->getId() == null
84
+ || is_null($element) || $element->getId() == null) {
85
+ return $html;
86
+ }
87
+ // Read product attribute code selected
88
+ $attribute_code = $element->getEntityAttribute()->getData('attribute_code');
89
+ // Get current entity_id from object
90
+ $entity_id = $data_object->getData('entity_id');
91
+
92
+ // Load query for category or product
93
+ $query = $this->getQueryByDataObject($data_object, $attribute_code, $entity_id);
94
+
95
+ // Init raw database
96
+ $resource = Mage::getSingleton('core/resource');
97
+ $readConnection = $resource->getConnection('core_read');
98
+
99
+ // Run query
100
+ $attributes_list = $readConnection->fetchAll($query);
101
+
102
+ // Stores
103
+ $stores_count = count($attributes_list);
104
+ if ($stores_count > 0) {
105
+ // Generate header
106
+ $html .= '<span> (<b>Overridden scopes : ';
107
+ $desc = 'Overridden in ' . $stores_count . ' stores:\n';
108
+ foreach ($attributes_list as $attribute) {
109
+ $store = Mage::getModel("core/store")->load($attribute["store_id"]);
110
+ $desc .= '- [' . $store->getName() . ']\n';
111
+ }
112
+ $html .= '<a href="#" onclick="alert(\'' . $desc . '\');return false;">Stores: ' . $stores_count . '</a>';
113
+ // End
114
+ $html .= "</b>)</span>";
115
+ }
116
+ return $html;
117
+ }
118
+
119
+ // Thanks https://gist.github.com/ticean/735798
120
+ public function getQueryByDataObject($data_object, $attribute_code, $entity_id) {
121
+ if ($data_object instanceof Mage_Catalog_Model_Product) {
122
+ // PRODUCTS
123
+ return "SELECT ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'varchar' AS 'type'
124
+ FROM catalog_product_entity e
125
+ JOIN catalog_product_entity_varchar eav
126
+ ON e.entity_id = eav.entity_id
127
+ JOIN eav_attribute ea
128
+ ON eav.attribute_id = ea.attribute_id
129
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0
130
+
131
+ UNION
132
+
133
+ SELECT ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'int' AS 'type'
134
+ FROM catalog_product_entity e
135
+ JOIN catalog_product_entity_int eav
136
+ ON e.entity_id = eav.entity_id
137
+ JOIN eav_attribute ea
138
+ ON eav.attribute_id = ea.attribute_id
139
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0
140
+
141
+ UNION
142
+
143
+ SELECT ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'decimal' AS 'type'
144
+ FROM catalog_product_entity e
145
+ JOIN catalog_product_entity_decimal eav
146
+ ON e.entity_id = eav.entity_id
147
+ JOIN eav_attribute ea
148
+ ON eav.attribute_id = ea.attribute_id
149
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0
150
+
151
+ UNION
152
+
153
+ SELECT ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'datetime' AS 'type'
154
+ FROM catalog_product_entity e
155
+ JOIN catalog_product_entity_datetime eav
156
+ ON e.entity_id = eav.entity_id
157
+ JOIN eav_attribute ea
158
+ ON eav.attribute_id = ea.attribute_id
159
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0
160
+
161
+ UNION
162
+
163
+ SELECT ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'text' AS 'type'
164
+ FROM catalog_product_entity e
165
+ JOIN catalog_product_entity_text eav
166
+ ON e.entity_id = eav.entity_id
167
+ JOIN eav_attribute ea
168
+ ON eav.attribute_id = ea.attribute_id
169
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0";
170
+
171
+ } else {
172
+ // CATEGORY
173
+ return "SELECT ea.attribute_id, ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'varchar' AS 'type'
174
+ FROM catalog_category_entity e
175
+ JOIN catalog_category_entity_varchar eav
176
+ ON e.entity_id = eav.entity_id
177
+ JOIN eav_attribute ea
178
+ ON eav.attribute_id = ea.attribute_id
179
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0
180
+
181
+ UNION
182
+
183
+ SELECT ea.attribute_id, ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'int' AS 'type'
184
+ FROM catalog_category_entity e
185
+ JOIN catalog_category_entity_int eav
186
+ ON e.entity_id = eav.entity_id
187
+ JOIN eav_attribute ea
188
+ ON eav.attribute_id = ea.attribute_id
189
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0
190
+
191
+ UNION
192
+
193
+ SELECT ea.attribute_id, ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'decimal' AS 'type'
194
+ FROM catalog_category_entity e
195
+ JOIN catalog_category_entity_decimal eav
196
+ ON e.entity_id = eav.entity_id
197
+ JOIN eav_attribute ea
198
+ ON eav.attribute_id = ea.attribute_id
199
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0
200
+
201
+ UNION
202
+
203
+ SELECT ea.attribute_id, ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'datetime' AS 'type'
204
+ FROM catalog_category_entity e
205
+ JOIN catalog_category_entity_datetime eav
206
+ ON e.entity_id = eav.entity_id
207
+ JOIN eav_attribute ea
208
+ ON eav.attribute_id = ea.attribute_id
209
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0
210
+
211
+ UNION
212
+
213
+ SELECT ea.attribute_id, ea.attribute_code, eav.value AS 'value', eav.store_id AS 'store_id', 'text' AS 'type'
214
+ FROM catalog_category_entity e
215
+ JOIN catalog_category_entity_text eav
216
+ ON e.entity_id = eav.entity_id
217
+ JOIN eav_attribute ea
218
+ ON eav.attribute_id = ea.attribute_id
219
+ WHERE e.entity_id = " . $entity_id . " AND ea.attribute_code = '" . $attribute_code . "' AND store_id != 0";
220
+ }
221
+ }
222
+ }
app/code/community/Ooworx/ScopesExplorer/etc/config.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Ooworx_ScopesExplorer>
5
+ <version>0.1.0</version>
6
+ </Ooworx_ScopesExplorer>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <adminhtml>
11
+ <rewrite>
12
+ <system_config_form>Ooworx_ScopesExplorer_Block_System_Config_Form</system_config_form>
13
+ <catalog_form_renderer_fieldset_element>Ooworx_ScopesExplorer_Block_Catalog_Form_Renderer_Fieldset_Element</catalog_form_renderer_fieldset_element>
14
+ </rewrite>
15
+ </adminhtml>
16
+ </blocks>
17
+ <helpers>
18
+ <scopesexplorer>
19
+ <class>Ooworx_ScopesExplorer_Helper</class>
20
+ </scopesexplorer>
21
+ </helpers>
22
+ </global>
23
+ </config>
app/etc/modules/Ooworx_ScopesExplorer.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Ooworx_ScopesExplorer>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.1.0</version>
8
+ </Ooworx_ScopesExplorer>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Ooworx_ScopesExplorer</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://www.gnu.org/licenses/gpl-3.0.en.html">GPLv3</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Show overridden scopes into configuration and product admin.</summary>
10
+ <description>Show overridden scopes into configuration and product admin. You can list in one click which website or stores who are not set to default scopes for one option / field.</description>
11
+ <notes>Initial package</notes>
12
+ <authors><author><name>Ooworx</name><user>ooworx</user><email>support@ooworx.com</email></author></authors>
13
+ <date>2015-09-21</date>
14
+ <time>09:46:49</time>
15
+ <contents><target name="magecommunity"><dir name="Ooworx"><dir name="ScopesExplorer"><dir name="Block"><dir name="Catalog"><dir name="Form"><dir name="Renderer"><dir name="Fieldset"><file name="Element.php" hash="2fc58369af7ae4fbbf8944c897be398e"/></dir></dir></dir></dir><dir name="System"><dir name="Config"><file name="Form.php" hash="3ad93ce446d84beb9493c78d0c49489b"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="f5154b62456c6dba46e60fcf8358359f"/></dir><dir name="etc"><file name="config.xml" hash="843b977ea4887c2dd0d51d37c464a390"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ooworx_ScopesExplorer.xml" hash="b394675874f61b1a5f1823e7b81dcf88"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Magento_Core_Modules</name><channel>community</channel><min>1.6</min><max>1.9</max></package></required></dependencies>
18
+ </package>