Skip to content

Commit

Permalink
add the getallapikeys, used for retrieve all the possible apikeys use…
Browse files Browse the repository at this point in the history
…d in the magento installation #240
  • Loading branch information
gonzaloebiz committed Mar 15, 2018
1 parent dd661c4 commit 67e3dd4
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions Model/Config/Source/ApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,42 @@

class ApiKey implements \Magento\Framework\Option\ArrayInterface
{
private $options = null;
protected $options = null;
/**
* MonkeyStore constructor.
* @var \Magento\Store\Model\StoreManager
*/
protected $storeManager;
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
protected $helper;

/**
* ApiKey constructor.
* @param \Magento\Store\Model\StoreManager $storeManager
* @param \Ebizmarts\MailChimp\Helper\Data $helper
* @param \Magento\Framework\App\RequestInterface $request
*/
public function __construct(
\Ebizmarts\MailChimp\Helper\Data $helper
\Magento\Store\Model\StoreManager $storeManager,
\Ebizmarts\MailChimp\Helper\Data $helper,
\Magento\Framework\App\RequestInterface $request
) {

$apiKeys = $helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_APIKEY_LIST);
$this->storeManager = $storeManager;
$this->helper = $helper;
$storeId = (int) $request->getParam("store", 0);
if($request->getParam('website',0)) {
$scope = 'websites';
$storeId = $request->getParam('website',0);
}
elseif($request->getParam('store',0)) {
$scope = 'stores';
$storeId = $request->getParam('store',0);
}
else {
$scope = 'default';
}
$apiKeys = $helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_APIKEY_LIST, $storeId, $scope);
if ($apiKeys) {
$this->options = explode("\n", $apiKeys);
} else {
Expand All @@ -43,4 +69,17 @@ public function toOptionArray()
}
return $rc;
}
public function getAllApiKeys() {
$apiKeys = [];
foreach ($this->storeManager->getStores() as $storeId => $val) {
$apiKey = $this->helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_APIKEY_LIST, $storeId);
$tempApiKeys = explode("\n",$apiKey);
foreach ($tempApiKeys as $tempAkiKey) {
if(!in_array($tempAkiKey,$apiKeys)) {
$apiKeys[] = $tempAkiKey;
}
}
}
$this->options = $apiKeys;
}
}

0 comments on commit 67e3dd4

Please sign in to comment.