-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b388f07
commit 8be0fa3
Showing
61 changed files
with
2,521 additions
and
837 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
app/code/Ecomail/Ecomail/Block/System/Config/Form/Field/Status.php
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,75 @@ | ||
<?php | ||
|
||
namespace Ecomail\Ecomail\Block\System\Config\Form\Field; | ||
|
||
use Ecomail\Ecomail\Helper\Data; | ||
use Ecomail\Ecomail\Model\Api; | ||
use Exception; | ||
use Magento\Backend\Block\Template\Context; | ||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class Status extends Field | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $_template = 'Ecomail_Ecomail::system/config/form/field/status.phtml'; | ||
|
||
/** | ||
* @var Data | ||
*/ | ||
private $helper; | ||
|
||
/** | ||
* @var Api | ||
*/ | ||
private $api; | ||
|
||
/** | ||
* Status constructor. | ||
* @param Context $context | ||
* @param Data $helper | ||
* @param Api $api | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Data $helper, | ||
Api $api, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->helper = $helper; | ||
$this->api = $api; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getStatusCode(): string | ||
{ | ||
if (!$this->helper->isEnabled()) { | ||
return 'Inactive'; | ||
} | ||
|
||
try { | ||
$this->api->getSubscriberLists(); | ||
return 'Active'; | ||
} catch (Exception $e) { | ||
return 'Error'; | ||
} | ||
} | ||
|
||
/** | ||
* Return element html | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
* | ||
*/ | ||
protected function _getElementHtml(AbstractElement $element): string | ||
{ | ||
return $this->_toHtml(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
app/code/Ecomail/Ecomail/Block/System/Config/Form/Field/Subscriber/LoadLists.php
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,67 @@ | ||
<?php | ||
|
||
namespace Ecomail\Ecomail\Block\System\Config\Form\Field\Subscriber; | ||
|
||
use Magento\Backend\Block\Widget\Button; | ||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\Exception\LocalizedException; | ||
|
||
class LoadLists extends Field | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $_template = 'Ecomail_Ecomail::system/config/form/field/subscriber/load_lists.phtml'; | ||
|
||
/** | ||
* Remove scope label | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
public function render(AbstractElement $element): string | ||
{ | ||
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); | ||
return parent::render($element); | ||
} | ||
|
||
/** | ||
* Return element html | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
* | ||
*/ | ||
protected function _getElementHtml(AbstractElement $element): string | ||
{ | ||
return $this->_toHtml(); | ||
} | ||
|
||
/** | ||
* @return string | ||
* @throws LocalizedException | ||
*/ | ||
public function getButtonHtml(): string | ||
{ | ||
$button = $this->getLayout()->createBlock( | ||
Button::class | ||
)->setData( | ||
[ | ||
'id' => 'load_lists', | ||
'label' => __('Load Lists') | ||
] | ||
); | ||
|
||
return $button->toHtml(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAjaxUrl(): string | ||
{ | ||
return $this->getUrl('*/system_config_ecomail/loadLists'); | ||
} | ||
} |
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,4 @@ | ||
# Ecomail changelog | ||
|
||
## v2.0.0 - 22 Mar, 2021 | ||
* initial release |
57 changes: 0 additions & 57 deletions
57
app/code/Ecomail/Ecomail/Controller/Adminhtml/Ecomail/Ajax.php
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
app/code/Ecomail/Ecomail/Controller/Adminhtml/System/Config/Ecomail/LoadLists.php
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,55 @@ | ||
<?php | ||
|
||
namespace Ecomail\Ecomail\Controller\Adminhtml\System\Config\Ecomail; | ||
|
||
use Ecomail\Ecomail\Model\Api; | ||
use Exception; | ||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Controller\ResultInterface; | ||
|
||
class LoadLists extends Action | ||
{ | ||
const ADMIN_RESOURCE = 'Ecomail_Ecomail::ecomail_configuration'; | ||
|
||
/** | ||
* @var Api | ||
*/ | ||
private $api; | ||
|
||
public function __construct( | ||
Context $context, | ||
Api $api | ||
) { | ||
parent::__construct($context); | ||
$this->api = $api; | ||
} | ||
|
||
/** | ||
* @return ResultInterface | ||
*/ | ||
public function execute(): ResultInterface | ||
{ | ||
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON); | ||
|
||
$apiKey = $this->getRequest()->getParam('api_key'); | ||
|
||
try { | ||
$subscriberLists = $this->api->getSubscriberLists($apiKey); | ||
} catch (Exception $e) { | ||
return $result->setData([]); | ||
} | ||
|
||
$response = []; | ||
|
||
foreach ($subscriberLists as $list) { | ||
$response[] = [ | ||
'label' => $list['name'], | ||
'value' => $list['id'], | ||
]; | ||
} | ||
|
||
return $result->setData($response); | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
namespace Ecomail\Ecomail\CustomerData; | ||
|
||
use Ecomail\Ecomail\Helper\Data; | ||
use Magento\Customer\CustomerData\SectionSourceInterface; | ||
use Magento\Customer\Model\Session; | ||
use Magento\Framework\DataObject; | ||
|
||
class Ecomail extends DataObject implements SectionSourceInterface | ||
{ | ||
/** | ||
* @var \Magento\Customer\Model\Session | ||
*/ | ||
private $customerSession; | ||
|
||
/** | ||
* @var Data | ||
*/ | ||
private $helper; | ||
|
||
/** | ||
* Ecomail constructor. | ||
* @param Session $customerSession | ||
* @param Data $helper | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Session $customerSession, | ||
Data $helper, | ||
array $data = [] | ||
) { | ||
parent::__construct($data); | ||
$this->customerSession = $customerSession; | ||
$this->helper = $helper; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getSectionData(): array | ||
{ | ||
$sectionData = []; | ||
|
||
if ($this->helper->isTrackingEnabled() && $this->customerSession->getEcomailEmail()) { | ||
$sectionData['email'] = $this->customerSession->getEcomailEmail(); | ||
$this->customerSession->setEcomailEmail(null); | ||
} | ||
|
||
return $sectionData; | ||
} | ||
} |
Oops, something went wrong.