add check for the existence of an event and add orm tomodule
This commit is contained in:
parent
200da19ebb
commit
1fadd66791
3 changed files with 249 additions and 31 deletions
|
@ -26,6 +26,7 @@ use Bitrix\Sale\Internals\OrderTable;
|
|||
use \RetailCrm\ApiClient;
|
||||
use RetailCrm\Exception\CurlException;
|
||||
use Intaro\RetailCrm\Component\Loyalty\EventsHandlers;
|
||||
use Intaro\RetailCrm\Model\Bitrix\ORM\ToModuleTable;
|
||||
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
if (class_exists('intaro_retailcrm')) {
|
||||
|
@ -43,15 +44,15 @@ class intaro_retailcrm extends CModule
|
|||
* @var string[][]
|
||||
*/
|
||||
private const SUBSCRIBE_LP_EVENTS = [
|
||||
['EVENT_NAME' => 'OnBeforeSalePaymentSetField', 'MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnBeforeEndBufferContent', 'MODULE' => 'main'],
|
||||
['EVENT_NAME' => 'OnSaleOrderBeforeSaved', 'MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleOrderPaid', 'MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleStatusOrderChange', 'MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleOrderSaved', 'MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleOrderCanceled', 'MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleOrderDeleted', 'MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleComponentOrderOneStepProcess', 'MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnBeforeSalePaymentSetField', 'FROM_MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnBeforeEndBufferContent', 'FROM_MODULE' => 'main'],
|
||||
['EVENT_NAME' => 'OnSaleOrderBeforeSaved', 'FROM_MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleOrderPaid', 'FROM_MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleStatusOrderChange', 'FROM_MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleOrderSaved', 'FROM_MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleOrderCanceled', 'FROM_MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleOrderDeleted', 'FROM_MODULE' => 'sale'],
|
||||
['EVENT_NAME' => 'OnSaleComponentOrderOneStepProcess', 'FROM_MODULE' => 'sale'],
|
||||
];
|
||||
public const V5 = 'v5';
|
||||
public $MODULE_ID = 'intaro.retailcrm';
|
||||
|
@ -1462,7 +1463,7 @@ class intaro_retailcrm extends CModule
|
|||
/**
|
||||
* Add USER fields for LP
|
||||
*/
|
||||
public function addLPUserFields()
|
||||
public function addLPUserFields(): void
|
||||
{
|
||||
$fieldNames = [
|
||||
"UF_REG_IN_PL_INTARO",
|
||||
|
@ -1588,6 +1589,9 @@ class intaro_retailcrm extends CModule
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add bonus pay system
|
||||
*/
|
||||
private function addBonusPaySystem(): void
|
||||
{
|
||||
$arrPaySystemAction = PaySystemActionTable::query()->setSelect(['ID'])->where(
|
||||
|
@ -1629,29 +1633,46 @@ class intaro_retailcrm extends CModule
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create loyalty program events handlers
|
||||
*/
|
||||
private function addLPEvents(): void
|
||||
{
|
||||
$eventManager = EventManager::getInstance();
|
||||
include($this->INSTALL_PATH . '/../lib/model/bitrix/orm/tomodule.php');
|
||||
|
||||
foreach (self::SUBSCRIBE_LP_EVENTS as $event){
|
||||
|
||||
$eventManager->registerEventHandler(
|
||||
$event['MODULE'],
|
||||
$event['EVENT_NAME'],
|
||||
$this->MODULE_ID,
|
||||
EventsHandlers::class,
|
||||
$event['EVENT_NAME'].'Handler'
|
||||
);
|
||||
|
||||
$events = ToModuleTable::query()->setSelect(['ID'])->where(
|
||||
[
|
||||
['from_module_id', '=', $event['FROM_MODULE']],
|
||||
['to_module_id', '=', $this->MODULE_ID],
|
||||
['to_method', '=', $event['EVENT_NAME'] . 'Handler'],
|
||||
['to_class', '=', EventsHandlers::class],
|
||||
]
|
||||
)->fetchCollection();
|
||||
|
||||
if (count($events) === 0) {
|
||||
$eventManager->registerEventHandler(
|
||||
$event['FROM_MODULE'],
|
||||
$event['EVENT_NAME'],
|
||||
$this->MODULE_ID,
|
||||
EventsHandlers::class,
|
||||
$event['EVENT_NAME'] . 'Handler'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function deleteLPEvents()
|
||||
/**
|
||||
* delete loyalty program events handlers
|
||||
*/
|
||||
private function deleteLPEvents(): void
|
||||
{
|
||||
$eventManager = EventManager::getInstance();
|
||||
|
||||
foreach (self::SUBSCRIBE_LP_EVENTS as $event){
|
||||
$eventManager->unRegisterEventHandler(
|
||||
$event['MODULE'],
|
||||
$event['FROM_MODULE'],
|
||||
$event['EVENT_NAME'],
|
||||
$this->MODULE_ID,
|
||||
EventsHandlers::class,
|
||||
|
|
|
@ -24,25 +24,23 @@ class EventsHandlers
|
|||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
public function OnBeforeSalePaymentSetFieldHandler(Event $event)
|
||||
public function OnBeforeSalePaymentSetFieldHandler(Event $event): void
|
||||
{
|
||||
AddMessage2Log('OnBeforeSalePaymentSetFieldHandler work! ' . $event->getDebugInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param &$content
|
||||
* @return mixed
|
||||
*/
|
||||
public function OnBeforeEndBufferContentHandler($content)
|
||||
public function OnBeforeEndBufferContentHandler()
|
||||
{
|
||||
AddMessage2Log('OnBeforeEndBufferContentHandler work! ');
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
public function OnSaleOrderBeforeSavedHandler(Event $event)
|
||||
public function OnSaleOrderBeforeSavedHandler(Event $event): void
|
||||
{
|
||||
AddMessage2Log('OnSaleOrderBeforeSavedHandler work! ' . $event->getDebugInfo());
|
||||
}
|
||||
|
@ -50,7 +48,7 @@ class EventsHandlers
|
|||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
public function OnSaleOrderPaidHandler(Event $event)
|
||||
public function OnSaleOrderPaidHandler(Event $event): void
|
||||
{
|
||||
AddMessage2Log('OnSaleOrderPaidHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
@ -58,7 +56,7 @@ class EventsHandlers
|
|||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
public function OnSaleStatusOrderChangeHandler(Event $event)
|
||||
public function OnSaleStatusOrderChangeHandler(Event $event): void
|
||||
{
|
||||
AddMessage2Log('OnSaleStatusOrderChangeHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
@ -66,7 +64,7 @@ class EventsHandlers
|
|||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
public function OnSaleOrderSavedHandler(Event $event)
|
||||
public function OnSaleOrderSavedHandler(Event $event): void
|
||||
{
|
||||
AddMessage2Log('OnSaleOrderSavedHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
@ -74,7 +72,7 @@ class EventsHandlers
|
|||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
public function OnSaleOrderCanceledHandler(Event $event)
|
||||
public function OnSaleOrderCanceledHandler(Event $event): void
|
||||
{
|
||||
AddMessage2Log('OnSaleOrderCanceledHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
@ -82,7 +80,7 @@ class EventsHandlers
|
|||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
public function OnSaleOrderDeletedHandler(Event $event)
|
||||
public function OnSaleOrderDeletedHandler(Event $event): void
|
||||
{
|
||||
AddMessage2Log('OnSaleOrderDeletedHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
|
199
intaro.retailcrm/lib/model/bitrix/orm/tomodule.php
Normal file
199
intaro.retailcrm/lib/model/bitrix/orm/tomodule.php
Normal file
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
|
||||
namespace Intaro\RetailCrm\Model\Bitrix\ORM;
|
||||
|
||||
use Bitrix\Main,
|
||||
Bitrix\Main\Localization\Loc;
|
||||
use Bitrix\Main\ORM\Fields\IntegerField;
|
||||
use Bitrix\Main\ORM\Fields\DatetimeField;
|
||||
use Bitrix\Main\ORM\Fields\StringField;
|
||||
|
||||
Loc::loadMessages(__FILE__);
|
||||
|
||||
/**
|
||||
* Class ToModuleTable
|
||||
*
|
||||
* Fields:
|
||||
* <ul>
|
||||
* <li> ID int mandatory
|
||||
* <li> TIMESTAMP_X datetime mandatory default 'CURRENT_TIMESTAMP'
|
||||
* <li> SORT int optional default 100
|
||||
* <li> FROM_MODULE_ID string(50) mandatory
|
||||
* <li> MESSAGE_ID string(255) mandatory
|
||||
* <li> TO_MODULE_ID string(50) mandatory
|
||||
* <li> TO_PATH string(255) optional
|
||||
* <li> TO_CLASS string(255) optional
|
||||
* <li> TO_METHOD string(255) optional
|
||||
* <li> TO_METHOD_ARG string(255) optional
|
||||
* <li> VERSION int optional
|
||||
* <li> UNIQUE_ID string(32) mandatory
|
||||
* </ul>
|
||||
*
|
||||
* @package Bitrix\Module
|
||||
**/
|
||||
class ToModuleTable extends Main\Entity\DataManager
|
||||
{
|
||||
/**
|
||||
* Returns DB table name for entity.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getTableName()
|
||||
{
|
||||
return 'b_module_to_module';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns entity map definition.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\SystemException
|
||||
*/
|
||||
public static function getMap()
|
||||
{
|
||||
return [
|
||||
new IntegerField(
|
||||
'id',
|
||||
['primary' => true, 'autocomplete' => true]),
|
||||
new DatetimeField('TIMESTAMP_X', ['required' => true]),
|
||||
new IntegerField('sort'),
|
||||
new StringField(
|
||||
'from_module_id',
|
||||
['required' => true, 'validation' => [__CLASS__, 'validateFromModuleId']]
|
||||
),
|
||||
new StringField(
|
||||
'message_id',
|
||||
['required' => true, 'validation' => [__CLASS__, 'validateMessageId']]
|
||||
),
|
||||
new StringField(
|
||||
'to_module_id',
|
||||
['required' => true, 'validation' => [__CLASS__, 'validateToModuleId']]
|
||||
),
|
||||
new StringField(
|
||||
'to_path',
|
||||
['validation' => [__CLASS__, 'validateToPath']]
|
||||
),
|
||||
new StringField(
|
||||
'to_class',
|
||||
['validation' => [__CLASS__, 'validateToClass']]
|
||||
),
|
||||
new StringField(
|
||||
'to_method',
|
||||
['validation' => [__CLASS__, 'validateToMethod']]
|
||||
),
|
||||
new StringField(
|
||||
'to_method_arg',
|
||||
['validation' => [__CLASS__, 'validateToMethodArg']]
|
||||
),
|
||||
new IntegerField('version'),
|
||||
new StringField(
|
||||
'unique_id',
|
||||
['required' => true, 'validation' => [__CLASS__, 'validateUniqueId']]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validators for FROM_MODULE_ID field.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\ArgumentTypeException
|
||||
*/
|
||||
public static function validateFromModuleId()
|
||||
{
|
||||
return [
|
||||
new Main\Entity\Validator\Length(null, 50),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validators for MESSAGE_ID field.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\ArgumentTypeException
|
||||
*/
|
||||
public static function validateMessageId()
|
||||
{
|
||||
return [
|
||||
new Main\Entity\Validator\Length(null, 255),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validators for TO_MODULE_ID field.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\ArgumentTypeException
|
||||
*/
|
||||
public static function validateToModuleId()
|
||||
{
|
||||
return [
|
||||
new Main\Entity\Validator\Length(null, 50),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validators for TO_PATH field.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\ArgumentTypeException
|
||||
*/
|
||||
public static function validateToPath()
|
||||
{
|
||||
return [
|
||||
new Main\Entity\Validator\Length(null, 255),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validators for TO_CLASS field.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\ArgumentTypeException
|
||||
*/
|
||||
public static function validateToClass()
|
||||
{
|
||||
return [
|
||||
new Main\Entity\Validator\Length(null, 255),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validators for TO_METHOD field.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\ArgumentTypeException
|
||||
*/
|
||||
public static function validateToMethod()
|
||||
{
|
||||
return [
|
||||
new Main\Entity\Validator\Length(null, 255),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validators for TO_METHOD_ARG field.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\ArgumentTypeException
|
||||
*/
|
||||
public static function validateToMethodArg()
|
||||
{
|
||||
return [
|
||||
new Main\Entity\Validator\Length(null, 255),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validators for UNIQUE_ID field.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Bitrix\Main\ArgumentTypeException
|
||||
*/
|
||||
public static function validateUniqueId()
|
||||
{
|
||||
return [
|
||||
new Main\Entity\Validator\Length(null, 32),
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue