Skip to content

Commit

Permalink
add button actions #2041 for magento 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Dec 9, 2024
1 parent c279f8f commit 3491591
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 17 deletions.
10 changes: 7 additions & 3 deletions Controller/Adminhtml/Ecommerce/CreateWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
\Ebizmarts\MailChimp\Helper\Data $helper,
\Magento\Config\Model\ResourceModel\Config $config
) {

parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->helper = $helper;
Expand All @@ -74,11 +74,15 @@ public function execute()
$message = $return['message'];
}
$resultJson = $this->resultJsonFactory->create();

return $resultJson->setData([
$resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
$this->helper->buttonPressed("CreateWebhook", [
'valid' => (int)$valid,
'message' => $message,
]);
return $resultJson;
}
protected function _isAllowed()
{
Expand Down
9 changes: 7 additions & 2 deletions Controller/Adminhtml/Ecommerce/DeleteStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
\Ebizmarts\MailChimp\Helper\Data $helper,
\Magento\Config\Model\ResourceModel\Config $config
) {

parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->helper = $helper;
Expand Down Expand Up @@ -89,10 +89,15 @@ public function execute()
$valid = 0;
$message = $e->getMessage();
}
return $resultJson->setData([
$resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
$this->helper->buttonPressed("DeleteStore", [
'valid' => (int)$valid,
'message' => $message,
]);
return $resultJson;
}
protected function _isAllowed()
{
Expand Down
10 changes: 7 additions & 3 deletions Controller/Adminhtml/Ecommerce/FixMailchimpJS.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
\Magento\Framework\App\Cache\TypeListInterface $typeList,
\Ebizmarts\MailChimp\Helper\Data $helper
) {

parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->helper = $helper;
Expand Down Expand Up @@ -76,11 +76,15 @@ public function execute()
$valid = 0;
$message = $e->getMessage();
}

return $resultJson->setData([
$resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
$this->helper->buttonPressed("FixMailchimpJS", [
'valid' => (int)$valid,
'message' => $message,
]);
return $resultJson;
}
protected function _isAllowed()
{
Expand Down
7 changes: 6 additions & 1 deletion Controller/Adminhtml/Ecommerce/ResetLocalErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ public function execute()
$valid = 0;
$message = $e->getMessage();
}
return $resultJson->setData([
$resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
$this->helper->buttonPressed("ResetLocalErrors",[
'valid' => (int)$valid,
'message' => $message,
]);
return $resultJson;
}
protected function _isAllowed()
{
Expand Down
7 changes: 6 additions & 1 deletion Controller/Adminhtml/Ecommerce/ResetLocalErrorsNoRetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ public function execute()
$valid = 0;
$message = $e->getMessage();
}
return $resultJson->setData([
$resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
$this->helper->buttonPressed("ResetLocalErrorNoRetry",[
'valid' => (int)$valid,
'message' => $message,
]);
return $resultJson;
}
protected function _isAllowed()
{
Expand Down
9 changes: 7 additions & 2 deletions Controller/Adminhtml/Ecommerce/ResetStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
\Ebizmarts\MailChimp\Helper\Data $helper
) {

parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->helper = $helper;
Expand Down Expand Up @@ -82,10 +82,15 @@ public function execute()
$valid = 0;
$message = $e->getMessage();
}
return $resultJson->setData([
$resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
$this->helper->buttonPressed("ResetStore", [
'valid' => (int)$valid,
'message' => $message,
]);
return $resultJson;
}
protected function _isAllowed()
{
Expand Down
16 changes: 14 additions & 2 deletions Controller/Adminhtml/Ecommerce/ResyncProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,30 @@ class ResyncProducts extends \Magento\Backend\App\Action
* @var SyncHelper
*/
private $syncHelper;
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
private $helper;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param JsonFactory $resultJsonFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface
* @param SyncHelper $syncHelper
* @param \Ebizmarts\MailChimp\Helper\Data $helper
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
JsonFactory $resultJsonFactory,
\Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
SyncHelper $syncHelper
SyncHelper $syncHelper,
\Ebizmarts\MailChimp\Helper\Data $helper
) {
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->storeManager = $storeManagerInterface;
$this->syncHelper = $syncHelper;
$this->helper = $helper;
}

public function execute()
Expand All @@ -64,10 +71,15 @@ public function execute()
$valid = 0;
$message = $e->getMessage();
}
return $resultJson->setData([
$resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
$this->helper->buttonPressed("ResyncProducts", [
'valid' => (int)$valid,
'message' => $message,
]);
return $resultJson;
}
protected function _isAllowed()
{
Expand Down
16 changes: 14 additions & 2 deletions Controller/Adminhtml/Ecommerce/ResyncSubscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,31 @@ class ResyncSubscribers extends \Magento\Backend\App\Action
* @var SyncHelper
*/
private $syncHelper;
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
private $helper;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param JsonFactory $resultJsonFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface
* @param SyncHelper $syncHelper
* @param \Ebizmarts\MailChimp\Helper\Data $helper
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
JsonFactory $resultJsonFactory,
\Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
SyncHelper $syncHelper
SyncHelper $syncHelper,
\Ebizmarts\MailChimp\Helper\Data $helper
) {

parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->storeManager = $storeManagerInterface;
$this->syncHelper = $syncHelper;
$this->helper = $helper;
}

public function execute()
Expand All @@ -65,10 +72,15 @@ public function execute()
$valid = 0;
$message = $e->getMessage();
}
return $resultJson->setData([
$resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
$this->helper->buttonPressed("ResyncSubscribers", [
'valid' => (int)$valid,
'message' => $message,
]);
return $resultJson;
}
protected function _isAllowed()
{
Expand Down
1 change: 1 addition & 0 deletions Cron/GenerateStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function __construct(
public function execute()
{
$data = [];
$data['storeURL'] = $this->storeManager->getStore()->getBaseUrl();
$data['time'] = $this->helper->getGmtDate();
foreach ($this->storeManager->getStores() as $storeId => $val)
{
Expand Down
13 changes: 13 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ public function getApi($store = null, $scope = null)
$timeOut = $this->getTimeOut($store,$scope);
$this->_api->setApiKey($apiKey);
$this->_api->setHelper($this);
$this->_api->setStoreURL($this->_storeManager->getStore($store)->getBaseUrl());
$this->_api->setUserAgent('Mailchimp4Magento' . (string)$this->getModuleVersion());
if ($timeOut) {
$this->_api->setTimeOut($timeOut);
Expand Down Expand Up @@ -461,8 +462,10 @@ public function getApiByApiKey($apiKey, $encrypted = false)
} else {
$this->_api->setApiKey($apiKey);
}

$this->_api->setUserAgent('Mailchimp4Magento' . (string)$this->getModuleVersion());
$this->_api->setHelper($this);
$this->_api->setStoreURL($this->_storeManager->getStore()->getBaseUrl());

return $this->_api;
}
Expand Down Expand Up @@ -1233,4 +1236,14 @@ public function encrypt($value)
{
return $this->_encryptor->encrypt($value);
}
public function buttonPressed($button, $result)
{
$data = [];
$data['storeURL'] = $this->_storeManager->getStore()->getBaseUrl();
$data['time'] = $this->getGmtDate();
$data['button']['action'] = $button;
$data['button']['result'] = $result;
$this->saveNotification($data);

}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require" : {
"magento/framework": "103.0.*",
"ebizmarts/mailchimp-lib": ">=3.0.42",
"ebizmarts/mailchimp-lib": ">=3.0.43",
"ext-json": "*"
}
}

0 comments on commit 3491591

Please sign in to comment.