1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Model_System_Config_Backend_Customer_Show_Customer extends Mage_Core_Model_Config_Data
35: {
36: 37: 38: 39: 40:
41: protected function _getAttributeCode()
42: {
43: return str_replace('_show', '', $this->getField());
44: }
45:
46: 47: 48: 49: 50:
51: protected function _getAttributeObjects()
52: {
53: return array(
54: Mage::getSingleton('eav/config')->getAttribute('customer', $this->_getAttributeCode())
55: );
56: }
57:
58: 59: 60: 61: 62:
63: protected function _afterSave()
64: {
65: $result = parent::_afterSave();
66:
67: $valueConfig = array(
68: '' => array('is_required' => 0, 'is_visible' => 0),
69: 'opt' => array('is_required' => 0, 'is_visible' => 1),
70: '1' => array('is_required' => 0, 'is_visible' => 1),
71: 'req' => array('is_required' => 1, 'is_visible' => 1),
72: );
73:
74: $value = $this->getValue();
75: if (isset($valueConfig[$value])) {
76: $data = $valueConfig[$value];
77: } else {
78: $data = $valueConfig[''];
79: }
80:
81: if ($this->getScope() == 'websites') {
82: $website = Mage::app()->getWebsite($this->getWebsiteCode());
83: $dataFieldPrefix = 'scope_';
84: } else {
85: $website = null;
86: $dataFieldPrefix = '';
87: }
88:
89: foreach ($this->_getAttributeObjects() as $attributeObject) {
90: if ($website) {
91: $attributeObject->setWebsite($website);
92: $attributeObject->load($attributeObject->getId());
93: }
94: $attributeObject->setData($dataFieldPrefix . 'is_required', $data['is_required']);
95: $attributeObject->setData($dataFieldPrefix . 'is_visible', $data['is_visible']);
96: $attributeObject->save();
97: }
98:
99: return $result;
100: }
101:
102: 103: 104: 105: 106:
107: protected function _afterDelete()
108: {
109: $result = parent::_afterDelete();
110:
111: if ($this->getScope() == 'websites') {
112: $website = Mage::app()->getWebsite($this->getWebsiteCode());
113: foreach ($this->_getAttributeObjects() as $attributeObject) {
114: $attributeObject->setWebsite($website);
115: $attributeObject->load($attributeObject->getId());
116: $attributeObject->setData('scope_is_required', null);
117: $attributeObject->setData('scope_is_visible', null);
118: $attributeObject->save();
119: }
120: }
121:
122: return $result;
123: }
124: }
125: