Skip to content

Commit

Permalink
Merge pull request #1 from adamkarnowka/master
Browse files Browse the repository at this point in the history
Version 2.1.7
  • Loading branch information
Leone authored Jun 16, 2021
2 parents b403466 + 80208c9 commit 8cf7e4f
Show file tree
Hide file tree
Showing 28 changed files with 2,426 additions and 3,127 deletions.
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

291 changes: 82 additions & 209 deletions Controller/Adminhtml/index/Ajax.php

Large diffs are not rendered by default.

138 changes: 83 additions & 55 deletions Controller/Adminhtml/index/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function execute()
}
try {
$model = $this->sibObject();

if (isset($post['submitUpdate']) && !empty($post['submitUpdate'])) {
$this->apiKeyPostProcessConfiguration();
}
Expand Down Expand Up @@ -154,41 +155,32 @@ public function apiKeyPostProcessConfiguration()
$scopeInerface = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
if ($status == 1) {
$apikey = trim($post['apikey']);
$rowList = $model->checkApikey($apikey);

if (isset($rowList) && $rowList['code'] == 'success' && $rowList['message'] == 'Data retrieved') {
//If a user enters a new API key, we remove all records that belongs to the
//old API key.
$oldApiKey = trim($model->_getValueDefault->getValue('sendinblue/api_key', $scopeInerface));

// Old key
if ($apikey != $oldApiKey) {
// Reset data for old key
$model->resetDataBaseValue();
$model->resetSmtpDetail();
}

if (isset($apikey)) {
$model->_resourceConfig->saveConfig('sendinblue/api_key', $apikey, $model->_scopeTypeDefault, $model->_storeId);
}

if (isset($status)) {
$model->_resourceConfig->saveConfig('sendinblue/api_key_status', $status, $model->_scopeTypeDefault, $model->_storeId);
}

$sendinListdata = $model->_getValueDefault->getValue('sendinblue/selected_list_data', $scopeInerface);
$sendinFirstrequest = $model->_getValueDefault->getValue('sendinblue/first_request', $scopeInerface);
//We remove all records that belongs to the old API
$oldApiKey = trim($model->_getValueDefault->getValue('sendinblue/api_key_v3', $scopeInerface));
if ($apikey != $oldApiKey) {
$model->resetDataBaseValue();
$model->resetSmtpDetail();
}
$model->_resourceConfig->saveConfig('sendinblue/api_key_v3', $apikey, $model->_scopeTypeDefault, $model->_storeId);
$model->_resourceConfig->saveConfig('sendinblue/api_key_status', $status, $model->_scopeTypeDefault, $model->_storeId);
$sendinListdata = $model->_getValueDefault->getValue('sendinblue/selected_list_data', $scopeInerface);
$sendinFirstrequest = $model->_getValueDefault->getValue('sendinblue/first_request', $scopeInerface);

if (empty($sendinListdata) && empty($sendinFirstrequest)) {
$model->_resourceConfig->saveConfig('sendinblue/first_request', 1, $model->_scopeTypeDefault, $model->_storeId);
$model->_resourceConfig->saveConfig('sendinblue/subscribe_setting', 1, $model->_scopeTypeDefault, $model->_storeId);
$model->_resourceConfig->saveConfig('sendinblue/notify_cron_executed', 0, $model->_scopeTypeDefault, $model->_storeId);
$model->_resourceConfig->saveConfig('sendinblue/syncronize', 1, $model->_scopeTypeDefault, $model->_storeId);
if (empty($sendinListdata) && empty($sendinFirstrequest)) {
$model->_resourceConfig->saveConfig('sendinblue/first_request', 1, $model->_scopeTypeDefault, $model->_storeId);
$model->_resourceConfig->saveConfig('sendinblue/subscribe_setting', 1, $model->_scopeTypeDefault, $model->_storeId);
$model->_resourceConfig->saveConfig('sendinblue/notify_cron_executed', 0, $model->_scopeTypeDefault, $model->_storeId);
$model->_resourceConfig->saveConfig('sendinblue/syncronize', 1, $model->_scopeTypeDefault, $model->_storeId);
}

$model->createFolderName($apikey);
}
$response = $model->checkApikey($apikey);

if ($response) {
$model->createAttributesName($apikey, $response);
$model->createFolderName($apikey);
$model->processInstallationInfo("login", $apikey);
$this->messageManager->addSuccess(
__('Sendiblue configuration setting Successfully updated')
__('Sendinblue configuration setting Successfully updated')
);
$this->_redirect('sendinblue/sib/index');
return;
Expand All @@ -203,7 +195,18 @@ public function apiKeyPostProcessConfiguration()
return;
}
}
else
{
$apikey = trim($model->_getValueDefault->getValue('sendinblue/api_key_v3', $scopeInerface));
$model->processInstallationInfo("logout", $apikey);
$model->_resourceConfig->saveConfig('sendinblue/api_key_status', 0, $model->_scopeTypeDefault, $model->_storeId);
$model->resetDataBaseValue();
$this->_redirect('sendinblue/sib/index');
return;
}
} catch (\Exception $e) {
$model->_resourceConfig->saveConfig('sendinblue/api_key_status', 0, $model->_scopeTypeDefault, $model->_storeId);
$model->resetDataBaseValue();
$this->messageManager->addError(
__('API key is invalid.')
);
Expand Down Expand Up @@ -239,57 +242,82 @@ public function saveTemplateValue()
$doubleoptinRedirectUrl = !empty($post['doubleoptin_redirect_url']) ? $post['doubleoptin_redirect_url'] : '';
$finalConfirmEmail = !empty($post['final_confirm_email']) ? $post['final_confirm_email'] : '';
$finalTempId = !empty($post['template_final']) ? $post['template_final'] : '';
$shopApiKey = $model->getDbData('api_key');
$manageSubscribe = !empty($post['managesubscribe']) ? $post['managesubscribe'] : 0;
$shopApiKeyStatus = $model->getDbData('api_key_status');

$model->updateDbData('doubleoptin_template_id', $doubleOptinTempId);
$model->updateDbData('template_id', $valueTemplateId);
$model->updateDbData('optin_url_check', $optinRedirectUrlCheck);
$model->updateDbData('doubleoptin_redirect', $doubleoptinRedirectUrl);
$model->updateDbData('final_confirm_email', $finalConfirmEmail);
$model->updateDbData('subscribe_setting', $manageSubscribe);
if (!empty($finalTempId)) {
$model->updateDbData('final_template_id', $finalTempId);
}
$model->updateSender();
if (!empty($subscribeConfirmType)) {
$model->updateDbData('confirm_type', $subscribeConfirmType);
if ($subscribeConfirmType == 'doubleoptin') {
$resOptin = $model->checkFolderListDoubleoptin($shopApiKey);
if ($subscribeConfirmType == 'doubleoptin') {
$resOptin = $model->checkFolderListDoubleoptin();
if (!empty($resOptin['optin_id'])) {
$model->updateDbData('optin_list_id', $resOptin['optin_id']);
}
$mailin = $model->createObjSibClient();
// add attribute.
$isEmpty = false;
$attributeRes = $mailin->getAttributes();

if ($resOptin === false) {
$mailin = $model->createObjMailin($shopApiKey);
if (!empty($shopApiKey)) {
$data = [];
$data = ["name"=> "FORM"];
$folderRes = $mailin->createFolder($data);
$folderId = $folderRes['data']['id'];
if ( isset($attributeRes["attributes"]) ) {
foreach ($attributeRes["attributes"] as $key => $value) {
if($value["category"] == "category" && 'DOUBLE_OPT-IN' == $value['name'] && ! empty( $value['enumeration'] ) ) {
$isEmpty = true;
}
}

if ( ! $isEmpty ) {
$data = [
'type' => 'category',
'enumeration' => [
[
'value' => 1,
'label' => 'Yes'
],
[
'value' => 2,
'label' => 'No'
],
]
];
$mailin->createAttribute('category', 'DOUBLE_OPT-IN', $data);
}
}

if (!empty($shopApiKey)) {
if ( $resOptin === false && !empty($shopApiKeyStatus) ) {
$data = [];
$data = ["name"=> "FORM"];
$folderRes = $mailin->createFolder($data);
if (201 === $mailin->getLastResponseCode()) {
$data = [];
$data = [
"list_name" => 'Temp - DOUBLE OPTIN',
"list_parent" => $folderId
"name" => 'Temp - DOUBLE OPTIN',
"folderId" => $folderRes["id"]
];
$listResp = $mailin->createList($data);
$listId = $listResp['data']['id'];
$model->updateDbData('optin_list_id', $listId);
if (201 === $mailin->getLastResponseCode()) {
$listId = $listResp['id'];
$model->updateDbData('optin_list_id', $listId);
}
}
}
}
}
$displayList = $post['display_list'];
if (!empty($displayList)) {
if ($model->getDbData('subscribe_setting') == 1) {
$listValue = implode('|', $displayList);
$model->updateDbData('selected_list_data', $listValue);
} else {
$model->updateDbData('subscribe_setting', 0);
}
}
$this->messageManager->addSuccess(__('Sendiblue configuration setting Successfully updated'));

$this->messageManager->addSuccess(__('Sendinblue configuration setting Successfully updated'));
$this->_redirect('sendinblue/sib/index');
return true;
}
Expand All @@ -307,7 +335,7 @@ public function saveNotifyValue()
$model->updateDbData('notify_value', $post['notify_value']);
$model->updateDbData('notify_email_send', 0);
}
$this->messageManager->addSuccess(__('Sendiblue configuration setting Successfully updated'));
$this->messageManager->addSuccess(__('Sendinblue configuration setting Successfully updated'));
$this->_redirect('sendinblue/sib/index');
return true;
}
Expand All @@ -324,7 +352,7 @@ public function saveOrderSms()
$model->updateDbData('sender_order', $post['sender_order']);
$model->updateDbData('sender_order_message', $post['sender_order_message']);
}
$this->messageManager->addSuccess(__('Sendiblue configuration setting Successfully updated'));
$this->messageManager->addSuccess(__('Sendinblue configuration setting Successfully updated'));
$this->_redirect('sendinblue/sib/index');
return true;
}
Expand All @@ -341,7 +369,7 @@ public function saveShippedSms()
$model->updateDbData('sender_shipment', $post['sender_shipment']);
$model->updateDbData('sender_shipment_message', $post['sender_shipment_message']);
}
$this->messageManager->addSuccess(__('Sendiblue configuration setting Successfully updated'));
$this->messageManager->addSuccess(__('Sendinblue configuration setting Successfully updated'));
$this->_redirect('sendinblue/sib/index');
return true;
}
Expand Down
23 changes: 12 additions & 11 deletions Controller/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,25 @@ public function dubleoptinProcess($userEmail)
{
$nlStatus = $this->_model->checkNlStatus($userEmail);
if (!empty($userEmail) && $nlStatus = 1) {
$apiKey = $this->_model->getDbData('api_key');
$optinListId = $this->_model->getDbData('optin_list_id');
$listId = $this->_model->getDbData('selected_list_data');

$mailin = $this->_model->createObjMailin($apiKey);
$mailin = $this->_model->createObjSibClient();

$data = array( "email" => $userEmail,
"attributes" => array("DOUBLE_OPT-IN"=>1),
"blacklisted" => 0,
"listid" => array($listId),
"listid_unlink" => array($optinListId),
"blacklisted_sms" => 0
$data = array(
"attributes" => array("DOUBLE_OPT-IN"=>'1'),
"emailBlacklisted" => false,
"listIds" => array_map('intval', explode('|', $listId)),
"unlinkListIds" => array_map('intval', explode('|', $optinListId)),
"smsBlacklisted" => false
);
$mailin->createUpdateUser($data);

$mailin->updateUser($userEmail, $data);

$confirmEmail = $this->_model->getDbData('final_confirm_email');
if ($confirmEmail === 'yes') {
$finalId = $this->_model->getDbData('final_template_id');
$this->_model->sendOptinConfirmMailResponce($userEmail, $finalId, $apiKey);
$this->_model->sendOptinConfirmMailResponce($userEmail, $finalId);
}
}
$doubleoptinRedirect = $this->_model->getDbData('doubleoptin_redirect');
Expand All @@ -67,7 +68,7 @@ public function dubleoptinProcess($userEmail)
header("Location: ".$doubleoptinRedirect);
ob_flush_end();
} else {
$shopName = $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
$shopName = $this->_model->_getValueDefault->getValue('web/unsecure/base_url', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
header("Location: ".$shopName);
ob_flush_end();
}
Expand Down
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

Loading

0 comments on commit 8cf7e4f

Please sign in to comment.