Skip to content

Commit

Permalink
controller to get the mailchimp list via ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Apr 21, 2017
1 parent 791a1d4 commit 6af85a6
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Controller/Adminhtml/Lists/Get.php
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;
}
}

0 comments on commit 6af85a6

Please sign in to comment.