Created
May 6, 2020 19:28
-
-
Save wpoortman/a8f492c7a0e16dfc91527059688aa49d to your computer and use it in GitHub Desktop.
Magento 2 - Webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Vendor\Namespace\Model\Converter; | |
use MageHook\Hook\Model\ConverterInterface; | |
/** | |
* Class OrderConverter | |
* | |
* @package Vendor\Namespace\Model\Converter | |
*/ | |
class OrderConverter implements ConverterInterface | |
{ | |
public function convert(array $data): array | |
{ | |
$data['entry'] = true; | |
return $data; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace MageHook\HookEventsSales\Event\Options; | |
use MageHook\Hook\Event\Options\AbstractValidator; | |
/** | |
* Class OrderStateChangeValidator | |
* | |
* @package Vendor\Namespace\Event\Options | |
*/ | |
class OrderStateChangeValidator extends AbstractValidator | |
{ | |
/** | |
* @inheritdoc | |
*/ | |
public function validate(): bool | |
{ | |
/** @var OrderInterface $order */ | |
$order = $this->getResource(); | |
return $order->getTotalItemCount() !== 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:noNamespaceSchemaLocation="urn:magento:module:MageHook_Hook/etc/webhooks.xsd"> | |
<hook event="order_state_change" | |
title="Order State Change" | |
group="Sales" | |
service="Magento\Sales\Api\Data\OrderInterface" | |
converter="Vendor\Namespace\Model\Converter\OrderConverter" | |
validator="Vendor\Namespace\Event\Options\OrderStateChangeValidator"/> | |
</config> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment