Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Share.php
Go to the documentation of this file.
1 <?php
7 
13 class Share extends \Magento\Framework\App\Config\Value implements \Magento\Framework\Option\ArrayInterface
14 {
19  const XML_PATH_CUSTOMER_ACCOUNT_SHARE = 'customer/account_share/scope';
20 
25  const SHARE_GLOBAL = 0;
26 
27  const SHARE_WEBSITE = 1;
28 
32  protected $_customerResource;
33 
37  protected $_storeManager;
38 
52  public function __construct(
53  \Magento\Framework\Model\Context $context,
54  \Magento\Framework\Registry $registry,
56  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
58  \Magento\Customer\Model\ResourceModel\Customer $customerResource,
59  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
60  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
61  array $data = []
62  ) {
63  $this->_storeManager = $storeManager;
64  $this->_customerResource = $customerResource;
65  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
66  }
67 
73  public function isGlobalScope()
74  {
75  return !$this->isWebsiteScope();
76  }
77 
83  public function isWebsiteScope()
84  {
85  return $this->_config->getValue(
86  self::XML_PATH_CUSTOMER_ACCOUNT_SHARE,
87  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
89  }
90 
96  public function toOptionArray()
97  {
98  return [self::SHARE_GLOBAL => __('Global'), self::SHARE_WEBSITE => __('Per Website')];
99  }
100 
107  public function beforeSave()
108  {
109  $value = $this->getValue();
110  if ($value == self::SHARE_GLOBAL) {
111  if ($this->_customerResource->findEmailDuplicates()) {
112  //@codingStandardsIgnoreStart
113  throw new \Magento\Framework\Exception\LocalizedException(
114  __(
115  'We can\'t share customer accounts globally when the accounts share identical email addresses on more than one website.'
116  )
117  );
118  //@codingStandardsIgnoreEnd
119  }
120  }
121  return $this;
122  }
123 
131  {
132  $ids = [];
133  if ($this->isWebsiteScope()) {
134  $ids[] = $websiteId;
135  } else {
136  foreach ($this->_storeManager->getWebsites() as $website) {
137  $ids[] = $website->getId();
138  }
139  }
140  return $ids;
141  }
142 }
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Model\ResourceModel\Customer $customerResource, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Share.php:52
$config
Definition: fraud_order.php:17
$storeManager
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
$value
Definition: gender.phtml:16