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 #70 from mageplaza/2.3-develop
Browse files Browse the repository at this point in the history
2.3-develop
  • Loading branch information
Shinichi69 authored May 26, 2021
2 parents 61050ec + fda8244 commit e875946
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 53 deletions.
22 changes: 22 additions & 0 deletions Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Magento\Newsletter\Model\ResourceModel\Subscriber;
use Magento\Quote\Model\ResourceModel\Quote;
use Magento\Sales\Model\OrderFactory;
use Magento\Sales\Model\ResourceModel\Order\Address;
use Magento\Sales\Model\ResourceModel\Order\Creditmemo as CreditmemoResource;
use Magento\Sales\Model\ResourceModel\Order\Invoice as InvoiceResource;
use Magento\Sales\Model\ResourceModel\Order\Shipment as ShipmentResource;
Expand Down Expand Up @@ -112,6 +113,11 @@ class Body extends Element
*/
protected $subscriber;

/**
* @var Address
*/
protected $addressResource;

/**
* Body constructor.
*
Expand All @@ -128,6 +134,7 @@ class Body extends Element
* @param LiquidFilters $liquidFilters
* @param HookFactory $hookFactory
* @param Subscriber $subscriber
* @param Address $addressResource
* @param array $data
*/
public function __construct(
Expand All @@ -144,6 +151,7 @@ public function __construct(
LiquidFilters $liquidFilters,
HookFactory $hookFactory,
Subscriber $subscriber,
Address $addressResource,
array $data = []
) {
$this->liquidFilters = $liquidFilters;
Expand All @@ -158,6 +166,7 @@ public function __construct(
$this->categoryFactory = $categoryFactory;
$this->quoteResource = $quoteResource;
$this->subscriber = $subscriber;
$this->addressResource = $addressResource;

parent::__construct($context, $data);
}
Expand Down Expand Up @@ -305,4 +314,17 @@ 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;
}
}
15 changes: 12 additions & 3 deletions Controller/Adminhtml/ManageHooks/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Mageplaza\Webhook\Helper\Data;
use Mageplaza\Webhook\Model\HookFactory;
use RuntimeException;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class Save
Expand All @@ -44,21 +45,29 @@ class Save extends AbstractManageHooks
*/
protected $helperData;

/**
* @var StoreManagerInterface
*/
protected $_storeManager;

