Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified Controller/Adminhtml/index/Ajax.php
100755 → 100644
Empty file.
Empty file modified Controller/Adminhtml/index/Post.php
100755 → 100644
Empty file.
Empty file modified Controller/Adminhtml/index/Sync.php
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion Controller/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function dubleoptinProcess($userEmail)
$mailin = $this->_model->createObjMailin($apiKey);

$data = array( "email" => $userEmail,
"attributes" => array(),
"attributes" => array("DOUBLE_OPT-IN"=>1),
"blacklisted" => 0,
"listid" => array($listId),
"listid_unlink" => array($optinListId),
Expand Down
19 changes: 11 additions & 8 deletions Model/SendinblueSib.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ public function createNewList($response, $existList)
);
$listResp = $mailin->createList($data);
$this->_resourceConfig->saveConfig('sendinblue/selected_list_data', trim($listResp['data']['id']), $this->_scopeTypeDefault, $this->_storeId);
//list id

$this->sendAllMailIDToSendin($listResp['data']['id']);
}


Expand Down Expand Up @@ -400,15 +397,15 @@ public function checkFolderList()
public function sendAllMailIDToSendin($listId)
{
$emailValue = $this->getSubscribeCustomer();
$baseUrl = $this->_storeManagerInterface->getStore()->getBaseUrl();
$mediaUrl = $this->_storeManagerInterface->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$apiKey = !empty($this->apiKey) ? $this->apiKey : $this->getDbData('api_key');
if ($emailValue > 0 && !empty($apiKey)) {
$this->updateDbData('import_old_user_status', 1);
$userDataInformation = array();
$listIdVal = explode('|', $listId);
$mailinObj = $this->createObjMailin($apiKey);
$userDataInformation['key'] = $apiKey;
$userDataInformation['url'] = $baseUrl.'pub/media/sendinblue_csv/ImportSubUsersToSendinblue.csv';
$userDataInformation['url'] = $mediaUrl.'sendinblue_csv/ImportSubUsersToSendinblue.csv';
$userDataInformation['listids'] = $listIdVal; // $list;
$userDataInformation['notify_url'] = '';
$responseValue = $mailinObj->importUsers($userDataInformation);
Expand Down Expand Up @@ -813,9 +810,9 @@ public function importOrderhistory()
$userDataInformation = array();
$listIdVal = explode('|', $listId);
$mailinObj = $this->createObjMailin($apiKey);
$baseUrl = $this->_storeManagerInterface->getStore()->getBaseUrl();
$baseUrl = $this->_storeManagerInterface->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$userDataInformation['key'] = $apiKey;
$userDataInformation['url'] = $baseUrl.'pub/media/sendinblue_csv/ImportOldOrdersToSendinblue.csv';
$userDataInformation['url'] = $baseUrl.'sendinblue_csv/ImportOldOrdersToSendinblue.csv';
$userDataInformation['listids'] = $listIdVal; // $list;
$userDataInformation['notify_url'] = '';
$responseValue = $mailinObj->importUsers($userDataInformation);
Expand Down Expand Up @@ -1118,11 +1115,11 @@ public function subscribeByruntime($userEmail, $updateDataInSib)
$sendinConfirmType = $this->getDbData('confirm_type');
if ($sendinConfirmType === 'doubleoptin') {
$listId = $this->getDbData('optin_list_id');
$updateDataInSib['DOUBLE_OPT-IN'] = 2;
} else {
$listId = $this->getDbData('selected_list_data');
}


$apiKey = trim($this->getDbData('api_key'));
if (!empty($apiKey)) {
$mailin = $this->createObjMailin($apiKey);
Expand Down Expand Up @@ -1326,11 +1323,17 @@ public function sendWsTemplateMail($to)

$to = array($to => '');
$from = array($senderEmail, $senderName);
$searchValue = "({{\s*doubleoptin\s*}})";

$htmlContent = str_replace('{title}', $subject, $htmlContent);
$htmlContent = str_replace('https://[DOUBLEOPTIN]', '{subscribe_url}', $htmlContent);
$htmlContent = str_replace('http://[DOUBLEOPTIN]', '{subscribe_url}', $htmlContent);
$htmlContent = str_replace('https://{{doubleoptin}}', '{subscribe_url}', $htmlContent);
$htmlContent = str_replace('http://{{doubleoptin}}', '{subscribe_url}', $htmlContent);
$htmlContent = str_replace('https://{{ doubleoptin }}', '{subscribe_url}', $htmlContent);
$htmlContent = str_replace('http://{{ doubleoptin }}', '{subscribe_url}', $htmlContent);
$htmlContent = str_replace('[DOUBLEOPTIN]', '{subscribe_url}', $htmlContent);
$htmlContent = preg_replace($searchValue, '{subscribe_url}', $htmlContent);
$htmlContent = str_replace('{site_name}', $siteName, $htmlContent);
$htmlContent = str_replace('{unsubscribe_url}', $pathResp, $htmlContent);
$htmlContent = str_replace('{subscribe_url}', $pathResp, $htmlContent);
Expand Down
97 changes: 56 additions & 41 deletions Model/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,59 @@
*/
namespace Sendinblue\Sendinblue\Model;

class Transport extends \Zend_Mail_Transport_Smtp implements \Magento\Framework\Mail\TransportInterface
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Mail\MessageInterface;
use Zend\Mail\Message;
use Zend\Mail\Transport\SmtpOptions;
use Zend\Mail\Transport\Smtp;

class Transport
{
/**
* @var \Magento\Framework\Mail\MessageInterface
*/
/** @var MessageInterface */
protected $_message;
public $scopeConfig;

/** @var Smtp|\Zend_Mail_Transport_Smtp **/
protected $transport;


/**
* @param MessageInterface $message
* @param null $parameters
* @throws \InvalidArgumentException
*/
public function __construct(\Magento\Framework\Mail\MessageInterface $message,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
)
{
if (!$message instanceof \Zend_Mail) {
throw new \InvalidArgumentException('The message should be an instance of \Zend_Mail');
}

$smtpHost = '';
$smtpConf = array();
$relaySib = $scopeConfig->getValue('sendinblue/relay_data_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

if ($relaySib == 'enabled') {
$smtpHost = $scopeConfig->getValue('sendinblue/smtp_host', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpAuthentication = $scopeConfig->getValue('sendinblue/smtp_authentication', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpTls = $scopeConfig->getValue('sendinblue/smtp_tls', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpPort = $scopeConfig->getValue('sendinblue/smtp_port', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpUsername = $scopeConfig->getValue('sendinblue/smtp_username', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpPassword = $scopeConfig->getValue('sendinblue/smtp_password', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpConf = [
'auth' => $smtpAuthentication,
'tls' => $smtpTls,
'port' => $smtpPort,
'username' => $smtpUsername,
'password' => $smtpPassword
];


}
parent::__construct($smtpHost, $smtpConf);
$this->_message = $message;

public function __construct(MessageInterface $message, ScopeConfigInterface $scopeConfig ){
$this->_message = $message;

$relaySib = $scopeConfig->getValue('sendinblue/relay_data_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
if ($relaySib == 'enabled') {
$smtpHost = "smtp-relay.sendinblue.com";
$smtpAuthentication = $scopeConfig->getValue('sendinblue/smtp_authentication', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpTls = $scopeConfig->getValue('sendinblue/smtp_tls', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpPort = $scopeConfig->getValue('sendinblue/smtp_port', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpUsername = $scopeConfig->getValue('sendinblue/smtp_username', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$smtpPassword = $scopeConfig->getValue('sendinblue/smtp_password', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

if ($message instanceof \Zend_mail) {
$this->transport = new \Zend_Mail_Transport_Smtp($smtpHost, [
'auth' => $smtpAuthentication,
'tls' => $smtpTls,
'port' => $smtpPort,
'username' => $smtpUsername,
'password' => $smtpPassword
]);
} elseif ($message instanceof MessageInterface) {
$this->transport = new Smtp( new SmtpOptions([
'host' => $smtpHost,
'port' => $smtpPort,
'connection_class' => $smtpAuthentication,
'connection_config' => [
'username' => $smtpUsername,
'password' => $smtpPassword,
'ssl' => $smtpTls,
],
]));
}
}
}

/**
Expand All @@ -57,10 +66,16 @@ public function __construct(\Magento\Framework\Mail\MessageInterface $message,
*/
public function sendMessage()
{
try {
parent::send($this->_message);
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);
if(null !== $this->transport){
try {
if ($this->_message instanceof \Zend_mail) {
$this->transport->send($this->_message);
} elseif ($this->_message instanceof MessageInterface) {
$this->transport->send(Message::fromString($this->_message->getRawMessage()));
}
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);
}
}
}

Expand Down
Empty file modified Observer/SibNlObserver.php
100755 → 100644
Empty file.
Empty file modified Observer/SibObserver.php
100755 → 100644
Empty file.
Empty file modified Observer/SibOrderObserver.php
100755 → 100644
Empty file.
Empty file modified Observer/SibShipObserver.php
100755 → 100644
Empty file.
Empty file modified Observer/SibaddrObserver.php
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sendinblue/module-sendinblue",
"description": "N/A",
"type": "magento2-module",
"version": "2.0.2",
"version": "2.0.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- for override magento default Transport class with our custom module model-->
<preference for="\Magento\Framework\Mail\Transport" type="Sendinblue\Sendinblue\Model\Transport"/>
<preference for="\Magento\Framework\Mail\TransportInterface" type="Sendinblue\Sendinblue\Model\Transport"/>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sendinblue_Sendinblue" setup_version="2.0.2"></module>
<module name="Sendinblue_Sendinblue" setup_version="2.0.3"></module>
</config>
10 changes: 4 additions & 6 deletions view/adminhtml/templates/sib.phtml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ $formKey = $block->getFormValue();
<div class="form-box">
<h2 class="heading"><img alt="" src="<?php echo $block->getViewFileUrl('Sendinblue_Sendinblue::images/logo_white.png'); ?>"><?php echo __('Prerequisites'); ?></h2>
<div class="form-box-content">
<p class="sub-heading"><?php echo __('You should have a SendinBlue account. You can create a free account here : '); ?><a class="link_action" href="https://www.sendinblue.com?utm_source=magento_plugin&amp;utm_medium=plugin&amp;utm_campaign=module_link" style="color:#268CCD;" target="_blank">&nbsp;https://www.sendinblue.com</a><br></p>
<p class="sub-heading"><?php echo __('You should have a SendinBlue account. You can create a free account here : '); ?><a class="link_action" href="https://app.sendinblue.com/account/register/?utm_source=magento_plugin&amp;utm_medium=plugin&amp;utm_campaign=module_link" style="color:#268CCD;" target="_blank">&nbsp;https://www.sendinblue.com</a><br></p>
</div>
</div>
<!-- Section Ends -->
Expand Down Expand Up @@ -254,7 +254,7 @@ $formKey = $block->getFormValue();
<?php
if (!empty($camp['campaign_records'])) {
foreach ($camp['campaign_records'] as $templateData) {
if ($templateData['templ_status'] === 'Active' && stristr($templateData['html_content'], 'DOUBLEOPTIN') === false) {
if ($templateData['templ_status'] === 'Active' && stristr($templateData['html_content'], 'doubleoptin') === false) {

?>

Expand Down Expand Up @@ -295,7 +295,7 @@ $formKey = $block->getFormValue();
$doubleOptinTempId = $model->getDbData('doubleoptin_template_id');
if (!empty($camp['campaign_records'])) {
foreach ($camp['campaign_records'] as $templateData) {
if ($templateData['templ_status'] === 'Active' && stristr($templateData['html_content'], 'DOUBLEOPTIN') == true) {
if ($templateData['templ_status'] === 'Active' && stristr($templateData['html_content'], 'doubleoptin') == true) {
if (trim($templateData['id']) == trim($doubleOptinTempId)) { echo 'selected="selected"'; }
?>

Expand Down Expand Up @@ -343,7 +343,7 @@ $formKey = $block->getFormValue();
$optinTempDb = $model->getDbData('final_template_id');
if (!empty($camp['campaign_records'])) {
foreach ($camp['campaign_records'] as $templateData) {
if ($templateData['templ_status'] === 'Active' && stristr($templateData['html_content'], 'DOUBLEOPTIN') === false) {
if ($templateData['templ_status'] === 'Active' && stristr($templateData['html_content'], 'doubleoptin') === false) {
if (trim($templateData['id']) == trim($optinTempDb)) { echo 'selected="selected"'; }
?>

Expand Down Expand Up @@ -373,10 +373,8 @@ $formKey = $block->getFormValue();
<td>
<input name="update_tempvalue" type="hidden" value="update_tempvalue" />
<input class="button submitForm2 btn-primary btn" name="submitForm2" type="submit" value="<?php echo __('Update'); ?>">&nbsp;
<?php if($model->getDbData('import_old_user_status') == 1) { ?>
<input name="import_function" type="hidden" value="import_function" />
<input class="button btn-success btn" name="submitUpdateImport" type="submit" value="<?php echo __('Import Old Subscribers'); ?>">
<?php } ?>
</td>
</tr>
<tr class="managesubscribeBlock">
Expand Down