From 5991c10ee4155068aefde1e34ca7e6648db59ce8 Mon Sep 17 00:00:00 2001 From: shin Date: Fri, 4 Dec 2020 14:21:49 +0700 Subject: [PATCH 1/6] Ticket Bug: Do not save new item if store is in single store mode. --- Controller/Adminhtml/ManageHooks/Save.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Controller/Adminhtml/ManageHooks/Save.php b/Controller/Adminhtml/ManageHooks/Save.php index e5efe65..3209bde 100755 --- a/Controller/Adminhtml/ManageHooks/Save.php +++ b/Controller/Adminhtml/ManageHooks/Save.php @@ -32,6 +32,7 @@ use Mageplaza\Webhook\Helper\Data; use Mageplaza\Webhook\Model\HookFactory; use RuntimeException; +use Magento\Store\Model\StoreManagerInterface; /** * Class Save @@ -44,6 +45,11 @@ class Save extends AbstractManageHooks */ protected $helperData; + /** + * @var StoreManagerInterface + */ + protected $_storeManager; + /** * Save constructor. * @@ -51,14 +57,17 @@ class Save extends AbstractManageHooks * @param Registry $coreRegistry * @param Context $context * @param Data $helperData + * @param StoreManagerInterface $storeManager */ public function __construct( HookFactory $hookFactory, Registry $coreRegistry, Context $context, - Data $helperData + Data $helperData, + StoreManagerInterface $storeManager ) { - $this->helperData = $helperData; + $this->helperData = $helperData; + $this->_storeManager = $storeManager; parent::__construct($hookFactory, $coreRegistry, $context); } @@ -82,7 +91,7 @@ public function execute() $data['order_status'] = implode(',', $data['order_status']); } - if (isset($data['store_ids']) && $data['store_ids']) { + if (isset($data['store_ids']) && $data['store_ids'] && !$this->_storeManager->isSingleStoreMode()) { $data['store_ids'] = implode(',', $data['store_ids']); } From 89f9f8f5c9ab0853924f08a5b1904ac4bf1ea340 Mon Sep 17 00:00:00 2001 From: shin Date: Tue, 12 Jan 2021 15:36:08 +0700 Subject: [PATCH 2/6] Update code to check response success. --- Helper/Data.php | 1121 ++++++++++++++++++++++++----------------------- 1 file changed, 566 insertions(+), 555 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index e177784..51a277c 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -1,555 +1,566 @@ -liquidFilters = $liquidFilters; - $this->curlFactory = $curlFactory; - $this->hookFactory = $hookFactory; - $this->historyFactory = $historyFactory; - $this->transportBuilder = $transportBuilder; - $this->backendUrl = $backendUrl; - $this->customer = $customer; - - parent::__construct($context, $objectManager, $storeManager); - } - - /** - * @param $item - * - * @return int - * @throws NoSuchEntityException - */ - public function getItemStore($item) - { - if (method_exists($item, 'getData')) { - return $item->getData('store_id') ?: $this->storeManager->getStore()->getId(); - } - - return $this->storeManager->getStore()->getId(); - } - - /** - * @param $item - * @param $hookType - * @throws LocalizedException - * @throws NoSuchEntityException - */ - public function send($item, $hookType) - { - if (!$this->isEnabled()) { - return; - } - - /** @var Collection $hookCollection */ - $hookCollection = $this->hookFactory->create()->getCollection() - ->addFieldToFilter('hook_type', $hookType) - ->addFieldToFilter('status', 1) - ->addFieldToFilter('store_ids', [ - ['finset' => Store::DEFAULT_STORE_ID], - ['finset' => $this->getItemStore($item)] - ]) - ->setOrder('priority', 'ASC'); - $isSendMail = $this->getConfigGeneral('alert_enabled'); - $sendTo = explode(',', $this->getConfigGeneral('send_to')); - foreach ($hookCollection as $hook) { - if ($hook->getHookType() === HookType::ORDER) { - $statusItem = $item->getStatus(); - $orderStatus = explode(',', $hook->getOrderStatus()); - if (!in_array($statusItem, $orderStatus, true)) { - continue; - } - } - $history = $this->historyFactory->create(); - $data = [ - 'hook_id' => $hook->getId(), - 'hook_name' => $hook->getName(), - 'store_ids' => $hook->getStoreIds(), - 'hook_type' => $hook->getHookType(), - 'priority' => $hook->getPriority(), - 'payload_url' => $this->generateLiquidTemplate($item, $hook->getPayloadUrl()), - 'body' => $this->generateLiquidTemplate($item, $hook->getBody()) - ]; - $history->addData($data); - try { - $result = $this->sendHttpRequestFromHook($hook, $item); - $history->setResponse(isset($result['response']) ? $result['response'] : ''); - } catch (Exception $e) { - $result = [ - 'success' => false, - 'message' => $e->getMessage() - ]; - } - if ($result['success'] === true) { - $history->setStatus(Status::SUCCESS); - } else { - $history->setStatus(Status::ERROR) - ->setMessage($result['message']); - if ($isSendMail) { - $this->sendMail( - $sendTo, - __('Something went wrong while sending %1 hook', $hook->getName()), - $this->getConfigGeneral('email_template'), - $this->getStoreId() - ); - } - } - - $history->save(); - } - } - - /** - * @param $hook - * @param bool $item - * @param bool $log - * - * @return array - */ - public function sendHttpRequestFromHook($hook, $item = false, $log = false) - { - $url = $log ? $log->getPayloadUrl() : $this->generateLiquidTemplate($item, $hook->getPayloadUrl()); - $authentication = $hook->getAuthentication(); - $method = $hook->getMethod(); - $username = $hook->getUsername(); - $password = $hook->getPassword(); - if ($authentication === Authentication::BASIC) { - $authentication = $this->getBasicAuthHeader($username, $password); - } elseif ($authentication === Authentication::DIGEST) { - $authentication = $this->getDigestAuthHeader( - $url, - $method, - $username, - $hook->getRealm(), - $password, - $hook->getNonce(), - $hook->getAlgorithm(), - $hook->getQop(), - $hook->getNonceCount(), - $hook->getClientNonce(), - $hook->getOpaque() - ); - } - - $body = $log ? $log->getBody() : $this->generateLiquidTemplate($item, $hook->getBody()); - $headers = $hook->getHeaders(); - $contentType = $hook->getContentType(); - - return $this->sendHttpRequest($headers, $authentication, $contentType, $url, $body, $method); - } - - /** - * @param $item - * @param $templateHtml - * - * @return string - */ - public function generateLiquidTemplate($item, $templateHtml) - { - try { - $template = new Template; - $filtersMethods = $this->liquidFilters->getFiltersMethods(); - - $template->registerFilter($this->liquidFilters); - $template->parse($templateHtml, $filtersMethods); - - if ($item instanceof Product) { - $item->setStockItem(null); - } - - return $template->render([ - 'item' => $item, - ]); - } catch (Exception $e) { - $this->_logger->critical($e->getMessage()); - } - - return ''; - } - - /** - * @param $headers - * @param $authentication - * @param $contentType - * @param $url - * @param $body - * @param $method - * - * @return array - */ - public function sendHttpRequest($headers, $authentication, $contentType, $url, $body, $method) - { - if (!$method) { - $method = 'GET'; - } - if ($headers && !is_array($headers)) { - $headers = $this::jsonDecode($headers); - } - $headersConfig = []; - - foreach ($headers as $header) { - $key = $header['name']; - $value = $header['value']; - $headersConfig[] = trim($key) . ': ' . trim($value); - } - - if ($authentication) { - $headersConfig[] = 'Authorization: ' . $authentication; - } - - if ($contentType) { - $headersConfig[] = 'Content-Type: ' . $contentType; - } - - $curl = $this->curlFactory->create(); - $curl->write($method, $url, '1.1', $headersConfig, $body); - - $result = ['success' => false]; - - try { - $resultCurl = $curl->read(); - $result['response'] = $resultCurl; - if (!empty($resultCurl)) { - $result['status'] = Zend_Http_Response::extractCode($resultCurl); - if (isset($result['status']) && in_array($result['status'], [200, 201])) { - $result['success'] = true; - } else { - $result['message'] = __('Cannot connect to server. Please try again later.'); - } - } else { - $result['message'] = __('Cannot connect to server. Please try again later.'); - } - } catch (Exception $e) { - $result['message'] = $e->getMessage(); - } - $curl->close(); - - return $result; - } - - /** - * @param $url - * @param $method - * @param $username - * @param $realm - * @param $password - * @param $nonce - * @param $algorithm - * @param $qop - * @param $nonceCount - * @param $clientNonce - * @param $opaque - * - * @return string - */ - public function getDigestAuthHeader( - $url, - $method, - $username, - $realm, - $password, - $nonce, - $algorithm, - $qop, - $nonceCount, - $clientNonce, - $opaque - ) { - $uri = parse_url($url)[2]; - $method = $method ?: 'GET'; - $A1 = hash('md5', "{$username}:{$realm}:{$password}"); - $A2 = hash('md5', "{$method}:{$uri}"); - $response = hash('md5', "{$A1}:{$nonce}:{$nonceCount}:{$clientNonce}:{$qop}:${A2}"); - $digestHeader = "Digest username=\"{$username}\", realm=\"{$realm}\", nonce=\"{$nonce}\", uri=\"{$uri}\", cnonce=\"{$clientNonce}\", nc={$nonceCount}, qop=\"{$qop}\", response=\"{$response}\", opaque=\"{$opaque}\", algorithm=\"{$algorithm}\""; - - return $digestHeader; - } - - /** - * @param $username - * @param $password - * - * @return string - */ - public function getBasicAuthHeader($username, $password) - { - return 'Basic ' . base64_encode("{$username}:{$password}"); - } - - /** - * @param $item - * @param $hookType - * @throws LocalizedException - * @throws NoSuchEntityException - */ - public function sendObserver($item, $hookType) - { - if (!$this->isEnabled()) { - return; - } - - /** @var Collection $hookCollection */ - $hookCollection = $this->hookFactory->create()->getCollection() - ->addFieldToFilter('hook_type', $hookType) - ->addFieldToFilter('status', 1) - ->setOrder('priority', 'ASC'); - - $isSendMail = $this->getConfigGeneral('alert_enabled'); - $sendTo = explode(',', $this->getConfigGeneral('send_to')); - - foreach ($hookCollection as $hook) { - try { - $history = $this->historyFactory->create(); - $data = [ - 'hook_id' => $hook->getId(), - 'hook_name' => $hook->getName(), - 'store_ids' => $hook->getStoreIds(), - 'hook_type' => $hook->getHookType(), - 'priority' => $hook->getPriority(), - 'payload_url' => $this->generateLiquidTemplate($item, $hook->getPayloadUrl()), - 'body' => $this->generateLiquidTemplate($item, $hook->getBody()) - ]; - $history->addData($data); - try { - $result = $this->sendHttpRequestFromHook($hook, $item); - $history->setResponse(isset($result['response']) ? $result['response'] : ''); - } catch (Exception $e) { - $result = [ - 'success' => false, - 'message' => $e->getMessage() - ]; - } - if ($result['success'] === true) { - $history->setStatus(Status::SUCCESS); - } else { - $history->setStatus(Status::ERROR) - ->setMessage($result['message']); - if ($isSendMail) { - $this->sendMail( - $sendTo, - __('Something went wrong while sending %1 hook', $hook->getName()), - $this->getConfigGeneral('email_template'), - $this->storeManager->getStore()->getId() - ); - } - } - $history->save(); - } catch (Exception $e) { - if ($isSendMail) { - $this->sendMail( - $sendTo, - __('Something went wrong while sending %1 hook', $hook->getName()), - $this->getConfigGeneral('email_template'), - $this->storeManager->getStore()->getId() - ); - } - } - } - } - - /** - * @param $sendTo - * @param $mes - * @param $emailTemplate - * @param $storeId - * - * @return bool - * @throws LocalizedException - */ - public function sendMail($sendTo, $mes, $emailTemplate, $storeId) - { - try { - $this->transportBuilder - ->setTemplateIdentifier($emailTemplate) - ->setTemplateOptions([ - 'area' => Area::AREA_FRONTEND, - 'store' => $storeId, - ]) - ->setTemplateVars([ - 'viewLogUrl' => $this->backendUrl->getUrl('mpwebhook/logs/'), - 'mes' => $mes - ]) - ->setFrom('general') - ->addTo($sendTo); - $transport = $this->transportBuilder->getTransport(); - $transport->sendMessage(); - - return true; - } catch (MailException $e) { - $this->_logger->critical($e->getLogMessage()); - } - - return false; - } - - /** - * @return int - * @throws NoSuchEntityException - */ - public function getStoreId() - { - return $this->storeManager->getStore()->getId(); - } - - /** - * @param string $schedule - * @param string $startTime - * - * @return string - */ - public function getCronExpr($schedule, $startTime) - { - $ArTime = explode(',', $startTime); - $cronExprArray = [ - (int)$ArTime[1], // Minute - (int)$ArTime[0], // Hour - $schedule === Schedule::CRON_MONTHLY ? 1 : '*', // Day of the Month - '*', // Month of the Year - $schedule === Schedule::CRON_WEEKLY ? 0 : '*', // Day of the Week - ]; - if ($schedule === Schedule::CRON_MINUTE) { - return '* * * * *'; - } - - return implode(' ', $cronExprArray); - } - - /** - * @param null $field - * - * @return mixed - * @throws NoSuchEntityException - */ - public function getCronSchedule($field = null) - { - $storeId = $this->getStoreId(); - if ($field === null) { - return $this->getModuleConfig('cron/schedule', $storeId); - } - - return $this->getModuleConfig('cron/' . $field, $storeId); - } - - /** - * @param $classPath - * - * @return mixed - */ - public function getObjectClass($classPath) - { - return $this->objectManager->create($classPath); - } -} +liquidFilters = $liquidFilters; + $this->curlFactory = $curlFactory; + $this->hookFactory = $hookFactory; + $this->historyFactory = $historyFactory; + $this->transportBuilder = $transportBuilder; + $this->backendUrl = $backendUrl; + $this->customer = $customer; + + parent::__construct($context, $objectManager, $storeManager); + } + + /** + * @param $item + * + * @return int + * @throws NoSuchEntityException + */ + public function getItemStore($item) + { + if (method_exists($item, 'getData')) { + return $item->getData('store_id') ?: $this->storeManager->getStore()->getId(); + } + + return $this->storeManager->getStore()->getId(); + } + + /** + * @param $item + * @param $hookType + * @throws LocalizedException + * @throws NoSuchEntityException + */ + public function send($item, $hookType) + { + if (!$this->isEnabled()) { + return; + } + + /** @var Collection $hookCollection */ + $hookCollection = $this->hookFactory->create()->getCollection() + ->addFieldToFilter('hook_type', $hookType) + ->addFieldToFilter('status', 1) + ->addFieldToFilter('store_ids', [ + ['finset' => Store::DEFAULT_STORE_ID], + ['finset' => $this->getItemStore($item)] + ]) + ->setOrder('priority', 'ASC'); + $isSendMail = $this->getConfigGeneral('alert_enabled'); + $sendTo = explode(',', $this->getConfigGeneral('send_to')); + foreach ($hookCollection as $hook) { + if ($hook->getHookType() === HookType::ORDER) { + $statusItem = $item->getStatus(); + $orderStatus = explode(',', $hook->getOrderStatus()); + if (!in_array($statusItem, $orderStatus, true)) { + continue; + } + } + $history = $this->historyFactory->create(); + $data = [ + 'hook_id' => $hook->getId(), + 'hook_name' => $hook->getName(), + 'store_ids' => $hook->getStoreIds(), + 'hook_type' => $hook->getHookType(), + 'priority' => $hook->getPriority(), + 'payload_url' => $this->generateLiquidTemplate($item, $hook->getPayloadUrl()), + 'body' => $this->generateLiquidTemplate($item, $hook->getBody()) + ]; + $history->addData($data); + try { + $result = $this->sendHttpRequestFromHook($hook, $item); + $history->setResponse(isset($result['response']) ? $result['response'] : ''); + } catch (Exception $e) { + $result = [ + 'success' => false, + 'message' => $e->getMessage() + ]; + } + if ($result['success'] === true) { + $history->setStatus(Status::SUCCESS); + } else { + $history->setStatus(Status::ERROR) + ->setMessage($result['message']); + if ($isSendMail) { + $this->sendMail( + $sendTo, + __('Something went wrong while sending %1 hook', $hook->getName()), + $this->getConfigGeneral('email_template'), + $this->getStoreId() + ); + } + } + + $history->save(); + } + } + + /** + * @param $hook + * @param bool $item + * @param bool $log + * + * @return array + */ + public function sendHttpRequestFromHook($hook, $item = false, $log = false) + { + $url = $log ? $log->getPayloadUrl() : $this->generateLiquidTemplate($item, $hook->getPayloadUrl()); + $authentication = $hook->getAuthentication(); + $method = $hook->getMethod(); + $username = $hook->getUsername(); + $password = $hook->getPassword(); + if ($authentication === Authentication::BASIC) { + $authentication = $this->getBasicAuthHeader($username, $password); + } elseif ($authentication === Authentication::DIGEST) { + $authentication = $this->getDigestAuthHeader( + $url, + $method, + $username, + $hook->getRealm(), + $password, + $hook->getNonce(), + $hook->getAlgorithm(), + $hook->getQop(), + $hook->getNonceCount(), + $hook->getClientNonce(), + $hook->getOpaque() + ); + } + + $body = $log ? $log->getBody() : $this->generateLiquidTemplate($item, $hook->getBody()); + $headers = $hook->getHeaders(); + $contentType = $hook->getContentType(); + + return $this->sendHttpRequest($headers, $authentication, $contentType, $url, $body, $method); + } + + /** + * @param $item + * @param $templateHtml + * + * @return string + */ + public function generateLiquidTemplate($item, $templateHtml) + { + try { + $template = new Template; + $filtersMethods = $this->liquidFilters->getFiltersMethods(); + + $template->registerFilter($this->liquidFilters); + $template->parse($templateHtml, $filtersMethods); + + if ($item instanceof Product) { + $item->setStockItem(null); + } + + return $template->render([ + 'item' => $item, + ]); + } catch (Exception $e) { + $this->_logger->critical($e->getMessage()); + } + + return ''; + } + + /** + * @param $headers + * @param $authentication + * @param $contentType + * @param $url + * @param $body + * @param $method + * + * @return array + */ + public function sendHttpRequest($headers, $authentication, $contentType, $url, $body, $method) + { + if (!$method) { + $method = 'GET'; + } + if ($headers && !is_array($headers)) { + $headers = $this::jsonDecode($headers); + } + $headersConfig = []; + + foreach ($headers as $header) { + $key = $header['name']; + $value = $header['value']; + $headersConfig[] = trim($key) . ': ' . trim($value); + } + + if ($authentication) { + $headersConfig[] = 'Authorization: ' . $authentication; + } + + if ($contentType) { + $headersConfig[] = 'Content-Type: ' . $contentType; + } + + $curl = $this->curlFactory->create(); + $curl->write($method, $url, '1.1', $headersConfig, $body); + + $result = ['success' => false]; + + try { + $resultCurl = $curl->read(); + $result['response'] = $resultCurl; + if (!empty($resultCurl)) { + $result['status'] = Zend_Http_Response::extractCode($resultCurl); + if (isset($result['status']) && $this->isSuccess($result['status'])) { + $result['success'] = true; + } else { + $result['message'] = __('Cannot connect to server. Please try again later.'); + } + } else { + $result['message'] = __('Cannot connect to server. Please try again later.'); + } + } catch (Exception $e) { + $result['message'] = $e->getMessage(); + } + $curl->close(); + + return $result; + } + + /** + * @param $url + * @param $method + * @param $username + * @param $realm + * @param $password + * @param $nonce + * @param $algorithm + * @param $qop + * @param $nonceCount + * @param $clientNonce + * @param $opaque + * + * @return string + */ + public function getDigestAuthHeader( + $url, + $method, + $username, + $realm, + $password, + $nonce, + $algorithm, + $qop, + $nonceCount, + $clientNonce, + $opaque + ) { + $uri = parse_url($url)[2]; + $method = $method ?: 'GET'; + $A1 = hash('md5', "{$username}:{$realm}:{$password}"); + $A2 = hash('md5', "{$method}:{$uri}"); + $response = hash('md5', "{$A1}:{$nonce}:{$nonceCount}:{$clientNonce}:{$qop}:${A2}"); + $digestHeader = "Digest username=\"{$username}\", realm=\"{$realm}\", nonce=\"{$nonce}\", uri=\"{$uri}\", cnonce=\"{$clientNonce}\", nc={$nonceCount}, qop=\"{$qop}\", response=\"{$response}\", opaque=\"{$opaque}\", algorithm=\"{$algorithm}\""; + + return $digestHeader; + } + + /** + * @param $username + * @param $password + * + * @return string + */ + public function getBasicAuthHeader($username, $password) + { + return 'Basic ' . base64_encode("{$username}:{$password}"); + } + + /** + * @param $item + * @param $hookType + * @throws LocalizedException + * @throws NoSuchEntityException + */ + public function sendObserver($item, $hookType) + { + if (!$this->isEnabled()) { + return; + } + + /** @var Collection $hookCollection */ + $hookCollection = $this->hookFactory->create()->getCollection() + ->addFieldToFilter('hook_type', $hookType) + ->addFieldToFilter('status', 1) + ->setOrder('priority', 'ASC'); + + $isSendMail = $this->getConfigGeneral('alert_enabled'); + $sendTo = explode(',', $this->getConfigGeneral('send_to')); + + foreach ($hookCollection as $hook) { + try { + $history = $this->historyFactory->create(); + $data = [ + 'hook_id' => $hook->getId(), + 'hook_name' => $hook->getName(), + 'store_ids' => $hook->getStoreIds(), + 'hook_type' => $hook->getHookType(), + 'priority' => $hook->getPriority(), + 'payload_url' => $this->generateLiquidTemplate($item, $hook->getPayloadUrl()), + 'body' => $this->generateLiquidTemplate($item, $hook->getBody()) + ]; + $history->addData($data); + try { + $result = $this->sendHttpRequestFromHook($hook, $item); + $history->setResponse(isset($result['response']) ? $result['response'] : ''); + } catch (Exception $e) { + $result = [ + 'success' => false, + 'message' => $e->getMessage() + ]; + } + if ($result['success'] === true) { + $history->setStatus(Status::SUCCESS); + } else { + $history->setStatus(Status::ERROR) + ->setMessage($result['message']); + if ($isSendMail) { + $this->sendMail( + $sendTo, + __('Something went wrong while sending %1 hook', $hook->getName()), + $this->getConfigGeneral('email_template'), + $this->storeManager->getStore()->getId() + ); + } + } + $history->save(); + } catch (Exception $e) { + if ($isSendMail) { + $this->sendMail( + $sendTo, + __('Something went wrong while sending %1 hook', $hook->getName()), + $this->getConfigGeneral('email_template'), + $this->storeManager->getStore()->getId() + ); + } + } + } + } + + /** + * @param $sendTo + * @param $mes + * @param $emailTemplate + * @param $storeId + * + * @return bool + * @throws LocalizedException + */ + public function sendMail($sendTo, $mes, $emailTemplate, $storeId) + { + try { + $this->transportBuilder + ->setTemplateIdentifier($emailTemplate) + ->setTemplateOptions([ + 'area' => Area::AREA_FRONTEND, + 'store' => $storeId, + ]) + ->setTemplateVars([ + 'viewLogUrl' => $this->backendUrl->getUrl('mpwebhook/logs/'), + 'mes' => $mes + ]) + ->setFrom('general') + ->addTo($sendTo); + $transport = $this->transportBuilder->getTransport(); + $transport->sendMessage(); + + return true; + } catch (MailException $e) { + $this->_logger->critical($e->getLogMessage()); + } + + return false; + } + + /** + * @return int + * @throws NoSuchEntityException + */ + public function getStoreId() + { + return $this->storeManager->getStore()->getId(); + } + + /** + * @param string $schedule + * @param string $startTime + * + * @return string + */ + public function getCronExpr($schedule, $startTime) + { + $ArTime = explode(',', $startTime); + $cronExprArray = [ + (int)$ArTime[1], // Minute + (int)$ArTime[0], // Hour + $schedule === Schedule::CRON_MONTHLY ? 1 : '*', // Day of the Month + '*', // Month of the Year + $schedule === Schedule::CRON_WEEKLY ? 0 : '*', // Day of the Week + ]; + if ($schedule === Schedule::CRON_MINUTE) { + return '* * * * *'; + } + + return implode(' ', $cronExprArray); + } + + /** + * @param null $field + * + * @return mixed + * @throws NoSuchEntityException + */ + public function getCronSchedule($field = null) + { + $storeId = $this->getStoreId(); + if ($field === null) { + return $this->getModuleConfig('cron/schedule', $storeId); + } + + return $this->getModuleConfig('cron/' . $field, $storeId); + } + + /** + * @param $classPath + * + * @return mixed + */ + public function getObjectClass($classPath) + { + return $this->objectManager->create($classPath); + } + + /** + * @param $code + * + * @return bool + */ + public function isSuccess($code) + { + return (200 <= $code && 300 > $code); + } + +} From 3dcd1b37fffd69ce10ed2b96fd363c848d7d8e7c Mon Sep 17 00:00:00 2001 From: shin Date: Tue, 12 Jan 2021 15:44:00 +0700 Subject: [PATCH 3/6] clean code. --- Helper/Data.php | 91 +++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 51a277c..0366523 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -116,13 +116,13 @@ public function __construct( HistoryFactory $historyFactory, CustomerRepositoryInterface $customer ) { - $this->liquidFilters = $liquidFilters; - $this->curlFactory = $curlFactory; - $this->hookFactory = $hookFactory; - $this->historyFactory = $historyFactory; + $this->liquidFilters = $liquidFilters; + $this->curlFactory = $curlFactory; + $this->hookFactory = $hookFactory; + $this->historyFactory = $historyFactory; $this->transportBuilder = $transportBuilder; - $this->backendUrl = $backendUrl; - $this->customer = $customer; + $this->backendUrl = $backendUrl; + $this->customer = $customer; parent::__construct($context, $objectManager, $storeManager); } @@ -145,6 +145,7 @@ public function getItemStore($item) /** * @param $item * @param $hookType + * * @throws LocalizedException * @throws NoSuchEntityException */ @@ -163,25 +164,25 @@ public function send($item, $hookType) ['finset' => $this->getItemStore($item)] ]) ->setOrder('priority', 'ASC'); - $isSendMail = $this->getConfigGeneral('alert_enabled'); - $sendTo = explode(',', $this->getConfigGeneral('send_to')); + $isSendMail = $this->getConfigGeneral('alert_enabled'); + $sendTo = explode(',', $this->getConfigGeneral('send_to')); foreach ($hookCollection as $hook) { if ($hook->getHookType() === HookType::ORDER) { - $statusItem = $item->getStatus(); + $statusItem = $item->getStatus(); $orderStatus = explode(',', $hook->getOrderStatus()); if (!in_array($statusItem, $orderStatus, true)) { continue; } } $history = $this->historyFactory->create(); - $data = [ - 'hook_id' => $hook->getId(), - 'hook_name' => $hook->getName(), - 'store_ids' => $hook->getStoreIds(), - 'hook_type' => $hook->getHookType(), - 'priority' => $hook->getPriority(), + $data = [ + 'hook_id' => $hook->getId(), + 'hook_name' => $hook->getName(), + 'store_ids' => $hook->getStoreIds(), + 'hook_type' => $hook->getHookType(), + 'priority' => $hook->getPriority(), 'payload_url' => $this->generateLiquidTemplate($item, $hook->getPayloadUrl()), - 'body' => $this->generateLiquidTemplate($item, $hook->getBody()) + 'body' => $this->generateLiquidTemplate($item, $hook->getBody()) ]; $history->addData($data); try { @@ -221,11 +222,11 @@ public function send($item, $hookType) */ public function sendHttpRequestFromHook($hook, $item = false, $log = false) { - $url = $log ? $log->getPayloadUrl() : $this->generateLiquidTemplate($item, $hook->getPayloadUrl()); + $url = $log ? $log->getPayloadUrl() : $this->generateLiquidTemplate($item, $hook->getPayloadUrl()); $authentication = $hook->getAuthentication(); - $method = $hook->getMethod(); - $username = $hook->getUsername(); - $password = $hook->getPassword(); + $method = $hook->getMethod(); + $username = $hook->getUsername(); + $password = $hook->getPassword(); if ($authentication === Authentication::BASIC) { $authentication = $this->getBasicAuthHeader($username, $password); } elseif ($authentication === Authentication::DIGEST) { @@ -244,8 +245,8 @@ public function sendHttpRequestFromHook($hook, $item = false, $log = false) ); } - $body = $log ? $log->getBody() : $this->generateLiquidTemplate($item, $hook->getBody()); - $headers = $hook->getHeaders(); + $body = $log ? $log->getBody() : $this->generateLiquidTemplate($item, $hook->getBody()); + $headers = $hook->getHeaders(); $contentType = $hook->getContentType(); return $this->sendHttpRequest($headers, $authentication, $contentType, $url, $body, $method); @@ -260,7 +261,7 @@ public function sendHttpRequestFromHook($hook, $item = false, $log = false) public function generateLiquidTemplate($item, $templateHtml) { try { - $template = new Template; + $template = new Template; $filtersMethods = $this->liquidFilters->getFiltersMethods(); $template->registerFilter($this->liquidFilters); @@ -301,8 +302,8 @@ public function sendHttpRequest($headers, $authentication, $contentType, $url, $ $headersConfig = []; foreach ($headers as $header) { - $key = $header['name']; - $value = $header['value']; + $key = $header['name']; + $value = $header['value']; $headersConfig[] = trim($key) . ': ' . trim($value); } @@ -320,7 +321,7 @@ public function sendHttpRequest($headers, $authentication, $contentType, $url, $ $result = ['success' => false]; try { - $resultCurl = $curl->read(); + $resultCurl = $curl->read(); $result['response'] = $resultCurl; if (!empty($resultCurl)) { $result['status'] = Zend_Http_Response::extractCode($resultCurl); @@ -368,11 +369,11 @@ public function getDigestAuthHeader( $clientNonce, $opaque ) { - $uri = parse_url($url)[2]; - $method = $method ?: 'GET'; - $A1 = hash('md5', "{$username}:{$realm}:{$password}"); - $A2 = hash('md5', "{$method}:{$uri}"); - $response = hash('md5', "{$A1}:{$nonce}:{$nonceCount}:{$clientNonce}:{$qop}:${A2}"); + $uri = parse_url($url)[2]; + $method = $method ?: 'GET'; + $A1 = hash('md5', "{$username}:{$realm}:{$password}"); + $A2 = hash('md5', "{$method}:{$uri}"); + $response = hash('md5', "{$A1}:{$nonce}:{$nonceCount}:{$clientNonce}:{$qop}:${A2}"); $digestHeader = "Digest username=\"{$username}\", realm=\"{$realm}\", nonce=\"{$nonce}\", uri=\"{$uri}\", cnonce=\"{$clientNonce}\", nc={$nonceCount}, qop=\"{$qop}\", response=\"{$response}\", opaque=\"{$opaque}\", algorithm=\"{$algorithm}\""; return $digestHeader; @@ -392,6 +393,7 @@ public function getBasicAuthHeader($username, $password) /** * @param $item * @param $hookType + * * @throws LocalizedException * @throws NoSuchEntityException */ @@ -408,19 +410,19 @@ public function sendObserver($item, $hookType) ->setOrder('priority', 'ASC'); $isSendMail = $this->getConfigGeneral('alert_enabled'); - $sendTo = explode(',', $this->getConfigGeneral('send_to')); + $sendTo = explode(',', $this->getConfigGeneral('send_to')); foreach ($hookCollection as $hook) { try { $history = $this->historyFactory->create(); - $data = [ - 'hook_id' => $hook->getId(), - 'hook_name' => $hook->getName(), - 'store_ids' => $hook->getStoreIds(), - 'hook_type' => $hook->getHookType(), - 'priority' => $hook->getPriority(), + $data = [ + 'hook_id' => $hook->getId(), + 'hook_name' => $hook->getName(), + 'store_ids' => $hook->getStoreIds(), + 'hook_type' => $hook->getHookType(), + 'priority' => $hook->getPriority(), 'payload_url' => $this->generateLiquidTemplate($item, $hook->getPayloadUrl()), - 'body' => $this->generateLiquidTemplate($item, $hook->getBody()) + 'body' => $this->generateLiquidTemplate($item, $hook->getBody()) ]; $history->addData($data); try { @@ -475,12 +477,12 @@ public function sendMail($sendTo, $mes, $emailTemplate, $storeId) $this->transportBuilder ->setTemplateIdentifier($emailTemplate) ->setTemplateOptions([ - 'area' => Area::AREA_FRONTEND, + 'area' => Area::AREA_FRONTEND, 'store' => $storeId, ]) ->setTemplateVars([ 'viewLogUrl' => $this->backendUrl->getUrl('mpwebhook/logs/'), - 'mes' => $mes + 'mes' => $mes ]) ->setFrom('general') ->addTo($sendTo); @@ -512,10 +514,10 @@ public function getStoreId() */ public function getCronExpr($schedule, $startTime) { - $ArTime = explode(',', $startTime); + $ArTime = explode(',', $startTime); $cronExprArray = [ - (int)$ArTime[1], // Minute - (int)$ArTime[0], // Hour + (int) $ArTime[1], // Minute + (int) $ArTime[0], // Hour $schedule === Schedule::CRON_MONTHLY ? 1 : '*', // Day of the Month '*', // Month of the Year $schedule === Schedule::CRON_WEEKLY ? 0 : '*', // Day of the Week @@ -562,5 +564,4 @@ public function isSuccess($code) { return (200 <= $code && 300 > $code); } - } From a91a807c59dab32d494dc3a2bdd7aa39fdf36fcd Mon Sep 17 00:00:00 2001 From: shin Date: Fri, 5 Mar 2021 18:01:04 +0700 Subject: [PATCH 4/6] Add shipping and billing address variables in the insert variable button. --- .../Adminhtml/Hook/Edit/Tab/Renderer/Body.php | 638 +++++++++--------- Helper/Data.php | 8 + view/adminhtml/templates/hook/body.phtml | 343 ++++++---- 3 files changed, 539 insertions(+), 450 deletions(-) diff --git a/Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php b/Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php index 93afc60..d2d7f26 100755 --- a/Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php +++ b/Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php @@ -1,308 +1,330 @@ -liquidFilters = $liquidFilters; - $this->orderFactory = $orderFactory; - $this->invoiceResource = $invoiceResource; - $this->shipmentResource = $shipmentResource; - $this->creditmemoResource = $creditmemoResource; - $this->hookFactory = $hookFactory; - $this->orderStatusResource = $orderStatusResource; - $this->customerResource = $customerResource; - $this->catalogEavAttribute = $catalogEavAttribute; - $this->categoryFactory = $categoryFactory; - $this->quoteResource = $quoteResource; - $this->subscriber = $subscriber; - - parent::__construct($context, $data); - } - - /** - * @param AbstractElement $element - * - * @return string - */ - public function render(AbstractElement $element) - { - $this->_element = $element; - - return $this->toHtml(); - } - - /** - * @return array - */ - - public function getHookType() - { - $type = $this->_request->getParam('type'); - if (!$type) { - $hookId = $this->getRequest()->getParam('hook_id'); - $hook = $this->hookFactory->create()->load($hookId); - $type = $hook->getHookType(); - } - if (!$type) { - $type = 'order'; - } - - return $type; - } - - /** - * @return array - * @throws LocalizedException - */ - public function getHookAttrCollection() - { - $hookType = $this->getHookType(); - - switch ($hookType) { - case HookType::NEW_ORDER_COMMENT: - $collectionData = $this->orderStatusResource->getConnection() - ->describeTable($this->orderStatusResource->getMainTable()); - $attrCollection = $this->getAttrCollectionFromDb($collectionData); - break; - case HookType::NEW_INVOICE: - $collectionData = $this->invoiceResource->getConnection() - ->describeTable($this->invoiceResource->getMainTable()); - $attrCollection = $this->getAttrCollectionFromDb($collectionData); - break; - case HookType::NEW_SHIPMENT: - $collectionData = $this->shipmentResource->getConnection() - ->describeTable($this->shipmentResource->getMainTable()); - $attrCollection = $this->getAttrCollectionFromDb($collectionData); - break; - case HookType::NEW_CREDITMEMO: - $collectionData = $this->creditmemoResource->getConnection() - ->describeTable($this->creditmemoResource->getMainTable()); - $attrCollection = $this->getAttrCollectionFromDb($collectionData); - break; - case HookType::NEW_CUSTOMER: - case HookType::UPDATE_CUSTOMER: - case HookType::DELETE_CUSTOMER: - case HookType::CUSTOMER_LOGIN: - $collectionData = $this->customerResource->loadAllAttributes()->getSortedAttributes(); - $attrCollection = $this->getAttrCollectionFromEav($collectionData); - break; - case HookType::NEW_PRODUCT: - case HookType::UPDATE_PRODUCT: - case HookType::DELETE_PRODUCT: - $collectionData = $this->catalogEavAttribute->getCollection() - ->addFieldToFilter(AttributeSet::KEY_ENTITY_TYPE_ID, 4); - $attrCollection = $this->getAttrCollectionFromEav($collectionData); - break; - case HookType::NEW_CATEGORY: - case HookType::UPDATE_CATEGORY: - case HookType::DELETE_CATEGORY: - $collectionData = $this->categoryFactory->create()->getAttributes(); - $attrCollection = $this->getAttrCollectionFromEav($collectionData); - break; - case HookType::ABANDONED_CART: - $collectionData = $this->quoteResource->getConnection() - ->describeTable($this->quoteResource->getMainTable()); - $attrCollection = $this->getAttrCollectionFromDb($collectionData); - break; - case HookType::SUBSCRIBER: - $collectionData = $this->subscriber->getConnection() - ->describeTable($this->subscriber->getMainTable()); - $attrCollection = $this->getAttrCollectionFromDb($collectionData); - break; - default: - $collectionData = $this->orderFactory->create()->getResource()->getConnection() - ->describeTable($this->orderFactory->create()->getResource()->getMainTable()); - $attrCollection = $this->getAttrCollectionFromDb($collectionData); - break; - } - - return $attrCollection; - } - - /** - * @param $collection - * - * @return array - */ - protected function getAttrCollectionFromDb($collection) - { - $attrCollection = []; - foreach ($collection as $item) { - $attrCollection[] = new DataObject([ - 'name' => $item['COLUMN_NAME'], - 'title' => ucwords(str_replace('_', ' ', $item['COLUMN_NAME'])) - ]); - } - - return $attrCollection; - } - - /** - * @param $collection - * - * @return array - */ - protected function getAttrCollectionFromEav($collection) - { - $attrCollection = []; - foreach ($collection as $item) { - $attrCollection[] = new DataObject([ - 'name' => $item->getAttributeCode(), - 'title' => $item->getDefaultFrontendLabel() - ]); - } - - return $attrCollection; - } - - /** - * @return array - */ - public function getModifier() - { - return $this->liquidFilters->getFilters(); - } -} +liquidFilters = $liquidFilters; + $this->orderFactory = $orderFactory; + $this->invoiceResource = $invoiceResource; + $this->shipmentResource = $shipmentResource; + $this->creditmemoResource = $creditmemoResource; + $this->hookFactory = $hookFactory; + $this->orderStatusResource = $orderStatusResource; + $this->customerResource = $customerResource; + $this->catalogEavAttribute = $catalogEavAttribute; + $this->categoryFactory = $categoryFactory; + $this->quoteResource = $quoteResource; + $this->subscriber = $subscriber; + $this->addressResource = $addressResource; + + parent::__construct($context, $data); + } + + /** + * @param AbstractElement $element + * + * @return string + */ + public function render(AbstractElement $element) + { + $this->_element = $element; + + return $this->toHtml(); + } + + /** + * @return array + */ + + public function getHookType() + { + $type = $this->_request->getParam('type'); + if (!$type) { + $hookId = $this->getRequest()->getParam('hook_id'); + $hook = $this->hookFactory->create()->load($hookId); + $type = $hook->getHookType(); + } + if (!$type) { + $type = 'order'; + } + + return $type; + } + + /** + * @return array + * @throws LocalizedException + */ + public function getHookAttrCollection() + { + $hookType = $this->getHookType(); + + switch ($hookType) { + case HookType::NEW_ORDER_COMMENT: + $collectionData = $this->orderStatusResource->getConnection() + ->describeTable($this->orderStatusResource->getMainTable()); + $attrCollection = $this->getAttrCollectionFromDb($collectionData); + break; + case HookType::NEW_INVOICE: + $collectionData = $this->invoiceResource->getConnection() + ->describeTable($this->invoiceResource->getMainTable()); + $attrCollection = $this->getAttrCollectionFromDb($collectionData); + break; + case HookType::NEW_SHIPMENT: + $collectionData = $this->shipmentResource->getConnection() + ->describeTable($this->shipmentResource->getMainTable()); + $attrCollection = $this->getAttrCollectionFromDb($collectionData); + break; + case HookType::NEW_CREDITMEMO: + $collectionData = $this->creditmemoResource->getConnection() + ->describeTable($this->creditmemoResource->getMainTable()); + $attrCollection = $this->getAttrCollectionFromDb($collectionData); + break; + case HookType::NEW_CUSTOMER: + case HookType::UPDATE_CUSTOMER: + case HookType::DELETE_CUSTOMER: + case HookType::CUSTOMER_LOGIN: + $collectionData = $this->customerResource->loadAllAttributes()->getSortedAttributes(); + $attrCollection = $this->getAttrCollectionFromEav($collectionData); + break; + case HookType::NEW_PRODUCT: + case HookType::UPDATE_PRODUCT: + case HookType::DELETE_PRODUCT: + $collectionData = $this->catalogEavAttribute->getCollection() + ->addFieldToFilter(AttributeSet::KEY_ENTITY_TYPE_ID, 4); + $attrCollection = $this->getAttrCollectionFromEav($collectionData); + break; + case HookType::NEW_CATEGORY: + case HookType::UPDATE_CATEGORY: + case HookType::DELETE_CATEGORY: + $collectionData = $this->categoryFactory->create()->getAttributes(); + $attrCollection = $this->getAttrCollectionFromEav($collectionData); + break; + case HookType::ABANDONED_CART: + $collectionData = $this->quoteResource->getConnection() + ->describeTable($this->quoteResource->getMainTable()); + $attrCollection = $this->getAttrCollectionFromDb($collectionData); + break; + case HookType::SUBSCRIBER: + $collectionData = $this->subscriber->getConnection() + ->describeTable($this->subscriber->getMainTable()); + $attrCollection = $this->getAttrCollectionFromDb($collectionData); + break; + default: + $collectionData = $this->orderFactory->create()->getResource()->getConnection() + ->describeTable($this->orderFactory->create()->getResource()->getMainTable()); + $attrCollection = $this->getAttrCollectionFromDb($collectionData); + break; + } + + return $attrCollection; + } + + /** + * @param $collection + * + * @return array + */ + protected function getAttrCollectionFromDb($collection) + { + $attrCollection = []; + foreach ($collection as $item) { + $attrCollection[] = new DataObject([ + 'name' => $item['COLUMN_NAME'], + 'title' => ucwords(str_replace('_', ' ', $item['COLUMN_NAME'])) + ]); + } + + return $attrCollection; + } + + /** + * @param $collection + * + * @return array + */ + protected function getAttrCollectionFromEav($collection) + { + $attrCollection = []; + foreach ($collection as $item) { + $attrCollection[] = new DataObject([ + 'name' => $item->getAttributeCode(), + 'title' => $item->getDefaultFrontendLabel() + ]); + } + + return $attrCollection; + } + + /** + * @return array + */ + public function getModifier() + { + return $this->liquidFilters->getFilters(); + } + + /** + * @return array + * @throws LocalizedException + */ + public function getShippingAddressAttrCollection() + { + $collectionData = $this->addressResource->getConnection() + ->describeTable($this->addressResource->getMainTable()); + $attrCollection = $this->getAttrCollectionFromDb($collectionData); + + return $attrCollection; + } +} diff --git a/Helper/Data.php b/Helper/Data.php index 0366523..c092959 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -271,6 +271,14 @@ public function generateLiquidTemplate($item, $templateHtml) $item->setStockItem(null); } + if ($item->getShippingAddress()) { + $item->setData('shippingAddress', $item->getShippingAddress()->getData()); + } + + if ($item->getBillingAddress()) { + $item->setData('billingAddress', $item->getBillingAddress()); + } + return $template->render([ 'item' => $item, ]); diff --git a/view/adminhtml/templates/hook/body.phtml b/view/adminhtml/templates/hook/body.phtml index 72e30d4..f428b05 100755 --- a/view/adminhtml/templates/hook/body.phtml +++ b/view/adminhtml/templates/hook/body.phtml @@ -1,142 +1,201 @@ - -getElement(); -$note = $element->getNote() ? '
' . $element->getNote() . '
' : ''; -$elementBeforeLabel = $element->getExtType() == 'checkbox' || $element->getExtType() == 'radio'; -$addOn = $element->getBeforeElementHtml() || $element->getAfterElementHtml(); -$fieldId = ($element->getHtmlContainerId()) ? ' id="' . $element->getHtmlContainerId() . '"' : ''; -$fieldClass = "admin__field field field-{$element->getId()} {$element->getCssClass()}"; -$fieldClass .= ($elementBeforeLabel) ? ' choice' : ''; -$fieldClass .= ($addOn) ? ' with-addon' : ''; -$fieldClass .= ($element->getRequired()) ? ' _required' : ''; -$fieldClass .= ($note) ? ' with-note' : ''; - -$fieldAttributes = $fieldId . ' class="' . $fieldClass . '" ' . $block->getUiId('form-field', $element->getId()); -$modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonEncode($block->getModifier()) : '{}'; -?> - -getNoDisplay()): ?> - getType() == 'hidden'): ?> - getElementHtml() ?> - - > - - getElementHtml() ?> - getLabelHtml('', $element->getScopeLabel()) ?> - - - getLabelHtml('', $element->getScopeLabel()) ?> -
-
- -
-
- - ' . $element->getElementHtml() . '
' : $element->getElementHtml(); ?> - getHintHtml() ?> - -
-
- -
-
-
- - - - - - -
- getHookAttrCollection() ?: []; ?> -
-
- - -
- - -
- - -
-
- - - - -
-
-
-
-
- -
-
- -
- + +getElement(); +$note = $element->getNote() ? '
' . $element->getNote() . '
' : ''; +$elementBeforeLabel = $element->getExtType() == 'checkbox' || $element->getExtType() == 'radio'; +$addOn = $element->getBeforeElementHtml() || $element->getAfterElementHtml(); +$fieldId = ($element->getHtmlContainerId()) ? ' id="' . $element->getHtmlContainerId() . '"' : ''; +$fieldClass = "admin__field field field-{$element->getId()} {$element->getCssClass()}"; +$fieldClass .= ($elementBeforeLabel) ? ' choice' : ''; +$fieldClass .= ($addOn) ? ' with-addon' : ''; +$fieldClass .= ($element->getRequired()) ? ' _required' : ''; +$fieldClass .= ($note) ? ' with-note' : ''; + +$fieldAttributes = $fieldId . ' class="' . $fieldClass . '" ' . $block->getUiId('form-field', $element->getId()); +$modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonEncode($block->getModifier()) : '{}'; +?> + +getNoDisplay()) : ?> + getType() == 'hidden') : ?> + getElementHtml() ?> + + > + + getElementHtml() ?> + getLabelHtml('', $element->getScopeLabel()) ?> + escapeHtml($note) ?> + + getLabelHtml('', $element->getScopeLabel()) ?> +
+
+ +
+
+ escapeHtml(__('Insert Variables')) ?> + ' . $element->getElementHtml() + . '
' : $element->getElementHtml(); ?> + getHintHtml() ?> + escapeHtml($note) ?> +
+
+ +
+
+
+ + + + + + +
+ getHookAttrCollection() ?: []; ?> +
+
+ + + escapeHtml(__('Item Attribute')) ?> + +
+ + +
+ + +
+
+ + + + +
+
+
+
+
+ +
+
+
+
+ + + escapeHtml(__('Shipping Address Attribute')) ?> + +
+ + +
+ getShippingAddressAttrCollection() as $attr) : ?> + +
+
+ + + + +
+
+
+
+
+ +
+
+
+
+ + + escapeHtml(__('Billing Address Attribute')) ?> + +
+ + +
+ getShippingAddressAttrCollection() as $attr) : ?> + +
+
+ + + + +
+
+
+
+
+ +
+
+ +
+ From 7fe130a1a5b5bad544cd9a9cf8dbc3cf0759f322 Mon Sep 17 00:00:00 2001 From: shin Date: Thu, 15 Apr 2021 11:20:42 +0700 Subject: [PATCH 5/6] compatible magento 2.4.2 --- Controller/Adminhtml/Logs/Replay.php | 5 +++-- i18n/en_US.csv | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Controller/Adminhtml/Logs/Replay.php b/Controller/Adminhtml/Logs/Replay.php index dbc6932..ffc708e 100644 --- a/Controller/Adminhtml/Logs/Replay.php +++ b/Controller/Adminhtml/Logs/Replay.php @@ -103,8 +103,9 @@ public function execute() $log->setStatus(Status::SUCCESS)->setMessage(''); $this->messageManager->addSuccess(__('The log has been replay successful.')); } else { - $this->messageManager->addError($result['message']); - $log->setStatus(Status::ERROR)->setMessage($result['message']); + $message = __('Cannot replay the log, Please try again later.'); + $this->messageManager->addError($message); + $log->setStatus(Status::ERROR)->setMessage($message); } $log->save(); diff --git a/i18n/en_US.csv b/i18n/en_US.csv index aa394b7..6cbb0cf 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -163,3 +163,4 @@ Replay,Replay "Created Date","Created Date" "Updated Date","Updated Date" Edit,Edit +"Cannot replay the log, Please try again later.","Cannot replay the log, Please try again later." From f4ab4e42a1a254ed764451e84d42f15204dfd827 Mon Sep 17 00:00:00 2001 From: shin Date: Wed, 26 May 2021 09:30:40 +0700 Subject: [PATCH 6/6] update composer --- composer.json | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 8d54eb6..8e0f282 100644 --- a/composer.json +++ b/composer.json @@ -1,27 +1,27 @@ -{ - "name": "mageplaza/module-webhook", - "description": "Magento 2 Webhook Extension", - "require": { - "mageplaza/module-core": "^1.4.5", - "liquid/liquid": "^1.4.8" - }, - "type": "magento2-module", - "version": "4.0.0", - "license": "proprietary", - "authors": [ - { - "name": "Mageplaza", - "email": "support@mageplaza.com", - "homepage": "https://www.mageplaza.com", - "role": "Technical Support" - } - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Mageplaza\\Webhook\\": "" - } - } -} +{ + "name": "mageplaza/module-webhook", + "description": "Magento 2 Webhook Extension", + "require": { + "mageplaza/module-core": "^1.4.5", + "liquid/liquid": "^1.4.8" + }, + "type": "magento2-module", + "version": "4.1.0", + "license": "proprietary", + "authors": [ + { + "name": "Mageplaza", + "email": "support@mageplaza.com", + "homepage": "https://www.mageplaza.com", + "role": "Technical Support" + } + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Mageplaza\\Webhook\\": "" + } + } +}