Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/** @var modX $modx */
/** @var array $scriptProperties */
switch ($modx->event->name) {
// расчет стоимости события
case "UserEventsOnBeforeGetOrderCost":
/** @var UserEventsOrderInterface $orderHandler */
$orderHandler = $modx->getOption("order", $scriptProperties);
if (!$orderHandler OR !($orderHandler instanceof UserEventsOrderInterface)) {
return;
}
$values = $modx->Event->returnedValues;
$data = $orderHandler->get();
$rid = $modx->getOption("resource", $data);
$cost = 0;
// расчет стоимости согласно своей логике
if ($resource = $modx->getObject("modResource", $rid)) {
$cost = $resource->get("price");
}
$values["cost"] = $cost;
$modx->event->returnedValues = $values;
break;
// оповещение на смену статуса события
case "UserEventsOnChangeStatus":
/** @var UserEvent $event */
/** @var msOrder $order */
/** @var modUser $user */
$event = $modx->getOption("instance", $scriptProperties);
$order = $modx->getOption("order", $scriptProperties);
if (!$event OR !$status = $event->getOne("Status") OR !$user = $event->getOne("User") OR !$profile = $event->getOne("UserProfile")) {
return;
}
$pls = array_merge($event->toArray(), array(
"status" => $status->toArray(),
"user" => $user->toArray(),
"profile" => $profile->toArray(),
));
// получаем опции события
$options = $modx->getOption("options", $pls);
$action = $modx->getOption("action", $options);
/** @var UserEvents $UserEvents */
if (!$UserEvents = $modx->getService("userevents")) {
return;
}
/** @var pdoTools $pdoTools */
if (!$pdoTools = $modx->getService("pdoTools")) {
return;
}
// если событие создано с заказом minishop ничего не делаем
if (!empty($order)) {
return;
}
//$modx->log(1, print_r($pls, 1));
$status = $modx->getOption("status", $scriptProperties);
switch ($status) {
// активно, отменено
case 2:
case 4:
$subject = $pdoTools->getChunk('@INLINE {"site_name"|option} {do 1}', $pls);
$body = $pdoTools->getChunk('@INLINE {"userevents_event"|lexicon} - {$status.name}', $pls);
$UserEvents->sendEmail($profile->get("email"), $subject, $body, true);
break;
}
break;
//
case 'UserEventsOnDaysState':
$orderHandler = $modx->getOption("order", $scriptProperties);
if (!$orderHandler OR !($orderHandler instanceof UserEventsOrderInterface)) {
return;
}
$data = $orderHandler->get();
$state = $modx->getOption("state", $scriptProperties);
$disabled = isset($state["disabled"]) ? $state["disabled"] : array();
// выключим определенные дни
$times = array(
array(
'2017-12-05',
'2017-12-06',
),
);
foreach ($times as $time) {
$intertime = array(
strtotime($time[0]),
strtotime($time[1]),
);
$disabled[] = array(
"time" => implode(",", $time),
"intertime" => implode(",", $intertime),
);
}
$state["disabled"] = $disabled;
$enabled = isset($state["enabled"]) ? $state["enabled"] : array();
// включим определенные дни
$resource = isset($data["resource"]) ? $data["resource"] : 0;
$modx->log(1, print_r($resource ,1));
if ($resource == 60) {
$times = array(
array(
'2017-12-18',
'2017-12-19',
),
array(
'2017-12-03',
'2017-12-04',
),
);
}
else {
$times = array(
array(
'2017-12-17',
'2017-12-18',
),
array(
'2017-12-03',
'2017-12-04',
),
);
}
foreach ($times as $time) {
$intertime = array(
strtotime($time[0]),
strtotime($time[1]),
);
$enabled[] = array(
"time" => implode(",", $time),
"intertime" => implode(",", $intertime),
);
}
$state["enabled"] = $enabled;
$values = $modx->Event->returnedValues;
$values["state"] = $state;
$modx->event->returnedValues = $values;
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment