Skip to content
7 changes: 7 additions & 0 deletions Block/Adminhtml/System/Config/Fieldset/Hint.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,11 @@ public function getScopeId()
}
return $scopeId;
}
public function getRegisterToken()
{
$scopeId = $this->getScopeId();
$scope = $this->getScope();
$token = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_STATISTICS_TOKEN, $scopeId, $scope);
return $token;
}
}
18 changes: 14 additions & 4 deletions Controller/Adminhtml/Ecommerce/Getaccountdetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use \Ebizmarts\MailChimp\Helper\Data as MailChimpHelper;

class Getaccountdetails extends Action
{
Expand All @@ -33,15 +34,14 @@ class Getaccountdetails extends Action
protected $_storeManager;

/**
* Getaccountdetails constructor.
* @param Context $context
* @param \Magento\Store\Model\StoreManager $storeManager
* @param \Ebizmarts\MailChimp\Helper\Data $helper
* @param MailChimpHelper $helper
*/
public function __construct(
Context $context,
\Magento\Store\Model\StoreManager $storeManager,
\Ebizmarts\MailChimp\Helper\Data $helper
MailChimpHelper $helper
) {

parent::__construct($context);
Expand All @@ -55,6 +55,8 @@ public function execute()
$apiKey = $param['apikey'];
$store = $param['store'];
$encrypt = $param['encrypt'];
$scope = $param['scope'];
$scopeId = $param['scopeId'];
try {
if ($encrypt == 3) {
$api = $this->_helper->getApi($this->_storeManager->getStore()->getId());
Expand All @@ -64,14 +66,22 @@ public function execute()
$apiInfo = $api->root->info();
$options = [];
if (isset($apiInfo['account_name'])) {
$options['username'] = ['label' => __('User name:'), 'value' => $apiInfo['account_name']];
$options['account_name'] = ['code' => 'account_name','html' => __('Account Name'),'value' => $apiInfo['account_name']];
$options['email'] = ['code' => 'email','html' => __('email'),'value' => $apiInfo['email']];
$options['first_name'] = ['code'=> 'first_name','html' => __('First Name'),'value' => $apiInfo['first_name']];
$options['last_name'] = ['code'=>'last_name','html' => __('Last Name'),'value' => $apiInfo['last_name']];
$options['pricing_plan_type'] = ['code'=>'pricing_plan_type','html' => __('Pricing Plan'),'value' => $apiInfo['pricing_plan_type']];
$options['username'] = ['code'=>'username','html' => __('User name:'), 'value' => $apiInfo['account_name']];
$options['account_id'] = ['code'=> 'account_id','html' => __('Account id:'), 'value' => $apiInfo['account_id']];
$options['total_subscribers'] = ['label' => __('Total Account Subscribers:'), 'value' => $apiInfo['total_subscribers']];
$token = $this->_helper->getConfigValue(MailChimpHelper::XML_STATISTICS_TOKEN, $scopeId, $scope);
if ($store != -1) {
$storeData = $api->ecommerce->stores->get($store);
$options['list_id'] = $storeData['list_id'];
$list = $api->lists->getLists($storeData['list_id']);
$options['list_name'] = $list['name'];
$options['total_list_subscribers'] = ['label' => __('Total List Subscribers:'), 'value' => $list['stats']['member_count']];
$options['token'] = ['label' => __('Registration ID:'), 'value' => $token];
$options['subtitle'] = ['label' => __('Ecommerce Data uploaded to MailChimp:'), 'value' => ''];
$totalCustomers = $api->ecommerce->customers->getAll($store, 'total_items');
$options['total_customers'] = ['label' => __('Total customers:'), 'value' => $totalCustomers['total_items']];
Expand Down
98 changes: 98 additions & 0 deletions Controller/Adminhtml/Ecommerce/Register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace Ebizmarts\MailChimp\Controller\Adminhtml\Ecommerce;

use Magento\Backend\App\Action;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Store\Model\StoreManager;
use Magento\Backend\App\Action\Context;
use Magento\Config\Model\ResourceModel\Config;
use Ebizmarts\MailChimp\Helper\Data as Helper;
use Ebizmarts\MailChimp\Helper\Http as MailChimpHttp;

class Register extends Action
{
/**
* @var ResultFactory
*/
protected $_resultFactory;
/**
* @var Helper
*/
protected $_helper;
/**
* @var MailChimpHttp
*/
protected $_http;
/**
* @var Config
*/
protected $_config;
/**
* @var StoreManager
*/
protected $_storeManager;

/**
* @param Context $context
* @param Helper $helper
* @param MailChimpHttp $http
* @param Config $config
* @param StoreManager $storeManager
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(
Context $context,
Helper $helper,
MailChimpHttp $http,
Config $config,
StoreManager $storeManager
)
{
parent::__construct($context);
$this->_resultFactory = $context->getResultFactory();
$this->_helper = $helper;
$this->_http = $http;
$this->_http->setUrl($helper->getConfigValue(Helper::XML_REGISTER_URL).'/register');
$this->_config = $config;
$this->_storeManager = $storeManager;
}
public function execute()
{
$params = $this->getRequest()->getParams();
$scope = $params['scope'];
$scopeId = $params['scopeId'];
$registerData = [];
$error = true;
$token = $this->_helper->getConfigValue(Helper::XML_STATISTICS_TOKEN,$scopeId, $scope);
foreach ($params['data'] as $index => $value) {
$registerData[$index] = $value['value'];
}
$registerData['store_url'] = stripslashes($this->_storeManager->getStore($scopeId)->getBaseUrl());
$registerDataJson = json_encode($registerData);
$resultJson = $this->_resultFactory->create(ResultFactory::TYPE_JSON);
if ($token) {
$ret = $this->_http->patch($token, $registerDataJson);
} else {
$ret = $this->_http->post($registerDataJson);
}
$ret = json_decode($ret,true);
if ( !$ret['error']) {
$error = false;
$token = $ret['token'];
$this->_helper->saveConfigValue(Helper::XML_STATISTICS_TOKEN, $token, $scopeId, $scope);
}
$resultJson->setData(['error' => $error, 'token' => $token]);
return $resultJson;

}
/**
* @return mixed
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Ebizmarts_MailChimp::config_mailchimp');
}

}
67 changes: 67 additions & 0 deletions Controller/Adminhtml/Ecommerce/SyncLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Ebizmarts\MailChimp\Controller\Adminhtml\Ecommerce;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Ebizmarts\MailChimp\Helper\Data as MailchimpHelper;
use Ebizmarts\MailChimp\Helper\Http as MailChimpHttp;


class SyncLog extends Action
{
/**
* @var ResultFactory
*/
protected $_resultFactory;
/**
* @var MailChimpHttp
*/
protected $_http;
/**
* @var MailchimpHelper
*/
protected $_helper;
public function __construct(
Context $context,
MailchimpHelper $mailchimpHelper,
MailchimpHttp $mailchimpHttp
)
{
parent::__construct($context);
$this->_resultFactory = $context->getResultFactory();
$this->_helper = $mailchimpHelper;
$this->_http = $mailchimpHttp;
$this->_url = $mailchimpHelper->getConfigValue(MailchimpHelper::XML_REGISTER_URL);
}
public function execute()
{
$error = 0;
$message = '';
$params = $this->getRequest()->getParams();
$scope = $params['scope'];
$scopeId = $params['scopeId'];
$onoff = $params['onoff'];
$token = $this->_helper->getConfigValue(MailchimpHelper::XML_STATISTICS_TOKEN, $scopeId, $scope);
if ($token) {
if ($onoff) {
$this->_http->setUrl($this->_url . '/switchon');
} else {
$this->_http->setUrl($this->_url . '/switchoff');
}
$response = $this->_http->put($token, null);
$res = json_decode($response, true);
if (key_exists('error',$res)) {
$error = $res['error'];
$message = $res['message'];
}
} else {
$error = 1;
$message = 'First register your copy';
}
$resultJson = $this->_resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData(['error' => $error, 'message' => $message]);
return $resultJson;
}
}
Loading