Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #45 from mageplaza/2.3-develop
Browse files Browse the repository at this point in the history
Clean code
  • Loading branch information
haitv282 authored Oct 13, 2020
2 parents 914046a + af7eac7 commit 61050ec
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 143 deletions.
6 changes: 3 additions & 3 deletions Block/Adminhtml/Hook/Edit/Tab/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ protected function _prepareForm()

if ($this->_request->getParam('type') === HookType::ORDER || $hook->getHookType() === HookType::ORDER) {
$fieldset->addField('order_status', 'multiselect', [
'name' => 'order_status',
'label' => __('Order Status'),
'title' => __('Order Status'),
'name' => 'order_status',
'label' => __('Order Status'),
'title' => __('Order Status'),
'values' => $this->orderStatus->toOptionArray()
]);
}
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Logs/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected function _construct()
* Get replay action URL
*
* @param $log
*
* @return string
*/
protected function getReplayUrl($log)
Expand Down
6 changes: 3 additions & 3 deletions Block/Adminhtml/Logs/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ protected function _prepareForm()
]);

$fieldset->addField('body', 'textarea', [
'name' => 'body',
'label' => __('Request Body'),
'title' => __('Request Body')
'name' => 'body',
'label' => __('Request Body'),
'title' => __('Request Body')
]);

$form->addValues($log->getData());
Expand Down
8 changes: 5 additions & 3 deletions Controller/Adminhtml/Logs/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

namespace Mageplaza\Webhook\Controller\Adminhtml\Logs;

use Exception;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Mageplaza\Webhook\Controller\Adminhtml\AbstractManageLogs;
use Mageplaza\Webhook\Model\History;
use RuntimeException;

/**
* Class Save
Expand All @@ -40,7 +42,7 @@ class Save extends AbstractManageLogs
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$data = $this->getRequest()->getPost('log');
$data = $this->getRequest()->getPost('log');
/** @var History $log */
$log = $this->initLog();

Expand All @@ -53,9 +55,9 @@ public function execute()
$this->_getSession()->setData('mageplaza_webhook_log', false);
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\RuntimeException $e) {
} catch (RuntimeException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
} catch (Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while saving the Log.'));
}

