-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controller to get the mailchimp list via ajax
- Loading branch information
1 parent
791a1d4
commit 6af85a6
Showing
1 changed file
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* mc-magento2 Magento Component | ||
* | ||
* @category Ebizmarts | ||
* @package mc-magento2 | ||
* @author Ebizmarts Team <info@ebizmarts.com> | ||
* @copyright Ebizmarts (http://ebizmarts.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
* @date: 4/20/17 3:20 PM | ||
* @file: Get.php | ||
*/ | ||
namespace Ebizmarts\MailChimp\Controller\Adminhtml\Lists; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\Controller\ResultFactory; | ||
|
||
class Get extends Action | ||
{ | ||
/** | ||
* @var \Ebizmarts\MailChimp\Helper\Data | ||
*/ | ||
protected $_helper; | ||
/** | ||
* @var ResultFactory | ||
*/ | ||
protected $_resultFactory; | ||
|
||
/** | ||
* Get constructor. | ||
* @param Context $context | ||
* @param ResultFactory $resultFactory | ||
* @param \Ebizmarts\MailChimp\Helper\Data $helper | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
ResultFactory $resultFactory, | ||
\Ebizmarts\MailChimp\Helper\Data $helper | ||
) | ||
{ | ||
parent::__construct($context); | ||
$this->_resultFactory = $resultFactory; | ||
$this->_helper = $helper; | ||
|
||
} | ||
public function execute() | ||
{ | ||
$param = $this->getRequest()->getParams(); | ||
$apiKey = $param['apikey']; | ||
$api = $this->_helper->getApiByApiKey($apiKey); | ||
$lists = $api->lists->getLists(); | ||
$result = []; | ||
foreach($lists['lists'] as $list) { | ||
$result[] = ['id'=> $list['id'], 'name'=> $list['name']]; | ||
} | ||
$resultJson = $this->_resultFactory->create(ResultFactory::TYPE_JSON); | ||
$resultJson->setData($result); | ||
return $resultJson; | ||
} | ||
} |