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: * Customer group model
29: *
30: * @method Mage_Customer_Model_Resource_Group _getResource()
31: * @method Mage_Customer_Model_Resource_Group getResource()
32: * @method string getCustomerGroupCode()
33: * @method Mage_Customer_Model_Group setCustomerGroupCode(string $value)
34: * @method Mage_Customer_Model_Group setTaxClassId(int $value)
35: *
36: * @category Mage
37: * @package Mage_Customer
38: * @author Magento Core Team <core@magentocommerce.com>
39: */
40: class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract
41: {
42: /**
43: * Xml config path for create account default group
44: */
45: const XML_PATH_DEFAULT_ID = 'customer/create_account/default_group';
46:
47: const NOT_LOGGED_IN_ID = 0;
48: const CUST_GROUP_ALL = 32000;
49:
50: const ENTITY = 'customer_group';
51:
52: const GROUP_CODE_MAX_LENGTH = 32;
53:
54: /**
55: * Prefix of model events names
56: *
57: * @var string
58: */
59: protected $_eventPrefix = 'customer_group';
60:
61: /**
62: * Parameter name in event
63: *
64: * In observe method you can use $observer->getEvent()->getObject() in this case
65: *
66: * @var string
67: */
68: protected $_eventObject = 'object';
69:
70: protected static $_taxClassIds = array();
71:
72: protected function _construct()
73: {
74: $this->_init('customer/group');
75: }
76:
77: /**
78: * Alias for setCustomerGroupCode
79: *
80: * @param string $value
81: */
82: public function setCode($value)
83: {
84: return $this->setCustomerGroupCode($value);
85: }
86:
87: /**
88: * Alias for getCustomerGroupCode
89: *
90: * @return string
91: */
92: public function getCode()
93: {
94: return $this->getCustomerGroupCode();
95: }
96:
97: public function getTaxClassId($groupId = null)
98: {
99: if (!is_null($groupId)) {
100: if (empty(self::$_taxClassIds[$groupId])) {
101: $this->load($groupId);
102: self::$_taxClassIds[$groupId] = $this->getData('tax_class_id');
103: }
104: $this->setData('tax_class_id', self::$_taxClassIds[$groupId]);
105: }
106: return $this->getData('tax_class_id');
107: }
108:
109:
110: public function usesAsDefault()
111: {
112: $data = Mage::getConfig()->getStoresConfigByPath(self::XML_PATH_DEFAULT_ID);
113: if (in_array($this->getId(), $data)) {
114: return true;
115: }
116: return false;
117: }
118:
119: /**
120: * Processing data save after transaction commit
121: *
122: * @return Mage_Customer_Model_Group
123: */
124: public function afterCommitCallback()
125: {
126: parent::afterCommitCallback();
127: Mage::getSingleton('index/indexer')->processEntityAction(
128: $this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
129: );
130: return $this;
131: }
132:
133: /**
134: * Prepare data before save
135: *
136: * @return Mage_Core_Model_Abstract
137: */
138: protected function _beforeSave()
139: {
140: $this->_prepareData();
141: return parent::_beforeSave();
142: }
143:
144: /**
145: * Prepare customer group data
146: *
147: * @return Mage_Customer_Model_Group
148: */
149: protected function _prepareData()
150: {
151: $this->setCode(
152: substr($this->getCode(), 0, self::GROUP_CODE_MAX_LENGTH)
153: );
154: return $this;
155: }
156:
157: }
158: