1: <?php
2: /**
3: * Magento
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: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Customer
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Customer resource setup model
30: *
31: * @category Mage
32: * @package Mage_Customer
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Customer_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
36: {
37: /**
38: * Prepare customer attribute values to save in additional table
39: *
40: * @param array $attr
41: * @return array
42: */
43: protected function _prepareValues($attr)
44: {
45: $data = parent::_prepareValues($attr);
46: $data = array_merge($data, array(
47: 'is_visible' => $this->_getValue($attr, 'visible', 1),
48: 'is_system' => $this->_getValue($attr, 'system', 1),
49: 'input_filter' => $this->_getValue($attr, 'input_filter', null),
50: 'multiline_count' => $this->_getValue($attr, 'multiline_count', 0),
51: 'validate_rules' => $this->_getValue($attr, 'validate_rules', null),
52: 'data_model' => $this->_getValue($attr, 'data', null),
53: 'sort_order' => $this->_getValue($attr, 'position', 0)
54: ));
55:
56: return $data;
57: }
58:
59: /**
60: * Add customer attributes to customer forms
61: *
62: * @return void
63: */
64: public function installCustomerForms()
65: {
66: $customer = (int)$this->getEntityTypeId('customer');
67: $customerAddress = (int)$this->getEntityTypeId('customer_address');
68:
69: $attributeIds = array();
70: $select = $this->getConnection()->select()
71: ->from(
72: array('ea' => $this->getTable('eav/attribute')),
73: array('entity_type_id', 'attribute_code', 'attribute_id'))
74: ->where('ea.entity_type_id IN(?)', array($customer, $customerAddress));
75: foreach ($this->getConnection()->fetchAll($select) as $row) {
76: $attributeIds[$row['entity_type_id']][$row['attribute_code']] = $row['attribute_id'];
77: }
78:
79: $data = array();
80: $entities = $this->getDefaultEntities();
81: $attributes = $entities['customer']['attributes'];
82: foreach ($attributes as $attributeCode => $attribute) {
83: $attributeId = $attributeIds[$customer][$attributeCode];
84: $attribute['system'] = isset($attribute['system']) ? $attribute['system'] : true;
85: $attribute['visible'] = isset($attribute['visible']) ? $attribute['visible'] : true;
86: if ($attribute['system'] != true || $attribute['visible'] != false) {
87: $usedInForms = array(
88: 'customer_account_create',
89: 'customer_account_edit',
90: 'checkout_register',
91: );
92: if (!empty($attribute['adminhtml_only'])) {
93: $usedInForms = array('adminhtml_customer');
94: } else {
95: $usedInForms[] = 'adminhtml_customer';
96: }
97: if (!empty($attribute['admin_checkout'])) {
98: $usedInForms[] = 'adminhtml_checkout';
99: }
100: foreach ($usedInForms as $formCode) {
101: $data[] = array(
102: 'form_code' => $formCode,
103: 'attribute_id' => $attributeId
104: );
105: }
106: }
107: }
108:
109: $attributes = $entities['customer_address']['attributes'];
110: foreach ($attributes as $attributeCode => $attribute) {
111: $attributeId = $attributeIds[$customerAddress][$attributeCode];
112: $attribute['system'] = isset($attribute['system']) ? $attribute['system'] : true;
113: $attribute['visible'] = isset($attribute['visible']) ? $attribute['visible'] : true;
114: if (false === ($attribute['system'] == true && $attribute['visible'] == false)) {
115: $usedInForms = array(
116: 'adminhtml_customer_address',
117: 'customer_address_edit',
118: 'customer_register_address'
119: );
120: foreach ($usedInForms as $formCode) {
121: $data[] = array(
122: 'form_code' => $formCode,
123: 'attribute_id' => $attributeId
124: );
125: }
126: }
127: }
128:
129: if ($data) {
130: $this->getConnection()->insertMultiple($this->getTable('customer/form_attribute'), $data);
131: }
132: }
133:
134: /**
135: * Retreive default entities: customer, customer_address
136: *
137: * @return array
138: */
139: public function getDefaultEntities()
140: {
141: $entities = array(
142: 'customer' => array(
143: 'entity_model' => 'customer/customer',
144: 'attribute_model' => 'customer/attribute',
145: 'table' => 'customer/entity',
146: 'increment_model' => 'eav/entity_increment_numeric',
147: 'additional_attribute_table' => 'customer/eav_attribute',
148: 'entity_attribute_collection' => 'customer/attribute_collection',
149: 'attributes' => array(
150: 'website_id' => array(
151: 'type' => 'static',
152: 'label' => 'Associate to Website',
153: 'input' => 'select',
154: 'source' => 'customer/customer_attribute_source_website',
155: 'backend' => 'customer/customer_attribute_backend_website',
156: 'sort_order' => 10,
157: 'position' => 10,
158: 'adminhtml_only' => 1,
159: ),
160: 'store_id' => array(
161: 'type' => 'static',
162: 'label' => 'Create In',
163: 'input' => 'select',
164: 'source' => 'customer/customer_attribute_source_store',
165: 'backend' => 'customer/customer_attribute_backend_store',
166: 'sort_order' => 20,
167: 'visible' => false,
168: 'adminhtml_only' => 1,
169: ),
170: 'created_in' => array(
171: 'type' => 'varchar',
172: 'label' => 'Created From',
173: 'input' => 'text',
174: 'required' => false,
175: 'sort_order' => 20,
176: 'position' => 20,
177: 'adminhtml_only' => 1,
178: ),
179: 'prefix' => array(
180: 'type' => 'varchar',
181: 'label' => 'Prefix',
182: 'input' => 'text',
183: 'required' => false,
184: 'sort_order' => 30,
185: 'visible' => false,
186: 'system' => false,
187: 'position' => 30,
188: ),
189: 'firstname' => array(
190: 'type' => 'varchar',
191: 'label' => 'First Name',
192: 'input' => 'text',
193: 'sort_order' => 40,
194: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
195: 'position' => 40,
196: ),
197: 'middlename' => array(
198: 'type' => 'varchar',
199: 'label' => 'Middle Name/Initial',
200: 'input' => 'text',
201: 'required' => false,
202: 'sort_order' => 50,
203: 'visible' => false,
204: 'system' => false,
205: 'position' => 50,
206: ),
207: 'lastname' => array(
208: 'type' => 'varchar',
209: 'label' => 'Last Name',
210: 'input' => 'text',
211: 'sort_order' => 60,
212: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
213: 'position' => 60,
214: ),
215: 'suffix' => array(
216: 'type' => 'varchar',
217: 'label' => 'Suffix',
218: 'input' => 'text',
219: 'required' => false,
220: 'sort_order' => 70,
221: 'visible' => false,
222: 'system' => false,
223: 'position' => 70,
224: ),
225: 'email' => array(
226: 'type' => 'static',
227: 'label' => 'Email',
228: 'input' => 'text',
229: 'sort_order' => 80,
230: 'validate_rules' => 'a:1:{s:16:"input_validation";s:5:"email";}',
231: 'position' => 80,
232: 'admin_checkout' => 1
233: ),
234: 'group_id' => array(
235: 'type' => 'static',
236: 'label' => 'Group',
237: 'input' => 'select',
238: 'source' => 'customer/customer_attribute_source_group',
239: 'sort_order' => 25,
240: 'position' => 25,
241: 'adminhtml_only' => 1,
242: 'admin_checkout' => 1,
243: ),
244: 'dob' => array(
245: 'type' => 'datetime',
246: 'label' => 'Date Of Birth',
247: 'input' => 'date',
248: 'frontend' => 'eav/entity_attribute_frontend_datetime',
249: 'backend' => 'eav/entity_attribute_backend_datetime',
250: 'required' => false,
251: 'sort_order' => 90,
252: 'visible' => false,
253: 'system' => false,
254: 'input_filter' => 'date',
255: 'validate_rules' => 'a:1:{s:16:"input_validation";s:4:"date";}',
256: 'position' => 90,
257: 'admin_checkout' => 1,
258: ),
259: 'password_hash' => array(
260: 'type' => 'varchar',
261: 'input' => 'hidden',
262: 'backend' => 'customer/customer_attribute_backend_password',
263: 'required' => false,
264: 'sort_order' => 81,
265: 'visible' => false,
266: ),
267: 'default_billing' => array(
268: 'type' => 'int',
269: 'label' => 'Default Billing Address',
270: 'input' => 'text',
271: 'backend' => 'customer/customer_attribute_backend_billing',
272: 'required' => false,
273: 'sort_order' => 82,
274: 'visible' => false,
275: ),
276: 'default_shipping' => array(
277: 'type' => 'int',
278: 'label' => 'Default Shipping Address',
279: 'input' => 'text',
280: 'backend' => 'customer/customer_attribute_backend_shipping',
281: 'required' => false,
282: 'sort_order' => 83,
283: 'visible' => false,
284: ),
285: 'taxvat' => array(
286: 'type' => 'varchar',
287: 'label' => 'Tax/VAT Number',
288: 'input' => 'text',
289: 'required' => false,
290: 'sort_order' => 100,
291: 'visible' => false,
292: 'system' => false,
293: 'validate_rules' => 'a:1:{s:15:"max_text_length";i:255;}',
294: 'position' => 100,
295: 'admin_checkout' => 1,
296: ),
297: 'confirmation' => array(
298: 'type' => 'varchar',
299: 'label' => 'Is Confirmed',
300: 'input' => 'text',
301: 'required' => false,
302: 'sort_order' => 85,
303: 'visible' => false,
304: ),
305: 'created_at' => array(
306: 'type' => 'static',
307: 'label' => 'Created At',
308: 'input' => 'date',
309: 'required' => false,
310: 'sort_order' => 86,
311: 'visible' => false,
312: 'system' => false,
313: ),
314: 'gender' => array(
315: 'type' => 'int',
316: 'label' => 'Gender',
317: 'input' => 'select',
318: 'source' => 'eav/entity_attribute_source_table',
319: 'required' => false,
320: 'sort_order' => 110,
321: 'visible' => false,
322: 'system' => false,
323: 'validate_rules' => 'a:0:{}',
324: 'position' => 110,
325: 'admin_checkout' => 1,
326: 'option' => array('values' => array('Male', 'Female'))
327: ),
328: )
329: ),
330:
331: 'customer_address' => array(
332: 'entity_model' => 'customer/address',
333: 'attribute_model' => 'customer/attribute',
334: 'table' => 'customer/address_entity',
335: 'additional_attribute_table' => 'customer/eav_attribute',
336: 'entity_attribute_collection' => 'customer/address_attribute_collection',
337: 'attributes' => array(
338: 'prefix' => array(
339: 'type' => 'varchar',
340: 'label' => 'Prefix',
341: 'input' => 'text',
342: 'required' => false,
343: 'sort_order' => 10,
344: 'visible' => false,
345: 'system' => false,
346: 'position' => 10,
347: ),
348: 'firstname' => array(
349: 'type' => 'varchar',
350: 'label' => 'First Name',
351: 'input' => 'text',
352: 'sort_order' => 20,
353: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
354: 'position' => 20,
355: ),
356: 'middlename' => array(
357: 'type' => 'varchar',
358: 'label' => 'Middle Name/Initial',
359: 'input' => 'text',
360: 'required' => false,
361: 'sort_order' => 30,
362: 'visible' => false,
363: 'system' => false,
364: 'position' => 30,
365: ),
366: 'lastname' => array(
367: 'type' => 'varchar',
368: 'label' => 'Last Name',
369: 'input' => 'text',
370: 'sort_order' => 40,
371: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
372: 'position' => 40,
373: ),
374: 'suffix' => array(
375: 'type' => 'varchar',
376: 'label' => 'Suffix',
377: 'input' => 'text',
378: 'required' => false,
379: 'sort_order' => 50,
380: 'visible' => false,
381: 'system' => false,
382: 'position' => 50,
383: ),
384: 'company' => array(
385: 'type' => 'varchar',
386: 'label' => 'Company',
387: 'input' => 'text',
388: 'required' => false,
389: 'sort_order' => 60,
390: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
391: 'position' => 60,
392: ),
393: 'street' => array(
394: 'type' => 'text',
395: 'label' => 'Street Address',
396: 'input' => 'multiline',
397: 'backend' => 'customer/entity_address_attribute_backend_street',
398: 'sort_order' => 70,
399: 'multiline_count' => 2,
400: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
401: 'position' => 70,
402: ),
403: 'city' => array(
404: 'type' => 'varchar',
405: 'label' => 'City',
406: 'input' => 'text',
407: 'sort_order' => 80,
408: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
409: 'position' => 80,
410: ),
411: 'country_id' => array(
412: 'type' => 'varchar',
413: 'label' => 'Country',
414: 'input' => 'select',
415: 'source' => 'customer/entity_address_attribute_source_country',
416: 'sort_order' => 90,
417: 'position' => 90,
418: ),
419: 'region' => array(
420: 'type' => 'varchar',
421: 'label' => 'State/Province',
422: 'input' => 'text',
423: 'backend' => 'customer/entity_address_attribute_backend_region',
424: 'required' => false,
425: 'sort_order' => 100,
426: 'position' => 100,
427: ),
428: 'region_id' => array(
429: 'type' => 'int',
430: 'label' => 'State/Province',
431: 'input' => 'hidden',
432: 'source' => 'customer/entity_address_attribute_source_region',
433: 'required' => false,
434: 'sort_order' => 100,
435: 'position' => 100,
436: ),
437: 'postcode' => array(
438: 'type' => 'varchar',
439: 'label' => 'Zip/Postal Code',
440: 'input' => 'text',
441: 'sort_order' => 110,
442: 'validate_rules' => 'a:0:{}',
443: 'data' => 'customer/attribute_data_postcode',
444: 'position' => 110,
445: ),
446: 'telephone' => array(
447: 'type' => 'varchar',
448: 'label' => 'Telephone',
449: 'input' => 'text',
450: 'sort_order' => 120,
451: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
452: 'position' => 120,
453: ),
454: 'fax' => array(
455: 'type' => 'varchar',
456: 'label' => 'Fax',
457: 'input' => 'text',
458: 'required' => false,
459: 'sort_order' => 130,
460: 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
461: 'position' => 130,
462: ),
463: )
464: )
465: );
466: return $entities;
467: }
468: }
469: