Shopgo_AdvIfconfig - Version 1.0.3

Version Notes

The first release of Advanced Ifconfig extension.

Download this release

Release Info

Developer Moe Ghashim
Extension Shopgo_AdvIfconfig
Version 1.0.3
Comparing to
See all releases


Version 1.0.3

app/code/community/Shopgo/AdvIfconfig/Helper/Data.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ShopGo
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Shopgo
13
+ * @package Shopgo_AdvIfconfig
14
+ * @copyright Copyright (c) 2014 Shopgo. (http://www.shopgo.me)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+
19
+ /**
20
+ * Data helper
21
+ *
22
+ * @category Shopgo
23
+ * @package Shopgo_AdvIfconfig
24
+ * @author Ammar <ammar@shopgo.me>
25
+ */
26
+ class Shopgo_AdvIfconfig_Helper_Data extends Shopgo_Core_Helper_Abstract
27
+ {
28
+ /**
29
+ * Check system config node depends
30
+ *
31
+ * @param string $section
32
+ * @param string $group
33
+ * @param string $field
34
+ * @param bool $result
35
+ * @return bool
36
+ */
37
+ public function checkSystemConfigNodeDepends($section, $group, $field, $result = false)
38
+ {
39
+ $depends = $this->getSystemConfigNodeDepends($section, $group, $field);
40
+
41
+ foreach ((array)$depends as $fieldName => $fieldValue) {
42
+ $path = $section . '/' . $group . '/' . $fieldName;
43
+ $dependValid = $fieldValue == Mage::getStoreConfigFlag($path);
44
+ $result = $result && $this->checkSystemConfigNodeDepends(
45
+ $section, $group, $fieldName, $dependValid
46
+ );
47
+ }
48
+
49
+ return $result;
50
+ }
51
+
52
+ /**
53
+ * Get system config node depends
54
+ *
55
+ * @param string $sectionName
56
+ * @param string $groupName
57
+ * @param string $fieldName
58
+ * @return Varien_Simplexml_Element|null
59
+ */
60
+ public function getSystemConfigNodeDepends($sectionName, $groupName = null, $fieldName = null)
61
+ {
62
+ $config = Mage::getSingleton('adminhtml/config');
63
+ $sectionName = trim($sectionName, '/');
64
+ $path = '//sections/' . $sectionName;
65
+ $groupNode = $fieldNode = null;
66
+ $sectionNode = $config->getSections()->xpath($path);
67
+ if (!empty($groupName)) {
68
+ $groupPath = $path .= '/groups/' . trim($groupName, '/');
69
+ $groupNode = $config->getSections()->xpath($path);
70
+ }
71
+ if (!empty($fieldName)) {
72
+ if (!empty($groupName)) {
73
+ $path .= '/fields/' . trim($fieldName, '/');
74
+ $fieldNode = $config->getSections()->xpath($path);
75
+ }
76
+ else {
77
+ Mage::throwException(
78
+ $this->__('The group node name must be specified with field node name.')
79
+ );
80
+ }
81
+ }
82
+ $path .= '/depends';
83
+ $dependsNode = $config->getSections()->xpath($path);
84
+ foreach ($dependsNode as $node) {
85
+ return $node;
86
+ }
87
+ return null;
88
+ }
89
+
90
+ /**
91
+ * Get store config with depends flag
92
+ *
93
+ * @param string $configPath
94
+ * @param array $requiredDepends
95
+ * @param string $type
96
+ * @return bool
97
+ */
98
+ public function getStoreConfigWithDependsFlag($configPath, $requiredDepends = array(), $type = 'tree')
99
+ {
100
+ $ifConfig = Mage::getStoreConfigFlag($configPath);
101
+
102
+ if ($ifConfig) {
103
+ if ($type == 1 || $type == 'tree') {
104
+ $configPath = explode('/', $configPath);
105
+ $ifConfig = $ifConfig
106
+ && $this->checkSystemConfigNodeDepends(
107
+ $configPath[0], // Section
108
+ $configPath[1], // Group
109
+ $configPath[2], // Field
110
+ $ifConfig
111
+ );
112
+ }
113
+
114
+ if ($type == 1 || $type == 'required') {
115
+ if (is_string($requiredDepends)) {
116
+ $requiredDepends = array_map('trim', explode(',', $requiredDepends));
117
+ }
118
+
119
+ foreach ($requiredDepends as $depend) {
120
+ $ifConfig = $ifConfig && Mage::getStoreConfigFlag($depend);
121
+ }
122
+ }
123
+ }
124
+
125
+ return $ifConfig;
126
+ }
127
+ }
app/code/community/Shopgo/AdvIfconfig/Model/Magento/Core/Layout.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ShopGo
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Shopgo
13
+ * @package Shopgo_AdvIfconfig
14
+ * @copyright Copyright (c) 2014 Shopgo. (http://www.shopgo.me)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+
19
+ /**
20
+ * Layout model
21
+ *
22
+ * @category Shopgo
23
+ * @package Shopgo_AdvIfconfig
24
+ * @author Ammar <ammar@shopgo.me>
25
+ */
26
+ class Shopgo_AdvIfconfig_Model_Magento_Core_Layout extends Mage_Core_Model_Layout
27
+ {
28
+ /**
29
+ * Modified core generate action method
30
+ *
31
+ * @param Varien_Simplexml_Element $node
32
+ * @param Varien_Simplexml_Element $parent
33
+ * @return Mage_Core_Model_Layout
34
+ */
35
+ protected function _generateAction($node, $parent)
36
+ {
37
+ if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) {
38
+ $ifConfig = Mage::getStoreConfigFlag($configPath);
39
+ $nodeArray = (array)$node;
40
+
41
+ $advIfconfig = null;
42
+ $dependsCheck = false;
43
+ $requiredDepends = false;
44
+
45
+ if (isset($nodeArray['adv_ifconfig'])) {
46
+ $advIfconfig = (array)$nodeArray['adv_ifconfig'];
47
+
48
+ if (isset($advIfconfig['depends_check'])) {
49
+ $dependsCheck = $advIfconfig['depends_check'];
50
+ }
51
+
52
+ if (isset($advIfconfig['required_depends'])) {
53
+ $requiredDepends = $advIfconfig['required_depends'];
54
+ }
55
+ }
56
+
57
+ if ($ifConfig && $dependsCheck) {
58
+ if ($dependsCheck == 1 || $dependsCheck == 'tree') {
59
+ $configPath = explode('/', $configPath);
60
+ $ifConfig = $ifConfig
61
+ && Mage::helper('advifconfig')->checkSystemConfigNodeDepends(
62
+ $configPath[0], // Section
63
+ $configPath[1], // Group
64
+ $configPath[2], // Field
65
+ $ifConfig
66
+ );
67
+ }
68
+
69
+ if (($dependsCheck == 1 || $dependsCheck == 'required')
70
+ && $requiredDepends) {
71
+ $additionalDepends = array_map('trim',
72
+ explode(',', $requiredDepends)
73
+ );
74
+
75
+ foreach ($additionalDepends as $depend) {
76
+ $ifConfig = $ifConfig && Mage::getStoreConfigFlag($depend);
77
+ }
78
+ }
79
+ }
80
+
81
+ if (!$ifConfig) {
82
+ return $this;
83
+ }
84
+
85
+ if (isset($advIfconfig['custom_rules'])) {
86
+ $data = array_merge(
87
+ array('ifconfig' => false), // Default value for custom rules ifconfig
88
+ (array)$advIfconfig['custom_rules']
89
+ );
90
+ $data = new Varien_Object($data);
91
+
92
+ Mage::dispatchEvent('adv_ifconfig_custom_rules', $data);
93
+
94
+ if (!$data->getIfconfig()) {
95
+ return $this;
96
+ }
97
+ }
98
+ }
99
+
100
+ $method = (string)$node['method'];
101
+ if (!empty($node['block'])) {
102
+ $parentName = (string)$node['block'];
103
+ } else {
104
+ $parentName = $parent->getBlockName();
105
+ }
106
+
107
+ $_profilerKey = 'BLOCK ACTION: '.$parentName.' -> '.$method;
108
+ Varien_Profiler::start($_profilerKey);
109
+
110
+ if (!empty($parentName)) {
111
+ $block = $this->getBlock($parentName);
112
+ }
113
+ if (!empty($block)) {
114
+
115
+ $args = (array)$node->children();
116
+ unset($args['@attributes']);
117
+
118
+ if (isset($args['adv_ifconfig'])) {
119
+ unset($args['adv_ifconfig']);
120
+ }
121
+
122
+ foreach ($args as $key => $arg) {
123
+ if (($arg instanceof Mage_Core_Model_Layout_Element)) {
124
+ if (isset($arg['helper'])) {
125
+ $helperName = explode('/', (string)$arg['helper']);
126
+ $helperMethod = array_pop($helperName);
127
+ $helperName = implode('/', $helperName);
128
+ $arg = $arg->asArray();
129
+ unset($arg['@']);
130
+ $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg);
131
+ } else {
132
+ /**
133
+ * if there is no helper we hope that this is assoc array
134
+ */
135
+ $arr = array();
136
+ foreach($arg as $subkey => $value) {
137
+ $arr[(string)$subkey] = $value->asArray();
138
+ }
139
+ if (!empty($arr)) {
140
+ $args[$key] = $arr;
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ if (isset($node['json'])) {
147
+ $json = explode(' ', (string)$node['json']);
148
+ foreach ($json as $arg) {
149
+ $args[$arg] = Mage::helper('core')->jsonDecode($args[$arg]);
150
+ }
151
+ }
152
+
153
+ $this->_translateLayoutNode($node, $args);
154
+ call_user_func_array(array($block, $method), $args);
155
+ }
156
+
157
+ Varien_Profiler::stop($_profilerKey);
158
+
159
+ return $this;
160
+ }
161
+ }
app/code/community/Shopgo/AdvIfconfig/etc/config.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * ShopGo
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ *
13
+ * @category Shopgo
14
+ * @package Shopgo_AdvIfconfig
15
+ * @author Ammar <ammar@shopgo.me>
16
+ * @copyright Copyright (c) 2014 Shopgo. (http://www.shopgo.me)
17
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <modules>
22
+ <Shopgo_AdvIfconfig>
23
+ <version>1.0.3</version>
24
+ </Shopgo_AdvIfconfig>
25
+ </modules>
26
+ <global>
27
+ <helpers>
28
+ <advifconfig>
29
+ <class>Shopgo_AdvIfconfig_Helper</class>
30
+ </advifconfig>
31
+ </helpers>
32
+ <models>
33
+ <core>
34
+ <rewrite>
35
+ <layout>Shopgo_AdvIfconfig_Model_Magento_Core_Layout</layout>
36
+ </rewrite>
37
+ </core>
38
+ </models>
39
+ </global>
40
+ </config>
app/etc/modules/Shopgo_AdvIfconfig.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * ShopGo
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ *
13
+ * @category Shopgo
14
+ * @package Shopgo_AdvIfconfig
15
+ * @author Ammar <ammar@shopgo.me>
16
+ * @copyright Copyright (c) 2014 Shopgo. (http://www.shopgo.me)
17
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <modules>
22
+ <Shopgo_AdvIfconfig>
23
+ <active>true</active>
24
+ <codePool>community</codePool>
25
+ <depends>
26
+ <Shopgo_Core/>
27
+ </depends>
28
+ </Shopgo_AdvIfconfig>
29
+ </modules>
30
+ </config>
package.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Shopgo_AdvIfconfig</name>
4
+ <version>1.0.3</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Advanced Ifconfig is a utility module that extends Magento's ifconfig and adds more features to it.</summary>
10
+ <description>&lt;p&gt;Advanced Ifconfig is a utility module that extends Magento's ifconfig and adds more features to it.&#xD;
11
+ The module is used by some of ShopGo's modules.&#xD;
12
+ (Documentation is currently unavailable)&lt;/p&gt;&#xD;
13
+ You could also get the latest version of the module from:&#xD;
14
+ &lt;a href="https://github.com/shopgo-me/advanced-ifconfig"&gt;https://github.com/shopgo-me/advanced-ifconfig&lt;/a&gt;</description>
15
+ <notes>The first release of Advanced Ifconfig extension.</notes>
16
+ <authors><author><name>ShopGo</name><user>ShopGo</user><email>support@shopgo.me</email></author></authors>
17
+ <date>2015-07-08</date>
18
+ <time>19:27:24</time>
19
+ <contents><target name="magecommunity"><dir name="Shopgo"><dir name="AdvIfconfig"><dir name="Helper"><file name="Data.php" hash="9f81b663a44dc13da7fd44efb4e48109"/></dir><dir name="Model"><dir name="Magento"><dir name="Core"><file name="Layout.php" hash="f2cbd44603f3dbdda502596339802a98"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="220c82f948121bb220dc02fa186165a3"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shopgo_AdvIfconfig.xml" hash="712614f04a4563cbac40b522e8a7a9d8"/></dir></target></contents>
20
+ <compatible/>
21
+ <dependencies><required><php><min>5.3.0</min><max>7.0.0</max></php><package><name>Shopgo_Core</name><channel>community</channel><min>1.0.6</min><max/></package></required></dependencies>
22
+ </package>