regions_manager - Version 1.0.0

Version Notes

Moduleversion 1.0.0 allows you manage regions for any country on magento so that it will drop down list in the address fields.

Download this release

Release Info

Developer Mohammed Meabed
Extension regions_manager
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Web/States/Block/Adminhtml/Renderer/Name.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Block_Adminhtml_Renderer_Name extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
3
+ {
4
+ public function render(Varien_Object $row)
5
+ {
6
+ $html = '';
7
+ $locales = Mage::helper('web_states')->getLocales();
8
+
9
+ $resource = Mage::getSingleton('core/resource');
10
+ $read = $resource->getConnection('core_read');
11
+ $regionName = $resource->getTableName('directory/country_region_name');
12
+
13
+ $select = $read->select()->from(array('region' => $regionName))->where('region.region_id=?', $row->getRegionId());
14
+ $data = $read->fetchAll($select);
15
+ foreach ($data as $row) {
16
+ $arr[$row['locale']] = $row['name'];
17
+ }
18
+ foreach ($locales as $locale) {
19
+ $name = $arr[$locale];
20
+ if (!$name) {
21
+ $name = 'EMPTY';
22
+ }
23
+ $html[] = '<span>' . $locale . '</span> => <span class="' . $locale . '_name">' . $name . '</span>';
24
+ }
25
+ $html = implode('<br />', $html);
26
+
27
+ if ($html == '') {
28
+ $html = '&nbsp;';
29
+ }
30
+
31
+ return $html;
32
+ }
33
+ }
app/code/community/Web/States/Block/Adminhtml/States.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Block_Adminhtml_States extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ $this->_controller = 'adminhtml_states';
7
+ $this->_blockGroup = 'web_states';
8
+ $this->_headerText = Mage::helper('web_states')->__('Country/States Manager');
9
+ parent::__construct();
10
+ }
11
+ }
app/code/community/Web/States/Block/Adminhtml/States/Edit.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Block_Adminhtml_States_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ $this->_objectId = 'region_id';
8
+ $this->_blockGroup = 'web_states';
9
+ $this->_controller = 'adminhtml_states';
10
+ $this->_updateButton('save', 'label', Mage::helper('web_states')->__('Save Item'));
11
+ $this->_updateButton('delete', 'label', Mage::helper('web_states')->__('Delete Item'));
12
+
13
+ }
14
+
15
+ public function getHeaderText()
16
+ {
17
+ if (Mage::registry('state_data') && Mage::registry('state_data')->getRegionId()) {
18
+ return Mage::helper('web_states')->__("Edit Item '%s'", $this->escapeHtml(Mage::registry('state_data')->getRegionId()));
19
+ } else {
20
+ return Mage::helper('web_states')->__('Add Item');
21
+ }
22
+ }
23
+ }
app/code/community/Web/States/Block/Adminhtml/States/Edit/Form.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Block_Adminhtml_States_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
3
+ {
4
+ protected function _prepareForm()
5
+ {
6
+ $form = new Varien_Data_Form(array(
7
+ 'id' => 'edit_form',
8
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('region_id'))),
9
+ 'method' => 'post',
10
+ )
11
+ );
12
+
13
+ $form->setUseContainer(true);
14
+ $this->setForm($form);
15
+ return parent::_prepareForm();
16
+ }
17
+ }
app/code/community/Web/States/Block/Adminhtml/States/Edit/Tab/Form.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Block_Adminhtml_States_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
3
+ {
4
+ protected function _prepareForm()
5
+ {
6
+ $form = new Varien_Data_Form();
7
+ $this->setForm($form);
8
+ $countries = Mage::getSingleton('directory/country')->getCollection()->loadData()->toOptionArray(false);
9
+ $id = $this->getRequest()->getParam('region_id');
10
+
11
+
12
+
13
+ $fieldSet = $form->addFieldset('web_states_form', array('legend' => Mage::helper('web_states')->__('State information')));
14
+ $fieldSet->addField(
15
+ 'country_id', 'select', array(
16
+ 'label' => Mage::helper('web_states')->__('Country'),
17
+ 'name' => 'country_id',
18
+ 'required' => true,
19
+ 'values' => $countries
20
+ )
21
+ );
22
+
23
+ $fieldSet->addField(
24
+ 'code', 'text', array(
25
+ 'label' => Mage::helper('web_states')->__('Code'),
26
+ 'class' => 'required-entry',
27
+ 'required' => true,
28
+ 'name' => 'code',
29
+ )
30
+ );
31
+ $fieldSet->addField(
32
+ 'default_name', 'text', array(
33
+ 'label' => Mage::helper('web_states')->__('Default Name'),
34
+ 'class' => 'required-entry',
35
+ 'required' => true,
36
+ 'name' => 'default_name',
37
+ )
38
+ );
39
+ $locales = Mage::helper('web_states')->getLocales();
40
+ foreach ($locales as $locale) {
41
+ $fieldSet{$locale} = $form->addFieldset('web_states_form_' . $locale, array('legend' => Mage::helper('web_states')->__('Locale ' . $locale)));
42
+ $fieldSet{$locale}->addField(
43
+ 'name_'.$locale, 'text', array(
44
+ 'label' => Mage::helper('web_states')->__('Name'),
45
+ 'name' => 'name_'.$locale,
46
+ )
47
+ );
48
+ }
49
+ if (Mage::getSingleton('adminhtml/session')->getStateData()) {
50
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getStateData());
51
+ Mage::getSingleton('adminhtml/session')->setStateData(null);
52
+ } elseif (Mage::registry('state_data')) {
53
+ $form->setValues(Mage::registry('state_data')->getData());
54
+ }
55
+ if($id){
56
+ $resource = Mage::getSingleton('core/resource');
57
+ $read = $resource->getConnection('core_read');
58
+ $regionName = $resource->getTableName('directory/country_region_name');
59
+
60
+ $select = $read->select()->from(array('region'=>$regionName))->where('region.region_id=?', $id);
61
+ $data =$read->fetchAll($select);
62
+ foreach($data as $row)
63
+ {
64
+ $form->addValues(array('name_'.$row['locale']=> $row['name']));
65
+ }
66
+ }
67
+ return parent::_prepareForm();
68
+
69
+ }
70
+ }
app/code/community/Web/States/Block/Adminhtml/States/Edit/Tabs.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Block_Adminhtml_States_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('web_states_tabs');
9
+ $this->setDestElementId('edit_form');
10
+ $this->setTitle(Mage::helper('web_states')->__('State Information'));
11
+ }
12
+
13
+ protected function _beforeToHtml()
14
+ {
15
+ $this->addTab('form_section', array(
16
+ 'label' => Mage::helper('web_states')->__('State Information'),
17
+ 'title' => Mage::helper('web_states')->__('State Information'),
18
+ 'content' => $this->getLayout()->createBlock('web_states/adminhtml_states_edit_tab_form')->toHtml(),
19
+ ));
20
+
21
+ return parent::_beforeToHtml();
22
+ }
23
+ }
app/code/community/Web/States/Block/Adminhtml/States/Grid.php ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Block_Adminhtml_States_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ $this->setId('web_states_grid');
8
+ $this->setDefaultSort('region_id');
9
+ $this->setDefaultDir('DESC');
10
+ $this->setSaveParametersInSession(true);
11
+ }
12
+
13
+ protected function _prepareCollection()
14
+ {
15
+ $collection = Mage::getModel('web_states/states')->getCollection();
16
+ $this->setCollection($collection);
17
+
18
+ $this->setLocales(Mage::helper('web_states')->getLocales());
19
+ return parent::_prepareCollection();
20
+ }
21
+
22
+ protected function _prepareColumns()
23
+ {
24
+ $this->addColumn(
25
+ 'region_id', array(
26
+ 'header' => Mage::helper('web_states')->__('ID'),
27
+ 'align' => 'left',
28
+ 'width' => '5',
29
+ 'index' => 'region_id',
30
+ 'column_css_class' => 'row_id'
31
+ )
32
+ );
33
+
34
+ $this->addColumn(
35
+ 'country_id', array(
36
+ 'header' => Mage::helper('web_states')->__('Country Code'),
37
+ 'align' => 'left',
38
+ 'width' => '110px',
39
+ 'index' => 'country_id',
40
+ 'type' => 'country',
41
+ )
42
+ );
43
+ $this->addColumn(
44
+ 'code', array(
45
+ 'header' => Mage::helper('web_states')->__('Region Code'),
46
+ 'align' => 'left',
47
+ 'width' => '110px',
48
+ 'index' => 'code',
49
+ //'editable' =>true,
50
+ 'column_css_class' => 'code_td'
51
+ )
52
+ );
53
+ $this->addColumn(
54
+ 'default_name', array(
55
+ 'header' => Mage::helper('web_states')->__('Default Name'),
56
+ 'align' => 'left',
57
+ 'width' => '110px',
58
+ 'index' => 'default_name',
59
+ //'editable' =>true,
60
+ 'column_css_class' => 'default_name'
61
+ )
62
+ );
63
+ $this->addColumn(
64
+ 'name_locale', array(
65
+ 'header' => Mage::helper('web_states')->__('Name in Locale'),
66
+ 'align' => 'left',
67
+ 'width' => '110px',
68
+ 'index' => 'region_id',
69
+ 'sortable' => false,
70
+ 'filter' => false,
71
+ 'renderer' => 'Web_States_Block_Adminhtml_Renderer_Name',
72
+
73
+ //'editable' =>true,
74
+ 'column_css_class' => 'name_locale'
75
+ )
76
+ );
77
+ $this->addColumn(
78
+ 'action',
79
+ array(
80
+ 'header' => Mage::helper('web_states')->__('Action'),
81
+ 'width' => '50px',
82
+ 'type' => 'action',
83
+ 'getter' => 'getRegionId',
84
+ 'actions' => array(
85
+ array(
86
+ 'caption' => Mage::helper('web_states')->__('View'),
87
+ 'url' => array('base' => '*/*/edit'),
88
+ 'field' => 'region_id'
89
+ )
90
+ ),
91
+ 'filter' => false,
92
+ 'sortable' => false,
93
+ 'index' => 'region_id',
94
+ 'is_system' => true,
95
+ )
96
+ );
97
+ $this->setAdditionalJavaScript($this->getScripts());
98
+ return parent::_prepareColumns();
99
+ }
100
+
101
+ public function getRowUrl($row)
102
+ {
103
+ return '';
104
+ return $this->getUrl('*/*/edit', array('id' => $row->getRegionId()));
105
+ }
106
+
107
+ protected function _prepareMassaction()
108
+ {
109
+ $this->setMassactionIdField('region_id');
110
+ $this->getMassactionBlock()->setUseSelectAll(false);
111
+ $this->getMassactionBlock()->setFormFieldName('web_states');
112
+ $this->getMassactionBlock()->addItem(
113
+ 'delete', array(
114
+ 'label' => Mage::helper('web_states')->__('Delete'),
115
+ 'url' => $this->getUrl('*/*/massDelete', array('_current' => true)),
116
+ )
117
+ );
118
+ return $this;
119
+ }
120
+
121
+ public function getScripts()
122
+ {
123
+ $locales = Mage::helper('web_states')->getLocales();
124
+
125
+ $nameUrl = $this->getUrl('*/*/saveName');
126
+ $codeUrl = $this->getUrl('*/*/saveCode');
127
+ $js
128
+ = '
129
+ function getNameUrl(e)
130
+ {
131
+ return "' . $nameUrl . 'region_id/"+getId(e);
132
+ }
133
+ function getCodeUrl(e)
134
+ {
135
+ return "' . $codeUrl . 'region_id/"+getId(e);
136
+ }
137
+ function getNameLocaleUrl(e,url)
138
+ {
139
+ return url+"region_id/"+getId(e);
140
+ }
141
+ function getId(e)
142
+ {
143
+ id = e.up("tr").down("td.row_id").innerHTML;
144
+ return id.trim();
145
+ }
146
+ ';
147
+ $js
148
+ .= <<<EOF
149
+ document.observe('dom:loaded', function() {
150
+ $$('.default_name').each(function(el){
151
+ if(el.down('span')){return ;}
152
+ idx = getId(el);
153
+ el.update('<span id='+idx+'>'+el.innerHTML.trim()+'</span>');
154
+ new Ajax.InPlaceEditor(el.down('span'), getNameUrl(el),{formId:idx,okText: 'Save',cancelText: 'Cancel'} );
155
+ });
156
+ $$('.code_td').each(function(el){
157
+ if(el.down('span')){return ;}
158
+ idx = getId(el);
159
+ el.update('<span id='+idx+'>'+el.innerHTML.trim()+'</span>');
160
+ new Ajax.InPlaceEditor(el.down('span'), getCodeUrl(el),{formId:idx,okText: 'Save',cancelText: 'Cancel'} );
161
+ });
162
+
163
+ EOF;
164
+ foreach($locales as $locale)
165
+ {
166
+ $nameLocaleUrl = $this->getUrl('*/*/saveNameLocale',array('locale'=>$locale));
167
+ $e_name = $locale.'_name';
168
+ $js
169
+ .= <<<EOF
170
+ $$('.$e_name').each(function(el){
171
+ idx = getId(el);
172
+ el.update('<span id='+idx+'>'+el.innerHTML.trim()+'</span>');
173
+ new Ajax.InPlaceEditor(el.down('span'), getNameLocaleUrl(el,'$nameLocaleUrl'),{formId:idx,okText: 'Save',cancelText: 'Cancel'} );
174
+ });
175
+
176
+ EOF;
177
+
178
+ }
179
+ $js .='});';
180
+ return $js;
181
+
182
+ }
183
+
184
+ }
app/code/community/Web/States/Helper/Data.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by Mohammed Meabed
4
+ * Date: 7/18/13
5
+ * Time: 3:46 AM
6
+ */
7
+ class Web_States_Helper_Data extends Mage_Core_Helper_Abstract {
8
+ public function getLocales()
9
+ {
10
+ $stores = Mage::app()->getStores();
11
+ $locales = array();
12
+ foreach ($stores as $store) {
13
+ $v = Mage::getStoreConfig('general/locale/code', $store->getId());
14
+ $locales[$v] = $v;
15
+ }
16
+ return $locales;
17
+ }
18
+
19
+ }
app/code/community/Web/States/Model/Mysql4/States.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Model_Mysql4_States extends Web_States_Model_Resource_States
3
+ {
4
+
5
+ }
app/code/community/Web/States/Model/Mysql4/States/Collection.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Model_Mysql4_States_Collection extends Web_States_Model_Resource_States_Collection
3
+ {
4
+
5
+ }
app/code/community/Web/States/Model/Resource/States.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Model_Resource_States extends Mage_Core_Model_Resource_Db_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('web_states/states', 'region_id');
7
+ }
8
+ }
app/code/community/Web/States/Model/Resource/States/Collection.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Model_Resource_States_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
3
+ {
4
+
5
+ }
app/code/community/Web/States/Model/States.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Model_States extends Mage_Core_Model_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('web_states/states');
7
+ }
8
+
9
+ }
app/code/community/Web/States/controllers/Adminhtml/StatesController.php ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Web_States_Adminhtml_StatesController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ protected function _initAction()
5
+ {
6
+ $this->loadLayout()
7
+ ->_setActiveMenu('cms/web_states');
8
+ return $this;
9
+ }
10
+
11
+ public function indexAction()
12
+ {
13
+ $this->_initAction();
14
+ $this->renderLayout();
15
+ }
16
+
17
+ public function editAction()
18
+ {
19
+ $regionId = $this->getRequest()->getParam('region_id');
20
+ $state = Mage::getModel('web_states/states')->load($regionId);
21
+
22
+ if ($state->getRegionId() || $regionId == 0) {
23
+ $this->_initAction();
24
+ Mage::register('state_data', $state);
25
+ $this->_addBreadcrumb(Mage::helper('web_states')->__('Country/States Manager'), Mage::helper('web_states')->__('Item Manager'));
26
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
27
+
28
+ $this->_addContent($this->getLayout()->createBlock('web_states/adminhtml_states_edit'))
29
+ ->_addLeft($this->getLayout()->createBlock('web_states/adminhtml_states_edit_tabs'));
30
+
31
+ $this->renderLayout();
32
+ } else {
33
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('web_states')->__('State does not exist'));
34
+ $this->_redirect('*/*/');
35
+ }
36
+ }
37
+
38
+ public function newAction()
39
+ {
40
+ $this->_forward('edit');
41
+ }
42
+
43
+ public function saveAction()
44
+ {
45
+ $request = $this->getRequest();
46
+
47
+ if ($this->getRequest()->getPost()) {
48
+ $id = $request->getParam('id');
49
+ $code = $request->getParam('code');
50
+ $name = $request->getParam('default_name');
51
+ $countryId = $request->getParam('country_id');
52
+ if (!$name || !$code) {
53
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please fill the required fields'));
54
+ $this->_redirect('*/*/');
55
+ return;
56
+ }
57
+ $state = Mage::getModel('web_states/states')->getCollection()
58
+ ->addFieldToFilter('code', $code)
59
+ ->addFieldToFilter('country_id', $countryId)
60
+ ->getAllIds();
61
+ if (count($state) > 0 && !in_array($id, $state)) {
62
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('State/Country combination must be unique'));
63
+ $this->_redirect('*/*/edit', array('region_id' => $id));
64
+ return;
65
+ }
66
+
67
+ try {
68
+ $state = Mage::getModel('web_states/states');
69
+ $state->setRegionId($id)
70
+ ->setCode($code)
71
+ ->setCountryId($countryId)
72
+ ->setDefaultName($name)
73
+ ->save();
74
+ if ($state->getRegionId()) {
75
+ $locales = Mage::helper('web_states')->getLocales();
76
+ $resource = Mage::getSingleton('core/resource');
77
+ $write = $resource->getConnection('core_write');
78
+ $regionName = $resource->getTableName('directory/country_region_name');
79
+ $write->delete($regionName, array('region_id =' . $state->getRegionId()));
80
+ foreach ($locales as $locale) {
81
+ $localeName = $request->getParam('name_' . $locale);
82
+ if ($localeName) {
83
+ $write->insert($regionName, array('region_id' => $state->getRegionId(), 'locale' => $locale, 'name' => trim($name)));
84
+ }
85
+ }
86
+ }
87
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
88
+ Mage::getSingleton('adminhtml/session')->getStateData(false);
89
+ $this->_redirect('*/*/');
90
+ return;
91
+ } catch (Exception $e) {
92
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
93
+ Mage::getSingleton('adminhtml/session')->setStateData($this->getRequest()->getPost());
94
+ $this->_redirect('*/*/edit', array('region_id' => $this->getRequest()->getParam('id')));
95
+ return;
96
+ }
97
+ }
98
+ $this->_redirect('*/*/');
99
+ }
100
+
101
+ public function saveNameAction()
102
+ {
103
+ $request = $this->getRequest();
104
+ $editorId = $request->getParam('editorId');
105
+ $value = $request->getParam('value');
106
+ if (!$editorId) {
107
+ echo $this->__('Unable to Save.');
108
+ return;
109
+ }
110
+ if (!$value) {
111
+ echo $this->__('Value can not be empty.');
112
+ return;
113
+ }
114
+ $model = Mage::getModel('web_states/states')->load($editorId);
115
+ $model->setDefaultName(trim($value));
116
+ try {
117
+ $model->save();
118
+ } catch (Exception $e) {
119
+ echo $e->getCode() . '-' . $e->getMessage();
120
+ }
121
+ echo $model->getDefaultName();
122
+
123
+ }
124
+
125
+ public function saveNameLocaleAction()
126
+ {
127
+ $request = $this->getRequest();
128
+ $editorId = $request->getParam('editorId');
129
+ $locale = $request->getParam('locale');
130
+ $value = $request->getParam('value');
131
+ if (!$editorId) {
132
+ echo $this->__('Unable to Save.');
133
+ return;
134
+ }
135
+ if (!$locale) {
136
+ echo $this->__('Locale can not be empty.');
137
+ return;
138
+ }
139
+ if ($value == 'EMPTY' || $value == 'Empty value will not be saved.') {
140
+ echo $this->__('Empty value will not be saved.');
141
+ return;
142
+ }
143
+ $resource = Mage::getSingleton('core/resource');
144
+ $write = $resource->getConnection('core_write');
145
+ $regionName = $resource->getTableName('directory/country_region_name');
146
+ $write->delete($regionName, array('region_id =' . $editorId));
147
+
148
+ if ($value) {
149
+ $write->insert($regionName, array('region_id' => $editorId, 'locale' => $locale, 'name' => trim($value)));
150
+ }
151
+ $select = $write->select('*')->from(array('region' => $regionName))->where('region.region_id=?', $editorId)->where('region.locale=?', $locale);
152
+ $row = $write->fetchRow($select);
153
+ echo $row['name'];
154
+ }
155
+
156
+ public function saveCodeAction()
157
+ {
158
+ $request = $this->getRequest();
159
+ $editorId = $request->getParam('editorId');
160
+ $value = $request->getParam('value');
161
+ if (!$editorId) {
162
+ echo $this->__('Unable to Save.');
163
+ return;
164
+ }
165
+ if (!$value) {
166
+ echo $this->__('Value can not be empty.');
167
+ return;
168
+ }
169
+ $row = Mage::getModel('web_states/states')->getCollection()
170
+ ->addFieldToFilter('code', $value)
171
+ ->getFirstItem();
172
+ if (($row->getRegionId() == $editorId) && (trim($value) == $row->getCode())) {
173
+ echo $row->getCode() . ' not updated';
174
+ return;
175
+ }
176
+ if ($row->getRegionId()) {
177
+ echo $this->__('State code must be unique.');
178
+ return;
179
+ }
180
+
181
+ $model = Mage::getModel('web_states/states')->load($editorId);
182
+ $model->setCode(trim($value));
183
+ try {
184
+ $model->save();
185
+ } catch (Exception $e) {
186
+ echo $e->getCode() . '-' . $e->getMessage();
187
+ }
188
+ echo $model->getCode();
189
+ }
190
+
191
+ public function massDeleteAction()
192
+ {
193
+ $stateIds = $this->getRequest()->getParam('web_states');
194
+ if (!is_array($stateIds)) {
195
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select state(s).'));
196
+ } else {
197
+ try {
198
+ $state = Mage::getModel('web_states/states');
199
+ foreach ($stateIds as $stateId) {
200
+ $state->load($stateId)
201
+ ->delete();
202
+ }
203
+ Mage::getSingleton('adminhtml/session')->addSuccess(
204
+ Mage::helper('adminhtml')->__('Total of %d record(s) were deleted.', count($stateIds))
205
+ );
206
+ } catch (Exception $e) {
207
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
208
+ }
209
+ }
210
+
211
+ $this->_redirect('*/*/index');
212
+
213
+ }
214
+
215
+ }
app/code/community/Web/States/etc/adminhtml.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <cms>
5
+ <children>
6
+ <web_states module="web_states">
7
+ <title>Country States</title>
8
+ <sort_order>100</sort_order>
9
+ <action>states/adminhtml_states</action>
10
+ </web_states>
11
+ </children>
12
+ </cms>
13
+ </menu>
14
+ <acl>
15
+ <resources>
16
+ <admin>
17
+ <children>
18
+ <web_states>
19
+ <title>Country States</title>
20
+ <sort_order>600</sort_order>
21
+ </web_states>
22
+ </children>
23
+ </admin>
24
+ </resources>
25
+ </acl>
26
+ </config>
app/code/community/Web/States/etc/config.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Web_States>
5
+ <version>0.1.0</version>
6
+ </Web_States>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <web_states>
11
+ <class>Web_States_Model</class>
12
+ <resourceModel>web_states_mysql4</resourceModel>
13
+ </web_states>
14
+ <web_states_mysql4>
15
+ <class>Web_States_Model_Mysql4</class>
16
+ <entities>
17
+ <states>
18
+ <table>directory_country_region</table>
19
+ </states>
20
+ </entities>
21
+ </web_states_mysql4>
22
+ </models>
23
+ <blocks>
24
+ <web_states>
25
+ <class>Web_States_Block</class>
26
+ </web_states>
27
+ </blocks>
28
+ <helpers>
29
+ <web_states>
30
+ <class>Web_States_Helper</class>
31
+ </web_states>
32
+ </helpers>
33
+ <resources>
34
+ <web_states_setup>
35
+ <setup>
36
+ <module>Web_States</module>
37
+ </setup>
38
+ </web_states_setup>
39
+ <web_states_read>
40
+ <connection>
41
+ <use>core_read</use>
42
+ </connection>
43
+ </web_states_read>
44
+ <web_states_write>
45
+ <connection>
46
+ <use>core_write</use>
47
+ </connection>
48
+ </web_states_write>
49
+ </resources>
50
+ </global>
51
+ <admin>
52
+ <routers>
53
+ <web_states>
54
+ <use>admin</use>
55
+ <args>
56
+ <module>Web_States</module>
57
+ <frontName>states</frontName>
58
+ </args>
59
+ </web_states>
60
+ </routers>
61
+ </admin>
62
+ <adminhtml>
63
+ <layout>
64
+ <updates>
65
+ <web_states>
66
+ <file>web_states.xml</file>
67
+ </web_states>
68
+ </updates>
69
+ </layout>
70
+ </adminhtml>
71
+ </config>
app/code/community/Web/States/sql/web_states_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by Mohammed Meabed
4
+ * Date: 7/18/13
5
+ * Time: 3:46 AM
6
+ */
7
+ /* @var $installer Mage_Core_Model_Resource_Setup */
8
+ $installer = $this;
9
+
10
+ $installer->startSetup();
11
+
12
+
13
+
14
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/web_states.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <web_states_adminhtml_states_index>
4
+ <reference name="content">
5
+ <block type="web_states/adminhtml_states" name="web_states"/>
6
+ </reference>
7
+ </web_states_adminhtml_states_index>
8
+ </layout>
app/etc/modules/Web_States.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Web_States>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Directory/>
9
+
10
+ </depends>
11
+ </Web_States>
12
+ </modules>
13
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>regions_manager</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>States Manager for countries drop down list</summary>
10
+ <description>Magento provides country and region* as dropdown option in addresses This module provides flexibility of managing this regions for each country with its locale translations.</description>
11
+ <notes>Moduleversion 1.0.0 allows you manage regions for any country on magento so that it will drop down list in the address fields.</notes>
12
+ <authors><author><name>Mohammed Meabed</name><user>meabed</user><email>mo.meabed@gmail.com</email></author></authors>
13
+ <date>2013-07-18</date>
14
+ <time>19:03:22</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Web_States.xml" hash="f3bb54abd76c0d70a29c8377bd6d5410"/></dir></target><target name="magecommunity"><dir name="Web"><dir name="States"><dir name="Block"><dir name="Adminhtml"><dir name="Renderer"><file name="Name.php" hash="4eb5be33722df5922617e70f8d33cdda"/></dir><dir name="States"><dir name="Edit"><file name="Form.php" hash="6b659d1c5c7e7026af78ca39c78115b8"/><dir name="Tab"><file name="Form.php" hash="69c6dc43ea76238d1f5674677ff9b3e9"/></dir><file name="Tabs.php" hash="901859a748339b12f64e73b1d79ba8fc"/></dir><file name="Edit.php" hash="8f58d5d8dccabc59792355b2a6239e46"/><file name="Grid.php" hash="3bc6366734eef5ad1248ed4fdb6a7f2f"/></dir><file name="States.php" hash="d0a3644fb912e22021e98d88b8f7a6c9"/></dir></dir><dir name="Helper"><file name="Data.php" hash="db4734248cb15b57e2120d929f1fe814"/></dir><dir name="Model"><dir name="Mysql4"><dir name="States"><file name="Collection.php" hash="e37f39858e22304c7542362456c7553d"/></dir><file name="States.php" hash="ab904a71af6297ebbd3007a454ffeb7c"/></dir><dir name="Resource"><dir name="States"><file name="Collection.php" hash="b2d5ed5740a2ff530b9ce8ede55c27c4"/></dir><file name="States.php" hash="834be4c3985af02f3e80f7fd1409c2c7"/></dir><file name="States.php" hash="2e6a923ed8caa6c007a9efd7ccdb6910"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="StatesController.php" hash="bde861f0b23d812181964be80030f751"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="51901fff643b14f3ed1f0b3755c1e2fa"/><file name="config.xml" hash="9d6a49df7bd60726a32df8b9cedbbf99"/></dir><dir name="sql"><dir name="web_states_setup"><file name="mysql4-install-0.1.0.php" hash="431bbe763c9cf423f830346f16066145"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="web_states.xml" hash="95c276d5deea765290636009441f6eb8"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.1</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>