Expand Down
10 changes: 6 additions & 4 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public function __construct(
*/
public function getItemStore($item)
{
if (method_exists($item,'getData')) {
return $item->getData('store_id') ? : $this->storeManager->getStore()->getId();
if (method_exists($item, 'getData')) {
return $item->getData('store_id') ?: $this->storeManager->getStore()->getId();
}

return $this->storeManager->getStore()->getId();
Expand All @@ -145,6 +145,7 @@ public function getItemStore($item)
/**
* @param $item
* @param $hookType
*
* @throws LocalizedException
* @throws NoSuchEntityException
*/
Expand All @@ -167,7 +168,7 @@ public function send($item, $hookType)
$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;
Expand Down Expand Up @@ -267,7 +268,7 @@ public function generateLiquidTemplate($item, $templateHtml)
$template->parse($templateHtml, $filtersMethods);

if ($item instanceof Product) {
$item->setStockItem(NULL);
$item->setStockItem(null);
}

return $template->render([
Expand Down Expand Up @@ -392,6 +393,7 @@ public function getBasicAuthHeader($username, $password)
/**
* @param $item
* @param $hookType
*
* @throws LocalizedException
* @throws NoSuchEntityException
*/
Expand Down
21 changes: 10 additions & 11 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

namespace Mageplaza\Webhook\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Mageplaza\Webhook\Model\CronScheduleFactory;
use Mageplaza\Webhook\Model\HistoryFactory;
use Mageplaza\Webhook\Model\HookFactory;
Expand Down Expand Up @@ -56,8 +56,7 @@ public function __construct(
HookFactory $hookFactory,
CronScheduleFactory $cronScheduleFactory,
HistoryFactory $historyFactory
)
{
) {
$this->hookFactory = $hookFactory;
$this->cronScheduleFactory = $cronScheduleFactory;
$this->historyFactory = $historyFactory;
Expand All @@ -68,10 +67,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
if (version_compare($context->getVersion(), '1.0.2', '<')) {
/**
* Update hook type of mageplaza_webhook_hook table
*/
*/
$hookCollections = $this->hookFactory->create()->getCollection()
->addFieldToFilter('hook_type', array('eq' => 'new_order'));
foreach($hookCollections as $hook) {
->addFieldToFilter('hook_type', ['eq' => 'new_order']);
foreach ($hookCollections as $hook) {
$hook->setHookType('order');
}

Expand All @@ -81,8 +80,8 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
* Update hook type of mageplaza_webhook_cron_schedule table
*/
$cronScheduleCollections = $this->cronScheduleFactory->create()->getCollection()
->addFieldToFilter('hook_type', array('eq' => 'new_order'));
foreach($cronScheduleCollections as $cronSchedule) {
->addFieldToFilter('hook_type', ['eq' => 'new_order']);
foreach ($cronScheduleCollections as $cronSchedule) {
$cronSchedule->setHookType('order');
}

Expand All @@ -92,8 +91,8 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
* Update hook type of mageplaza_webhook_history table
*/
$historyCollections = $this->historyFactory->create()->getCollection()
->addFieldToFilter('hook_type', array('eq' => 'new_order'));
foreach($historyCollections as $history) {
->addFieldToFilter('hook_type', ['eq' => 'new_order']);
foreach ($historyCollections as $history) {
$history->setHookType('order');
}

Expand Down
14 changes: 8 additions & 6 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
}
}

if(version_compare($context->getVersion(), '1.0.2', '<')) {
$tableName = $installer->getTable( 'mageplaza_webhook_hook' );
if (version_compare($context->getVersion(), '1.0.2', '<')) {
$tableName = $installer->getTable('mageplaza_webhook_hook');
$installer->getConnection()
->addColumn($tableName,'order_status',
->addColumn(
$tableName,
'order_status',
[
'type' => Table::TYPE_TEXT,
'length' => 255,
'type' => Table::TYPE_TEXT,
'length' => 255,
'comment' => 'Order Status',
'after' => 'status'
'after' => 'status'
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"liquid/liquid": "^1.4.8"
},
"type": "magento2-module",
"version": "1.1.3",
"version": "1.2.0",
"license": "proprietary",
"authors": [
{
Expand Down
150 changes: 75 additions & 75 deletions etc/events.xml
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
<?xml version="1.0"?>
<!--
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Webhook
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_save_before">
<observer name="mp_wh_save_order_before" instance="Mageplaza\Webhook\Observer\BeforeSave"/>
</event>
<event name="sales_order_save_after">
<observer name="mp_wh_order" instance="Mageplaza\Webhook\Observer\AfterOrder"/>
</event>
<event name="sales_order_status_history_save_after">
<observer name="mp_wh_before_order" instance="Mageplaza\Webhook\Observer\AfterOrderComment"/>
</event>
<event name="sales_order_invoice_save_after">
<observer name="mp_wh_new_invoice" instance="Mageplaza\Webhook\Observer\AfterInvoice"/>
</event>
<event name="sales_order_shipment_save_after">
<observer name="mp_wh_new_shipment" instance="Mageplaza\Webhook\Observer\AfterShipment"/>
</event>
<event name="sales_order_creditmemo_save_after">
<observer name="mp_wh_new_creditmemo" instance="Mageplaza\Webhook\Observer\AfterCreditmemo"/>
</event>
<event name="customer_save_before">
<observer name="mp_wh_save_customer_before" instance="Mageplaza\Webhook\Observer\BeforeSave"/>
</event>
<event name="customer_save_after">
<observer name="mp_wh_new_customer" instance="Mageplaza\Webhook\Observer\AfterCustomer"/>
</event>
<event name="customer_delete_before">
<observer name="mp_wh_delete_customer" instance="Mageplaza\Webhook\Observer\BeforeDeleteCustomer"/>
</event>
<event name="catalog_product_save_before">
<observer name="mp_wh_product_save_before" instance="Mageplaza\Webhook\Observer\BeforeSave"/>
</event>
<event name="catalog_product_save_after">
<observer name="mp_wh_new_product" instance="Mageplaza\Webhook\Observer\AfterProduct"/>
</event>
<event name="catalog_product_delete_before">
<observer name="mp_wh_delete_product" instance="Mageplaza\Webhook\Observer\BeforeDeleteProduct"/>
</event>
<event name="catalog_category_save_before">
<observer name="mp_wh_category_save_before" instance="Mageplaza\Webhook\Observer\BeforeSave"/>
</event>
<event name="catalog_category_save_after">
<observer name="mp_wh_category_save_after" instance="Mageplaza\Webhook\Observer\AfterCategory"/>
</event>
<event name="catalog_category_delete_before">
<observer name="mp_wh_delete_product" instance="Mageplaza\Webhook\Observer\BeforeDeleteCategory"/>
</event>
<event name="customer_login">
<observer name="mp_wh_customer_login" instance="Mageplaza\Webhook\Observer\CustomerLogin"/>
</event>
<event name="newsletter_subscriber_save_after">
<observer name="mp_wh_subscriber" instance="Mageplaza\Webhook\Observer\Subscriber"/>
</event>
</config>
<?xml version="1.0"?>
<!--
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Webhook
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_save_before">
<observer name="mp_wh_save_order_before" instance="Mageplaza\Webhook\Observer\BeforeSave"/>
</event>
<event name="sales_order_save_after">
<observer name="mp_wh_order" instance="Mageplaza\Webhook\Observer\AfterOrder"/>
</event>
<event name="sales_order_status_history_save_after">
<observer name="mp_wh_before_order" instance="Mageplaza\Webhook\Observer\AfterOrderComment"/>
</event>
<event name="sales_order_invoice_save_after">
<observer name="mp_wh_new_invoice" instance="Mageplaza\Webhook\Observer\AfterInvoice"/>
</event>
<event name="sales_order_shipment_save_after">
<observer name="mp_wh_new_shipment" instance="Mageplaza\Webhook\Observer\AfterShipment"/>
</event>
<event name="sales_order_creditmemo_save_after">
<observer name="mp_wh_new_creditmemo" instance="Mageplaza\Webhook\Observer\AfterCreditmemo"/>
</event>
<event name="customer_save_before">
<observer name="mp_wh_save_customer_before" instance="Mageplaza\Webhook\Observer\BeforeSave"/>
</event>
<event name="customer_save_after">
<observer name="mp_wh_new_customer" instance="Mageplaza\Webhook\Observer\AfterCustomer"/>
</event>
<event name="customer_delete_before">
<observer name="mp_wh_delete_customer" instance="Mageplaza\Webhook\Observer\BeforeDeleteCustomer"/>
</event>
<event name="catalog_product_save_before">
<observer name="mp_wh_product_save_before" instance="Mageplaza\Webhook\Observer\BeforeSave"/>
</event>
<event name="catalog_product_save_after">
<observer name="mp_wh_new_product" instance="Mageplaza\Webhook\Observer\AfterProduct"/>
</event>
<event name="catalog_product_delete_before">
<observer name="mp_wh_delete_product" instance="Mageplaza\Webhook\Observer\BeforeDeleteProduct"/>
</event>
<event name="catalog_category_save_before">
<observer name="mp_wh_category_save_before" instance="Mageplaza\Webhook\Observer\BeforeSave"/>
</event>
<event name="catalog_category_save_after">
<observer name="mp_wh_category_save_after" instance="Mageplaza\Webhook\Observer\AfterCategory"/>
</event>
<event name="catalog_category_delete_before">
<observer name="mp_wh_delete_product" instance="Mageplaza\Webhook\Observer\BeforeDeleteCategory"/>
</event>
<event name="customer_login">
<observer name="mp_wh_customer_login" instance="Mageplaza\Webhook\Observer\CustomerLogin"/>
</event>
<event name="newsletter_subscriber_save_after">
<observer name="mp_wh_subscriber" instance="Mageplaza\Webhook\Observer\Subscriber"/>
</event>
</config>
Loading

0 comments on commit 61050ec

Please sign in to comment.