/**
* Save constructor.
*
* @param HookFactory $hookFactory
* @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);
}
Expand All @@ -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']);
}

Expand Down
20 changes: 19 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down Expand Up @@ -325,7 +333,7 @@ public function sendHttpRequest($headers, $authentication, $contentType, $url, $
$result['response'] = $resultCurl;
if (!empty($resultCurl)) {
$result['status'] = Zend_Http_Response::extractCode($resultCurl);
if (isset($result['status']) && in_array($result['status'], [200, 201])) {
if (isset($result['status']) && $this->isSuccess($result['status'])) {
$result['success'] = true;
} else {
$result['message'] = __('Cannot connect to server. Please try again later.');
Expand Down Expand Up @@ -554,4 +562,14 @@ public function getObjectClass($classPath)
{
return $this->objectManager->create($classPath);
}

/**
* @param $code
*
* @return bool
*/
public function isSuccess($code)
{
return (200 <= $code && 300 > $code);
}
}
54 changes: 27 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "1.2.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": "1.3.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\\": ""
}
}
}
103 changes: 81 additions & 22 deletions view/adminhtml/templates/hook/body.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ $fieldAttributes = $fieldId . ' class="' . $fieldClass . '" ' . $block->getUiId(
$modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonEncode($block->getModifier()) : '{}';
?>

<?php if (!$element->getNoDisplay()): ?>
<?php if ($element->getType() == 'hidden'): ?>
<?php if (!$element->getNoDisplay()) : ?>
<?php if ($element->getType() == 'hidden') : ?>
<?= $element->getElementHtml() ?>
<?php else: ?>
<div<?= $fieldAttributes ?>>
<?php if ($elementBeforeLabel): ?>
<?php else : ?>
<div<?= /** @noEscape */ $fieldAttributes ?>>
<?php if ($elementBeforeLabel) : ?>
<?= $element->getElementHtml() ?>
<?= $element->getLabelHtml('', $element->getScopeLabel()) ?>
<?= $note ?>
<?php else: ?>
<?= $block->escapeHtml($note) ?>
<?php else : ?>
<?= $element->getLabelHtml('', $element->getScopeLabel()) ?>
<div class="admin__field-control control">
<div id="grid_tab" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
Expand All @@ -56,15 +56,15 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE
aria-selected="true">
<a href="#grid_tab_body_content" id="grid_tab_body" title="Body" class="ui-tabs-anchor"
data-tab-type="" role="presentation" tabindex="-1">
<span><?= __('Body') ?></span>
<span><?= $block->escapeHtml(__('Body')) ?></span>
</a>
</li>
<li class="ui-state-default ui-corner-top" role="tab" tabindex="-1"
aria-controls="grid_tab_preview_content" aria-labelledby="grid_tab_preview"
aria-selected="false">
<a href="#grid_tab_preview_content" id="grid_tab_preview" title="Preview"
class="ui-tabs-anchor" data-tab-type="" role="presentation" tabindex="-1">
<span><?= __('Preview') ?></span>
<span><?= $block->escapeHtml(__('Preview')) ?></span>
</a>
</li>
</ul>
Expand All @@ -73,15 +73,17 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE
aria-labelledby="grid_tab_body" class="ui-widget-content ui-corner-bottom"
role="tabpanel" aria-expanded="true" aria-hidden="false">
<a id="insert-variable" style="float: right;margin-top: -53px;margin-right: -20px;"
class="btn"><?= __('Insert Variables') ?></a>
<?= $addOn ? '<div class="addon">' . $element->getElementHtml() . '</div>' : $element->getElementHtml(); ?>
class="btn"><?= $block->escapeHtml(__('Insert Variables')) ?></a>
<?= $addOn ? '<div class="addon">' . $element->getElementHtml()
. '</div>' : $element->getElementHtml(); ?>
<?= $block->getHintHtml() ?>
<?= $note ?>
<?= $block->escapeHtml($note) ?>
</div>
<div id="grid_tab_preview_content" style="border-top: 1px solid #adadad;"
aria-labelledby="grid_tab_body" class="ui-widget-content ui-corner-bottom"
role="tabpanel" aria-expanded="true" aria-hidden="false">
<textarea style="width: 100%" name="hook[preview]" title="preview" id="hook_preview"></textarea>
<textarea style="width: 100%" name="hook[preview]" title="preview" id="hook_preview">
</textarea>
</div>
</div>
</div>
Expand All @@ -103,22 +105,78 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE
<div class="entry-edit-head admin__collapsible-block">
<span id="ox_variable_item-link" class="entry-edit-head-link"></span>
<a id="ox_variable_item-head" href="#ox_variable_item-link"
onclick="Fieldset.toggleCollapse('ox_variable_item'); return false;"><?= __('Item Attribute') ?></a>
onclick="Fieldset.toggleCollapse('ox_variable_item'); return false;">
<?= $block->escapeHtml(__('Item Attribute')) ?>
</a>
</div>
<input id="ox_variable_item-state" value="1" type="hidden">

<fieldset class="config admin__collapsible-block admin__scope-old" id="ox_variable_item">
<?php foreach ($attrCollection as $attr): ?>
<?php foreach ($attrCollection as $attr) : ?>
<?php /** @var \Magento\Eav\Model\Entity\Attribute $attr */ ?>
<div class="attr-code" id="<?= $attr->getName() ?>" code="<?= $attr->getName() ?>">
<div class="attr-code" id="<?= $block->escapeHtmlAttr($attr->getName()) ?>" code="<?= $block->escapeHtmlAttr($attr->getName()) ?>">
<div class="row">
<label class="attr-code-label"><?= $attr->getTitle() . " ({$attr->getName()})"; ?></label>
<button class="insert"><?= __('Add') ?></button>
<button class="add-modifier"><?= __('Add Filter') ?></button>
<label class="liquid-variable">{{ <?= 'item.' . $attr->getName() ?> }}</label>
<label class="attr-code-label"><?= $block->escapeHtml($attr->getTitle() . " ({$attr->getName()})") ?></label>
<button class="insert"><?= $block->escapeHtml(__('Add')) ?></button>
<button class="add-modifier"><?= $block->escapeHtml(__('Add Filter')) ?></button>
<label class="liquid-variable">{{ <?= 'item.' . $block->escapeHtml($attr->getName()) ?> }}</label>
</div>
<div class="row-modifier data-table">
<div class="modifier-group" code="<?= $attr->getName() ?>"></div>
<div class="modifier-group" code="<?= $block->escapeHtmlAttr($attr->getName()) ?>"></div>
</div>
</div>
<?php endforeach; ?>
</fieldset>
</div>
<div class="section-config">
<div class="entry-edit-head admin__collapsible-block">
<span id="ox_variable_shipping_address-link" class="entry-edit-head-link"></span>
<a id="ox_variable_shipping_address-head" href="#ox_variable_shipping_address-link"
onclick="Fieldset.toggleCollapse('ox_variable_shipping_address'); return false;">
<?= $block->escapeHtml(__('Shipping Address Attribute')) ?>
</a>
</div>
<input id="ox_variable_shipping-state" value="1" type="hidden">

<fieldset class="config admin__collapsible-block admin__scope-old" id="ox_variable_shipping_address">
<?php foreach ($block->getShippingAddressAttrCollection() as $attr) : ?>
<?php /** @var \Magento\Eav\Model\Entity\Attribute $attr */ ?>
<div class="attr-code" id="<?= $block->escapeHtmlAttr($attr->getName()) ?>" code="<?= $block->escapeHtmlAttr($attr->getName()) ?>">
<div class="row">
<label class="attr-code-label"><?= $block->escapeHtml($attr->getTitle() . " ({$attr->getName()})") ?></label>
<button class="insert"><?= $block->escapeHtml(__('Add')) ?></button>
<button class="add-modifier"><?= $block->escapeHtml(__('Add Filter')) ?></button>
<label class="liquid-variable">{{ <?= 'item.shippingAddress.' . $block->escapeHtml($attr->getName()) ?> }}</label>
</div>
<div class="row-modifier data-table">
<div class="modifier-group" code="<?= $block->escapeHtmlAttr($attr->getName()) ?>"></div>
</div>
</div>
<?php endforeach; ?>
</fieldset>
</div>
<div class="section-config">
<div class="entry-edit-head admin__collapsible-block">
<span id="ox_variable_billing_address-link" class="entry-edit-head-link"></span>
<a id="ox_variable_billing_address-head" href="#ox_variable_billing_address-link"
onclick="Fieldset.toggleCollapse('ox_variable_billing_address'); return false;">
<?= $block->escapeHtml(__('Billing Address Attribute')) ?>
</a>
</div>
<input id="ox_variable_billing-state" value="1" type="hidden">

<fieldset class="config admin__collapsible-block admin__scope-old" id="ox_variable_shipping_address">
<?php foreach ($block->getShippingAddressAttrCollection() as $attr) : ?>
<?php /** @var \Magento\Eav\Model\Entity\Attribute $attr */ ?>
<div class="attr-code" id="<?= $block->escapeHtmlAttr($attr->getName()) ?>" code="<?= $block->escapeHtmlAttr($attr->getName()) ?>">
<div class="row">
<label class="attr-code-label"><?= $block->escapeHtml($attr->getTitle() . " ({$attr->getName()})") ?></label>
<button class="insert"><?= $block->escapeHtml(__('Add')) ?></button>
<button class="add-modifier"><?= $block->escapeHtml(__('Add Filter')) ?></button>
<label class="liquid-variable">{{ <?= 'item.billingAddress.' . $block->escapeHtml($attr->getName()) ?> }}</label>
</div>
<div class="row-modifier data-table">
<div class="modifier-group" code="<?= $block->escapeHtmlAttr($attr->getName()) ?>"></div>
</div>
</div>
<?php endforeach; ?>
Expand All @@ -127,6 +185,7 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE
<script type="text/javascript">//<![CDATA[
require(['prototype'], function () {
Fieldset.applyCollapse('ox_variable_item');
Fieldset.applyCollapse('ox_variable_shipping_address');
});
//]]>
</script>
Expand All @@ -135,7 +194,7 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE
{
"*": {
"Mageplaza_Webhook/js/hook/initActionsTab":{
"modifiersData": <?= $modifiersData ?>
"modifiersData": <?= /** @noEscape */ $modifiersData ?>
}
}
}
Expand Down

0 comments on commit e875946

Please sign in to comment.