diff --git a/Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php b/Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php index be2eebe..d2d7f26 100755 --- a/Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php +++ b/Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php @@ -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; @@ -112,6 +113,11 @@ class Body extends Element */ protected $subscriber; + /** + * @var Address + */ + protected $addressResource; + /** * Body constructor. * @@ -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( @@ -144,6 +151,7 @@ public function __construct( LiquidFilters $liquidFilters, HookFactory $hookFactory, Subscriber $subscriber, + Address $addressResource, array $data = [] ) { $this->liquidFilters = $liquidFilters; @@ -158,6 +166,7 @@ public function __construct( $this->categoryFactory = $categoryFactory; $this->quoteResource = $quoteResource; $this->subscriber = $subscriber; + $this->addressResource = $addressResource; parent::__construct($context, $data); } @@ -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; + } } 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']); } diff --git a/Helper/Data.php b/Helper/Data.php index 94330c7..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, ]); @@ -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.'); @@ -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); + } } diff --git a/composer.json b/composer.json index fd28168..1b8e436 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": "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\\": "" + } + } +} diff --git a/view/adminhtml/templates/hook/body.phtml b/view/adminhtml/templates/hook/body.phtml index 97e66cb..f428b05 100755 --- a/view/adminhtml/templates/hook/body.phtml +++ b/view/adminhtml/templates/hook/body.phtml @@ -36,16 +36,16 @@ $fieldAttributes = $fieldId . ' class="' . $fieldClass . '" ' . $block->getUiId( $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonEncode($block->getModifier()) : '{}'; ?> -getNoDisplay()): ?> - getType() == 'hidden'): ?> +getNoDisplay()) : ?> + getType() == 'hidden') : ?> getElementHtml() ?> - - > - + + > + getElementHtml() ?> getLabelHtml('', $element->getScopeLabel()) ?> - - + escapeHtml($note) ?> + getLabelHtml('', $element->getScopeLabel()) ?>
@@ -56,7 +56,7 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE aria-selected="true"> - + escapeHtml(__('Body')) ?> @@ -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"> - ' . $element->getElementHtml() . '
' : $element->getElementHtml(); ?> + class="btn">escapeHtml(__('Insert Variables')) ?> + ' . $element->getElementHtml() + . '
' : $element->getElementHtml(); ?> getHintHtml() ?> - + escapeHtml($note) ?>
- +
@@ -103,22 +105,78 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE
+ onclick="Fieldset.toggleCollapse('ox_variable_item'); return false;"> + escapeHtml(__('Item Attribute')) ?> +
- + -
+
- - - - + + + +
-
+
+
+
+ +
+ +
+
+ + + escapeHtml(__('Shipping Address Attribute')) ?> + +
+ + +
+ getShippingAddressAttrCollection() as $attr) : ?> + +
+
+ + + + +
+
+
+
+
+ +
+
+
+
+ + + escapeHtml(__('Billing Address Attribute')) ?> + +
+ + +
+ getShippingAddressAttrCollection() as $attr) : ?> + +
+
+ + + + +
+
+
@@ -127,6 +185,7 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE @@ -135,7 +194,7 @@ $modifiersData = $block->getModifier() ? \Mageplaza\Webhook\Helper\Data::jsonE { "*": { "Mageplaza_Webhook/js/hook/initActionsTab":{ - "modifiersData": + "modifiersData": } } }