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 sharing config model
29: *
30: * @category Mage
31: * @package Mage_Customer
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Customer_Model_Config_Share extends Mage_Core_Model_Config_Data
35: {
36: /**
37: * Xml config path to customers sharing scope value
38: *
39: */
40: const XML_PATH_CUSTOMER_ACCOUNT_SHARE = 'customer/account_share/scope';
41:
42: /**
43: * Possible customer sharing scopes
44: *
45: */
46: const SHARE_GLOBAL = 0;
47: const SHARE_WEBSITE = 1;
48:
49: /**
50: * Check whether current customers sharing scope is global
51: *
52: * @return bool
53: */
54: public function isGlobalScope()
55: {
56: return !$this->isWebsiteScope();
57: }
58:
59: /**
60: * Check whether current customers sharing scope is website
61: *
62: * @return bool
63: */
64: public function isWebsiteScope()
65: {
66: return Mage::getStoreConfig(self::XML_PATH_CUSTOMER_ACCOUNT_SHARE) == self::SHARE_WEBSITE;
67: }
68:
69: /**
70: * Get possible sharing configuration options
71: *
72: * @return array
73: */
74: public function toOptionArray()
75: {
76: return array(
77: self::SHARE_GLOBAL => Mage::helper('customer')->__('Global'),
78: self::SHARE_WEBSITE => Mage::helper('customer')->__('Per Website'),
79: );
80: }
81:
82: /**
83: * Check for email dublicates before saving customers sharing options
84: *
85: * @return Mage_Customer_Model_Config_Share
86: * @throws Mage_Core_Exception
87: */
88: public function _beforeSave()
89: {
90: $value = $this->getValue();
91: if ($value == self::SHARE_GLOBAL) {
92: if (Mage::getResourceSingleton('customer/customer')->findEmailDuplicates()) {
93: Mage::throwException(
94: Mage::helper('customer')->__('Cannot share customer accounts globally because some customer accounts with the same emails exist on multiple websites and cannot be merged.')
95: );
96: }
97: }
98: return $this;
99: }
100: }
101: