Lister_Coreconfig - Version 0.0.1

Version Notes

This is the initial stable version.

Download this release

Release Info

Developer Lister Technologies (P) Ltd
Extension Lister_Coreconfig
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

app/code/community/Lister/Coreconfig/Helper/Data.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Lister_Coreconfig_Helper_Data
4
+ *
5
+ * @category Lister ( http://www.listertechnologies.com )
6
+ * @package Lister_Coreconfig
7
+ * @contacts info@listertechnologies.com
8
+ */
9
+ class Lister_Coreconfig_Helper_Data extends Mage_Core_Helper_Abstract
10
+ {
11
+
12
+ }
app/code/community/Lister/Coreconfig/Model/Import.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Lister_Coreconfig_Model_Import
4
+ *
5
+ * @category Lister ( http://www.listertechnologies.com )
6
+ * @package Lister_Coreconfig
7
+ * @contacts info@listertechnologies.com
8
+ */
9
+ class Lister_Coreconfig_Model_Import extends Mage_Core_Model_Config_Data
10
+ {
11
+
12
+ public function _afterSave()
13
+ {
14
+ $this->_importData();
15
+ }
16
+
17
+ /**
18
+ * Declaration
19
+ * Imports csv to import folder.
20
+ * Retrive the content and save config data.
21
+ * @param
22
+ * @return void
23
+ */
24
+ protected function _importData()
25
+ {
26
+ $fileContent = $this->_getCsv();
27
+ $stores = $this->_getStores();
28
+ $websites = $this->_getWebsites();
29
+
30
+ if ($fileContent) {
31
+ $row = 0;
32
+ while (($csvContent = fgetcsv($fileContent, 1000, ",",'"',"~")) !== FALSE) {
33
+ if ($row > 0) {
34
+ $scope = trim($csvContent[0]);
35
+ $scopeVal = trim($csvContent[1]); // scope_id i.e website/store code
36
+ $path = trim($csvContent[2]);
37
+ $value = str_replace('~',',',trim($csvContent[3]));
38
+
39
+ if ($scope !== $csvContent[$row - 1][0] && $scopeVal !== $csvContent[$row - 1][1]) {
40
+ $scopeDetails = $this->_getScopeDetails($scope, $scopeVal, $row, $stores, $websites);
41
+ }
42
+ $updatedScope = $scopeDetails['scope'];
43
+ $updatedScopeId = $scopeDetails['scope_id'];
44
+
45
+ //To save data in the core_config_data table.
46
+ $configModel = Mage::getModel('core/config');
47
+ $configModel->saveConfig($path, $value, $updatedScope, $updatedScopeId);
48
+ }
49
+
50
+ $row++;
51
+ }
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Declaration
57
+ * Store Code / Id in an Array.
58
+ * @param
59
+ * @return array $storeData
60
+ */
61
+ protected function _getStores()
62
+ {
63
+ $stores = array_keys(Mage::app()->getStores());
64
+ foreach ($stores as $id) {
65
+ $store = Mage::app()->getStore($id);
66
+ $storeData[$store->getCode()] = $store->getId();
67
+ }
68
+ return $storeData;
69
+ }
70
+
71
+ /**
72
+ * Declaration
73
+ * Website Code / Id in an Array.
74
+ * @param
75
+ * @return array $website
76
+ */
77
+ protected function _getWebsites()
78
+ {
79
+ $websites = Mage::app()->getWebsites();
80
+ foreach ($websites as $website) {
81
+ $website[$website->getCode()] = $website->getId();
82
+ }
83
+ return $website;
84
+ }
85
+
86
+ /**
87
+ * Declaration
88
+ * Retrive the scope details
89
+ * @param string $scope default|stores|websites
90
+ * @param string $scopeVal
91
+ * @param integer $row
92
+ * @param array $stores
93
+ * @param array $websites
94
+ * @return array $scopeDetail
95
+ */
96
+ protected function _getScopeDetails($scope, $scopeVal, $row, $stores, $websites)
97
+ {
98
+ $scopeDetail = array();
99
+ if (!is_null($scope) && $scope === 'default') {
100
+ $scopeDetail['scope'] = 'default';
101
+ $scopeDetail['scope_id'] = 0;
102
+ }
103
+ else if (!is_null($scope) && !is_null($scopeVal) && $scope === 'stores') {
104
+ $scopeDetail['scope'] = $scope;
105
+ $scopeDetail['scope_id'] = $this->_getStoreByCode($scopeVal, $stores);
106
+ }
107
+ else if (!is_null($scope) && !is_null($scopeVal) && $scope === 'websites') {
108
+ $scopeDetail['scope'] = $scope;
109
+ $scopeDetail['scope_id'] = $this->_getWebsiteByCode($scopeVal, $websites);
110
+ }
111
+ else {
112
+ Mage::throwException('Please check the scope details in row# ' . $row);
113
+ }
114
+ return $scopeDetail;
115
+ }
116
+
117
+ /**
118
+ * Function used to fetch the store id
119
+ * @param type $storeCode
120
+ * @param type $storeData
121
+ * @return boolean / array
122
+ */
123
+ protected function _getStoreByCode($storeCode, $storeData)
124
+ {
125
+ if (array_key_exists($storeCode, $storeData)) {
126
+ return $storeData[$storeCode];
127
+ }
128
+ return false;
129
+ }
130
+
131
+ /**
132
+ * Declaration
133
+ * Function used to fetch the website
134
+ * @param type $websiteCode
135
+ * @param type $website
136
+ * @return boolean / array
137
+ */
138
+ protected function _getWebsiteByCode($websiteCode, $website)
139
+ {
140
+ if (array_key_exists($websiteCode, $website)) {
141
+ return $website[$websiteCode];
142
+ }
143
+ return false;
144
+ }
145
+
146
+ /**
147
+ * Declaration
148
+ * File uploader
149
+ * @return resource $fileOpen
150
+ */
151
+ protected function _getCsv()
152
+ {
153
+ //File uploader
154
+ $uploader = new Varien_File_Uploader(
155
+ array(
156
+ 'name' => $_FILES['groups']['name']['coreconfig']['fields']['coreconfig']['value'],
157
+ 'type' => $_FILES['groups']['type']['coreconfig']['fields']['coreconfig']['value'],
158
+ 'tmp_name' => $_FILES['groups']['tmp_name']['coreconfig']['fields']['coreconfig']['value'],
159
+ 'error' => $_FILES['groups']['error']['coreconfig']['fields']['coreconfig']['value'],
160
+ 'size' => $_FILES['groups']['size']['coreconfig']['fields']['coreconfig']['value']
161
+ )
162
+ );
163
+
164
+ $uploader->setAllowedExtensions(array('csv')); // allowed extension
165
+ $uploader->setFilesDispersion(false);
166
+ $destination = Mage::getBaseDir("var") . DS . str_replace("/", DS, 'import/');
167
+
168
+
169
+ // Make import directory
170
+ if (!is_dir($destination)) {
171
+ if (!mkdir($destination, 0777)) {
172
+ Mage::throwException("import folder needs to be under var folder");
173
+ }
174
+ }
175
+ $folderPermission = substr(sprintf('%o', fileperms($destination)), -4);
176
+ if ($folderPermission != '0777') {
177
+ Mage::throwException($destination . " is not writable. Please check the permission for the directory specified.");
178
+ }
179
+ $fileName = $_FILES['groups']['name']['coreconfig']['fields']['coreconfig']['value'];
180
+
181
+ //save the file in the specified destination
182
+ $uploader->save($destination, $fileName);
183
+ $fileOpen = fopen($destination . $fileName, "r");
184
+
185
+ return $fileOpen;
186
+ }
187
+
188
+ }
app/code/community/Lister/Coreconfig/etc/adminhtml.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Lister ( http://www.listertechnologies.com )
5
+ * @package Lister_Coreconfig
6
+ * @contacts info@listertechnologies.com
7
+ */
8
+ -->
9
+ <config>
10
+ <acl>
11
+ <resources>
12
+ <admin>
13
+ <children>
14
+ <system>
15
+ <children>
16
+ <config>
17
+ <children>
18
+ <coreconfig translate="title" module="coreconfig">
19
+ <title>Config Uploader</title>
20
+ </coreconfig>
21
+ </children>
22
+ </config>
23
+ </children>
24
+ </system>
25
+ </children>
26
+ </admin>
27
+ </resources>
28
+ </acl>
29
+ </config>
app/code/community/Lister/Coreconfig/etc/config.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Lister ( http://www.listertechnologies.com )
5
+ * @package Lister_Coreconfig
6
+ * @contacts info@listertechnologies.com
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Lister_Coreconfig>
12
+ <version>0.0.1</version>
13
+ </Lister_Coreconfig>
14
+ </modules>
15
+ <global>
16
+ <models>
17
+ <coreconfig>
18
+ <class>Lister_Coreconfig_Model</class>
19
+ </coreconfig>
20
+ </models>
21
+ <helpers>
22
+ <coreconfig>
23
+ <class>Lister_Coreconfig_Helper</class>
24
+ </coreconfig>
25
+ </helpers>
26
+ </global>
27
+ </config>
app/code/community/Lister/Coreconfig/etc/system.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Lister ( http://www.listertechnologies.com )
5
+ * @package Lister_Coreconfig
6
+ * @contacts info@listertechnologies.com
7
+ */
8
+ -->
9
+ <config>
10
+ <tabs>
11
+ <coreconfig translate="label" module="coreconfig">
12
+ <label>Lister Config Import</label>
13
+ <sort_order>30000</sort_order>
14
+ </coreconfig>
15
+ </tabs>
16
+ <sections>
17
+ <coreconfig translate="label" module="coreconfig">
18
+ <label>Import Config</label>
19
+ <tab>coreconfig</tab>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>302</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_store>1</show_in_store>
24
+ <groups>
25
+ <coreconfig translate="label">
26
+ <label>Create / Update configuration values</label>
27
+ <frontend_type>text</frontend_type>
28
+ <sort_order>1</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_store>1</show_in_store>
31
+ <fields>
32
+ <coreconfig translate="label">
33
+ <label>Select csv file to import data</label>
34
+ <frontend_type>import</frontend_type>
35
+ <comment>Csv should contain scope,scope_id,path,value</comment>
36
+ <backend_model>coreconfig/import</backend_model>
37
+ <sort_order>1</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ </coreconfig>
40
+ </fields>
41
+ </coreconfig>
42
+ </groups>
43
+ </coreconfig>
44
+ </sections>
45
+ </config>
app/etc/modules/Lister_Coreconfig.xml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ *
5
+ * @category Lister (http://www.listertechnologies.com)
6
+ * @package Lister_Coreconfig
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Lister_Coreconfig>
12
+ <active>true</active>
13
+ <codePool>community</codePool>
14
+ </Lister_Coreconfig>
15
+ </modules>
16
+ </config>
package.xml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Lister_Coreconfig</name>
4
+ <version>0.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Coreconfig - Module which is used to import the config data via csv and store it in the respective table (core_config_data)</summary>
10
+ <description>Magento Installations with more than one website/store/storeview with active development then copying all the manual config changes done by the developers to production will become difficult. It will become much more critical when you have pool of developers &amp; designers working on.&#xD;
11
+ &#xD;
12
+ This module helps to reduce the pain, development cost &amp; the quality cost by updating any number of configurations in a single click. Also this module reduces the chance of human errors when you have too many configurations. Also this will help you to fastrack the deployment time.&#xD;
13
+ &#xD;
14
+ Just the developer needs to take the back up of configurations which needs to be updated in production and replace production specific values if any, prove the csv to the system admin / Magento Admin with the proper instructions where to import and save.&#xD;
15
+ &#xD;
16
+ Features: &#xD;
17
+ &#xD;
18
+ Simple to use : Just specify the path, scope and the value to be updated.&#xD;
19
+ &#xD;
20
+ Time effective : Any number of configurations will be updated with in a short span.&#xD;
21
+ &#xD;
22
+ Seemlessly work with any extension.&#xD;
23
+ &#xD;
24
+ Scope settigs can also be defined.</description>
25
+ <notes>This is the initial stable version.</notes>
26
+ <authors><author><name>Lister Technologies (P) Ltd</name><user>Lister</user><email>senthil.muppidathi@listertechnologies.com</email></author></authors>
27
+ <date>2015-05-28</date>
28
+ <time>10:51:51</time>
29
+ <contents><target name="magecommunity"><dir name="Lister"><dir name="Coreconfig"><dir name="Helper"><file name="Data.php" hash="cbbb844cf3c432190cf7922fcaf5cb1c"/></dir><dir name="Model"><file name="Import.php" hash="07e75a2de9426e984956ba62fa442930"/></dir><dir name="etc"><file name="adminhtml.xml" hash="8da415f2e282cd71b9bb3236da09d286"/><file name="config.xml" hash="bd7ad6de39af734f5d9a4e8ad10c96d9"/><file name="system.xml" hash="d08b0be6a03415d67cde38d5ff5714f0"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Lister_Coreconfig.xml" hash="ed0b754c0ba6281f7ed977c14812d361"/></dir></target></contents>
30
+ <compatible/>
31
+ <dependencies><required><php><min>5.1.0</min><max>5.6.9</max></php></required></dependencies>
32
+ </package>