-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config setting for user ID source
- Loading branch information
Showing
13 changed files
with
327 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Copyright 2016-2017 Henrik Hedelund | ||
* | ||
* This file is part of Henhed_Piwik. | ||
* | ||
* Henhed_Piwik is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Henhed_Piwik is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Henhed_Piwik. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Henhed\Piwik\Model\Config\Source\UserId; | ||
|
||
/** | ||
* User ID provider config source model | ||
* | ||
*/ | ||
class Provider implements \Magento\Framework\Option\ArrayInterface | ||
{ | ||
|
||
/** | ||
* User ID provider pool | ||
* | ||
* @var \Henhed\Piwik\UserId\Provider\Pool $_pool | ||
*/ | ||
protected $_pool; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \Henhed\Piwik\UserId\Provider\Pool $pool | ||
*/ | ||
public function __construct(\Henhed\Piwik\UserId\Provider\Pool $pool) | ||
{ | ||
$this->_pool = $pool; | ||
} | ||
|
||
/** | ||
* Return array of user ID providers as value-label pairs | ||
* | ||
* @return array | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
$options = [['value' => '', 'label' => __('No')]]; | ||
foreach ($this->_pool->getAllProviders() as $code => $provider) { | ||
$options[] = [ | ||
'value' => $code, | ||
'label' => sprintf('%s (%s)', __('Yes'), $provider->getTitle()) | ||
]; | ||
} | ||
return $options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Copyright 2016-2017 Henrik Hedelund | ||
* | ||
* This file is part of Henhed_Piwik. | ||
* | ||
* Henhed_Piwik is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Henhed_Piwik is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Henhed_Piwik. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Henhed\Piwik\UserId\Provider; | ||
|
||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
|
||
/** | ||
* Customer email provider | ||
* | ||
*/ | ||
class EmailProvider implements ProviderInterface | ||
{ | ||
|
||
/** | ||
* Customer repository | ||
* | ||
* @var CustomerRepositoryInterface $_customerRepository | ||
*/ | ||
protected $_customerRepository; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param CustomerRepositoryInterface $customerRepository | ||
*/ | ||
public function __construct(CustomerRepositoryInterface $customerRepository) | ||
{ | ||
$this->_customerRepository = $customerRepository; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getUserId($customerId) | ||
{ | ||
try { | ||
return $this->_customerRepository->getById($customerId)->getEmail(); | ||
} catch (\Exception $e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getTitle() | ||
{ | ||
return __('Customer E-mail'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.