improved delivery + door + resolved #23
This commit is contained in:
parent
ae866d8ddb
commit
9944e5309c
|
@ -17,6 +17,11 @@ server {
|
||||||
try_files $uri $uri/ /index.php;
|
try_files $uri $uri/ /index.php;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /api/cdek {
|
||||||
|
rewrite ^/api/cdek(.*)$ /$1 break;
|
||||||
|
index cdek.php;
|
||||||
|
}
|
||||||
|
|
||||||
location ~ /(?<type>categories|products) {
|
location ~ /(?<type>categories|products) {
|
||||||
root /var/www/arming_bot/mirzaev/arming_bot/system/storage;
|
root /var/www/arming_bot/mirzaev/arming_bot/system/storage;
|
||||||
try_files $uri =404;
|
try_files $uri =404;
|
||||||
|
|
|
@ -7,7 +7,8 @@ namespace mirzaev\arming_bot\controllers;
|
||||||
// Files of the project
|
// Files of the project
|
||||||
use mirzaev\arming_bot\controllers\core,
|
use mirzaev\arming_bot\controllers\core,
|
||||||
mirzaev\arming_bot\models\cart,
|
mirzaev\arming_bot\models\cart,
|
||||||
mirzaev\arming_bot\models\deliveries\cdek;
|
mirzaev\arming_bot\models\deliveries\cdek,
|
||||||
|
mirzaev\arming_bot\models\enumerations\delivery as company;
|
||||||
|
|
||||||
// Framework for PHP
|
// Framework for PHP
|
||||||
use mirzaev\minimal\http\enumerations\content,
|
use mirzaev\minimal\http\enumerations\content,
|
||||||
|
@ -58,19 +59,25 @@ final class delivery extends core
|
||||||
* Validate and write delivery data to account and session buffers
|
* Validate and write delivery data to account and session buffers
|
||||||
*
|
*
|
||||||
* @param string|null $company Name of delivery company
|
* @param string|null $company Name of delivery company
|
||||||
* @param string|null $location Location (city)
|
* @param string|null $location Receiver location (city)
|
||||||
* @param string|null $street Address (street with house)
|
* @param string|null $street Receiver address (street with house)
|
||||||
* @param string|int|null $type Type or taruff
|
* @param string|int|null $apartament Receiver apartament
|
||||||
|
* @param string|null $type Delivery type ('office', 'door')
|
||||||
|
* @param string|int|null $tariff Delivery tariff
|
||||||
|
* @param string|int|float|null $longitude Receiver longitude
|
||||||
|
* @param string|int|float|null $latitude Receiver latitude
|
||||||
*
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function write(
|
public function write(
|
||||||
/* string|company|null $company = null, */
|
|
||||||
string|null $company = null,
|
string|null $company = null,
|
||||||
/* string|location|null $location = null, */
|
|
||||||
?string $location = null,
|
?string $location = null,
|
||||||
?string $street = null,
|
?string $street = null,
|
||||||
string|int|null $type = null
|
string|int|null $apartament = null,
|
||||||
|
?string $type = null,
|
||||||
|
string|int|null $tariff = null,
|
||||||
|
string|int|float|null $longitude = null,
|
||||||
|
string|int|float|null $latitude = null
|
||||||
): null {
|
): null {
|
||||||
if (str_contains($this->request->headers['accept'], content::json->value)) {
|
if (str_contains($this->request->headers['accept'], content::json->value)) {
|
||||||
// Request for JSON response
|
// Request for JSON response
|
||||||
|
@ -154,34 +161,46 @@ final class delivery extends core
|
||||||
// Initialization buffer of delivery parameters
|
// Initialization buffer of delivery parameters
|
||||||
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
||||||
|
|
||||||
if (isset($delivery[$normalized])) {
|
|
||||||
// Initialized delivery company data
|
|
||||||
|
|
||||||
if (!empty($delivery[$normalized]['location']) && !empty($delivery[$normalized]['street'])) {
|
|
||||||
// Required parameters initialized: company, location, street
|
|
||||||
|
|
||||||
// Writing readiness status to the buffer of the response
|
// Writing readiness status to the buffer of the response
|
||||||
$response['ready'] = true;
|
$response['ready'] = $this->model::ready(company::{$normalized}, $delivery[$normalized] ?? []);
|
||||||
|
|
||||||
|
if ($response['ready']) {
|
||||||
|
// Initialized required parameters
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $normalized . '_ready' => true]));
|
||||||
|
|
||||||
// Writing to the account buffer
|
// Writing to the account buffer
|
||||||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => true]));
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => true]));
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($name);
|
unset($name);
|
||||||
}
|
} else {
|
||||||
|
// Not initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready = 'delivery_' . $normalized . '_ready' => false,
|
||||||
|
$name_cost = 'delivery_' . $normalized . '_cost' => null,
|
||||||
|
$name_days = 'delivery_' . $normalized . '_days' => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready => false,
|
||||||
|
$name_cost => null,
|
||||||
|
$name_days => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name_ready, $name_cost, $name_days);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($delivery);
|
unset($delivery, $normalized);
|
||||||
|
|
||||||
// Writing status of execution to the buffer of the response
|
// Writing status of execution to the buffer of the response
|
||||||
$response['status'] = 'success';
|
$response['status'] = 'success';
|
||||||
|
|
||||||
// Deinitializing variable for normalized value of the parameter
|
|
||||||
unset($normalized);
|
|
||||||
}
|
}
|
||||||
} else if (isset($location)) {
|
} else if (isset($location)) {
|
||||||
// Received location name
|
// Received location name
|
||||||
|
@ -204,7 +223,7 @@ final class delivery extends core
|
||||||
// Initialization buffer of delivery parameters
|
// Initialization buffer of delivery parameters
|
||||||
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
||||||
|
|
||||||
if (isset($delivery['company'])) {
|
if (!empty($delivery['company'])) {
|
||||||
// Initialized delivery company
|
// Initialized delivery company
|
||||||
|
|
||||||
if (!empty($separated)) {
|
if (!empty($separated)) {
|
||||||
|
@ -215,14 +234,19 @@ final class delivery extends core
|
||||||
|
|
||||||
// Normalizing location name
|
// Normalizing location name
|
||||||
foreach ($separated as $value) $normalized[] = mb_ucfirst($value);
|
foreach ($separated as $value) $normalized[] = mb_ucfirst($value);
|
||||||
|
/* foreach ($separated as $value) $normalized[] = $value; */
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($separated, $value);
|
unset($separated, $value);
|
||||||
|
|
||||||
|
// Reinitializing result value of location name
|
||||||
|
$result = $normalized[0];
|
||||||
|
|
||||||
// Declaring of universalized locations buffer
|
// Declaring of universalized locations buffer
|
||||||
$locations = null;
|
$locations = null;
|
||||||
|
|
||||||
if ($delivery['company'] === 'cdek') {
|
if ($delivery['company'] === 'cdek') {
|
||||||
|
// CDEK
|
||||||
|
|
||||||
// Searching for locations by name (first part with spaces before first comma or any non word symbol)
|
// Searching for locations by name (first part with spaces before first comma or any non word symbol)
|
||||||
$cdek = cdek::location($normalized[0], $this->errors['delivery'])?->items;
|
$cdek = cdek::location($normalized[0], $this->errors['delivery'])?->items;
|
||||||
|
@ -230,11 +254,20 @@ final class delivery extends core
|
||||||
foreach ($cdek ?? [] as $location) {
|
foreach ($cdek ?? [] as $location) {
|
||||||
// Iterating over found locations
|
// Iterating over found locations
|
||||||
|
|
||||||
|
// Initializing structure
|
||||||
|
$structure = [$location->country];
|
||||||
|
|
||||||
|
// Initializing additional instances in the structure
|
||||||
|
if (!empty($location->region) && $location->region !== $location->city)
|
||||||
|
$structure[] = $location->region;
|
||||||
|
if (!empty($location->sub_region) && $location->sub_region !== $location->region && $location->sub_region !== $location->city)
|
||||||
|
$structure[] = $location->sub_region;
|
||||||
|
|
||||||
// Universalizing and writing to locations buffer
|
// Universalizing and writing to locations buffer
|
||||||
$locations[] = [
|
$locations[] = [
|
||||||
'identifier' => $location->code,
|
'identifier' => $location->code,
|
||||||
'name' => $location->city,
|
'name' => $location->city,
|
||||||
'structure' => [$location->country, $location->region, $location->sub_region],
|
'structure' => $structure,
|
||||||
'longitude' => $location->longitude,
|
'longitude' => $location->longitude,
|
||||||
'latitude' => $location->latitude,
|
'latitude' => $location->latitude,
|
||||||
'data' => $location
|
'data' => $location
|
||||||
|
@ -298,7 +331,8 @@ final class delivery extends core
|
||||||
// Reinitializating locations from buffer of validated locations by input values
|
// Reinitializating locations from buffer of validated locations by input values
|
||||||
$locations = $buffer;
|
$locations = $buffer;
|
||||||
|
|
||||||
/* if (count($locations) === 1) { */
|
/* if (count($locations) === 1) */
|
||||||
|
if (count($locations) > 0) {
|
||||||
// Identificated location
|
// Identificated location
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
|
@ -313,20 +347,20 @@ final class delivery extends core
|
||||||
// Writing result value of location name
|
// Writing result value of location name
|
||||||
$result = $locations[0]['name'] . ', ' . implode(', ', array_reverse($locations[0]['structure']));
|
$result = $locations[0]['name'] . ', ' . implode(', ', array_reverse($locations[0]['structure']));
|
||||||
|
|
||||||
|
// Writing to the actual buffer copy
|
||||||
|
$delivery[$delivery['company']]['location'] = $result;
|
||||||
|
|
||||||
// Writing location data to the buffer of the response
|
// Writing location data to the buffer of the response
|
||||||
/* $response['location'] = [
|
/* $response['location'] = [
|
||||||
'identifier' => $locations[0]['identifier'],
|
'identifier' => $locations[0]['identifier'],
|
||||||
'input' => $result
|
'input' => $result
|
||||||
]; */
|
]; */
|
||||||
|
|
||||||
// Writing status of execution to the buffer of the response
|
|
||||||
$response['status'] = 'success';
|
|
||||||
|
|
||||||
if (!empty($delivery[$delivery['company']]['street'])) {
|
|
||||||
// Required parameters initialized: company, location, street
|
|
||||||
|
|
||||||
// Writing readiness status to the buffer of the response
|
// Writing readiness status to the buffer of the response
|
||||||
$response['ready'] = true;
|
$response['ready'] = $this->model::ready(company::{$delivery['company']}, $delivery[$delivery['company']] ?? []);
|
||||||
|
|
||||||
|
if ($response['ready']) {
|
||||||
|
// Initialized required parameters
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
||||||
|
@ -336,7 +370,7 @@ final class delivery extends core
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($name);
|
unset($name);
|
||||||
/* } else {
|
} else {
|
||||||
// Not initialized required parameters
|
// Not initialized required parameters
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
|
@ -355,16 +389,22 @@ final class delivery extends core
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($name_ready, $name_cost, $name_days);
|
unset($name_ready, $name_cost, $name_days);
|
||||||
} */
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery);
|
||||||
|
|
||||||
// Writing locations into response buffer
|
// Writing locations into response buffer
|
||||||
$response['locations'] = [];
|
$response['locations'] = [];
|
||||||
|
|
||||||
|
// Writing status of execution to the buffer of the response
|
||||||
|
$response['status'] = 'success';
|
||||||
} else {
|
} else {
|
||||||
// Not identificated location
|
// Not identificated location
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||||
$name_location = 'delivery_' . $delivery['company'] . '_location' => null,
|
$name_location = 'delivery_' . $delivery['company'] . '_location' => $result,
|
||||||
$name_ready = 'delivery_' . $delivery['company'] . '_ready' => false,
|
$name_ready = 'delivery_' . $delivery['company'] . '_ready' => false,
|
||||||
$name_cost = 'delivery_' . $delivery['company'] . '_cost' => null,
|
$name_cost = 'delivery_' . $delivery['company'] . '_cost' => null,
|
||||||
$name_days = 'delivery_' . $delivery['company'] . '_days' => null
|
$name_days = 'delivery_' . $delivery['company'] . '_days' => null
|
||||||
|
@ -372,7 +412,7 @@ final class delivery extends core
|
||||||
|
|
||||||
// Writing to the account buffer
|
// Writing to the account buffer
|
||||||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||||
$name_location => null,
|
$name_location => $result,
|
||||||
$name_ready => false,
|
$name_ready => false,
|
||||||
$name_cost => null,
|
$name_cost => null,
|
||||||
$name_days => null
|
$name_days => null
|
||||||
|
@ -381,6 +421,9 @@ final class delivery extends core
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($name_location, $name_ready, $name_cost, $name_days);
|
unset($name_location, $name_ready, $name_cost, $name_days);
|
||||||
|
|
||||||
|
// Writing status of execution to the buffer of the response (???)
|
||||||
|
$response['status'] = 'success';
|
||||||
|
|
||||||
// Declaring buffer of data to send
|
// Declaring buffer of data to send
|
||||||
$buffer = [];
|
$buffer = [];
|
||||||
|
|
||||||
|
@ -458,10 +501,10 @@ final class delivery extends core
|
||||||
unset($delivery, $normalized);
|
unset($delivery, $normalized);
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: ['delivery_location' => empty($result) ? $location : $result]));
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: ['delivery_location' => $result]));
|
||||||
|
|
||||||
// Writing to the account buffer
|
// Writing to the account buffer
|
||||||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: ['delivery_location' => empty($result) ? $location : $result]));
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: ['delivery_location' => $result]));
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($location, $result, $normalized);
|
unset($location, $result, $normalized);
|
||||||
|
@ -476,7 +519,7 @@ final class delivery extends core
|
||||||
$normalized = '';
|
$normalized = '';
|
||||||
|
|
||||||
// Normalizing street
|
// Normalizing street
|
||||||
if (preg_match('/[\w\d\s\.\,]+/u', urldecode($street), $matches)) $normalized = mb_ucfirst($matches[0] ?? '');
|
if (preg_match('/[\w\d\s\.\,\-]+/u', urldecode($street), $matches)) $normalized = mb_ucfirst($matches[0] ?? '');
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($matches);
|
unset($matches);
|
||||||
|
@ -496,11 +539,14 @@ final class delivery extends core
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($name);
|
unset($name);
|
||||||
|
|
||||||
if (!empty($normalized) && !empty($delivery[$delivery['company']]['location'])) {
|
// Writing to the actual buffer copy
|
||||||
// Required parameters initialized: company, location, street
|
$delivery[$delivery['company']]['street'] = $normalized;
|
||||||
|
|
||||||
// Writing readiness status to the buffer of the response
|
// Writing readiness status to the buffer of the response
|
||||||
$response['ready'] = true;
|
$response['ready'] = $this->model::ready(company::{$delivery['company']}, $delivery[$delivery['company']] ?? []);
|
||||||
|
|
||||||
|
if ($response['ready']) {
|
||||||
|
// Initialized required parameters
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
||||||
|
@ -531,6 +577,9 @@ final class delivery extends core
|
||||||
unset($name_ready, $name_cost, $name_days);
|
unset($name_ready, $name_cost, $name_days);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery);
|
||||||
|
|
||||||
// Writing status of execution to the buffer of the response
|
// Writing status of execution to the buffer of the response
|
||||||
$response['status'] = 'success';
|
$response['status'] = 'success';
|
||||||
}
|
}
|
||||||
|
@ -553,7 +602,7 @@ final class delivery extends core
|
||||||
} else if (isset($type)) {
|
} else if (isset($type)) {
|
||||||
// Received delivery type
|
// Received delivery type
|
||||||
|
|
||||||
if ((is_string($type) && mb_strlen($type) < 30) || (is_int($type && $type < 10000))) {
|
if (mb_strlen($type) < 30) {
|
||||||
// Validated delivery type
|
// Validated delivery type
|
||||||
|
|
||||||
// Declating variable for result value of delivery type
|
// Declating variable for result value of delivery type
|
||||||
|
@ -562,8 +611,8 @@ final class delivery extends core
|
||||||
// Declating variable for normalized value of delivery type
|
// Declating variable for normalized value of delivery type
|
||||||
$normalized = '';
|
$normalized = '';
|
||||||
|
|
||||||
// Normalizing location name
|
// Normalizing delivery type
|
||||||
if (preg_match('/[\w\d]+/', trim(urldecode($type)), $matches)) $normalized = $matches[0];
|
if (preg_match('/[\w]+/', trim(urldecode($type)), $matches)) $normalized = $matches[0];
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($matches);
|
unset($matches);
|
||||||
|
@ -574,9 +623,6 @@ final class delivery extends core
|
||||||
if (isset($delivery['company'])) {
|
if (isset($delivery['company'])) {
|
||||||
// Initialized delivery company
|
// Initialized delivery company
|
||||||
|
|
||||||
if (!empty($normalized)) {
|
|
||||||
// Normalized delivery type
|
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_type' => $normalized]));
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_type' => $normalized]));
|
||||||
|
|
||||||
|
@ -586,22 +632,34 @@ final class delivery extends core
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($name);
|
unset($name);
|
||||||
|
|
||||||
|
// Writing to the actual buffer copy
|
||||||
|
$delivery[$delivery['company']]['type'] = $normalized;
|
||||||
|
|
||||||
// Writing result value of delivery type
|
// Writing result value of delivery type
|
||||||
$result = $normalized;
|
$result = $normalized;
|
||||||
|
|
||||||
// Writing status of execution to the buffer of the response
|
|
||||||
$response['status'] = 'success';
|
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($normalized);
|
unset($normalized);
|
||||||
} else {
|
|
||||||
// Value is empty after separating
|
|
||||||
|
|
||||||
|
// Writing readiness status to the buffer of the response
|
||||||
|
$response['ready'] = $this->model::ready(company::{$delivery['company']}, $delivery[$delivery['company']] ?? []);
|
||||||
|
|
||||||
|
if ($response['ready']) {
|
||||||
|
// Initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => true]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
} else {
|
||||||
// Not initialized required parameters
|
// Not initialized required parameters
|
||||||
|
|
||||||
// Writing to the session buffer
|
// Writing to the session buffer
|
||||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||||
$name_type = 'delivery_' . $delivery['company'] . '_type' => null,
|
|
||||||
$name_ready = 'delivery_' . $delivery['company'] . '_ready' => false,
|
$name_ready = 'delivery_' . $delivery['company'] . '_ready' => false,
|
||||||
$name_cost = 'delivery_' . $delivery['company'] . '_cost' => null,
|
$name_cost = 'delivery_' . $delivery['company'] . '_cost' => null,
|
||||||
$name_days = 'delivery_' . $delivery['company'] . '_days' => null
|
$name_days = 'delivery_' . $delivery['company'] . '_days' => null
|
||||||
|
@ -609,15 +667,359 @@ final class delivery extends core
|
||||||
|
|
||||||
// Writing to the account buffer
|
// Writing to the account buffer
|
||||||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||||
$name_type => null,
|
|
||||||
$name_ready => false,
|
$name_ready => false,
|
||||||
$name_cost => null,
|
$name_cost => null,
|
||||||
$name_days => null
|
$name_days => null
|
||||||
]));
|
]));
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
unset($name_type, $name_ready, $name_cost, $name_days);
|
unset($name_ready, $name_cost, $name_days);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery);
|
||||||
|
|
||||||
|
// Writing status of execution to the buffer of the response
|
||||||
|
$response['status'] = 'success';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery, $result, $normalized);
|
||||||
|
}
|
||||||
|
} else if (isset($tariff)) {
|
||||||
|
// Received delivery tariff
|
||||||
|
|
||||||
|
if ((is_string($tariff) && mb_strlen($tariff) < 30) || (is_int($tariff && $tariff < 10000))) {
|
||||||
|
// Validated delivery tariff
|
||||||
|
|
||||||
|
// Declating variable for result value of delivery tariff
|
||||||
|
$result = '';
|
||||||
|
|
||||||
|
// Declating variable for normalized value of delivery tariff
|
||||||
|
$normalized = '';
|
||||||
|
|
||||||
|
// Normalizing delivery tariff
|
||||||
|
if (preg_match('/[\w\d]+/', trim(urldecode($tariff)), $matches)) $normalized = $matches[0];
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($matches);
|
||||||
|
|
||||||
|
// Initialization buffer of delivery parameters
|
||||||
|
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
||||||
|
|
||||||
|
if (isset($delivery['company'])) {
|
||||||
|
// Initialized delivery company
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_tariff' => $normalized]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => $normalized]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
|
||||||
|
// Writing to the actual buffer copy
|
||||||
|
$delivery[$delivery['company']]['tariff'] = $normalized;
|
||||||
|
|
||||||
|
// Writing result value of delivery tariff
|
||||||
|
$result = $normalized;
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($normalized);
|
||||||
|
|
||||||
|
// Writing readiness status to the buffer of the response
|
||||||
|
$response['ready'] = $this->model::ready(company::{$delivery['company']}, $delivery[$delivery['company']] ?? []);
|
||||||
|
|
||||||
|
if ($response['ready']) {
|
||||||
|
// Initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => true]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
} else {
|
||||||
|
// Not initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready = 'delivery_' . $delivery['company'] . '_ready' => false,
|
||||||
|
$name_cost = 'delivery_' . $delivery['company'] . '_cost' => null,
|
||||||
|
$name_days = 'delivery_' . $delivery['company'] . '_days' => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready => false,
|
||||||
|
$name_cost => null,
|
||||||
|
$name_days => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name_ready, $name_cost, $name_days);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery);
|
||||||
|
|
||||||
|
// Writing status of execution to the buffer of the response
|
||||||
|
$response['status'] = 'success';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery, $result, $normalized);
|
||||||
|
}
|
||||||
|
} else if (isset($longitude)) {
|
||||||
|
// Received delivery receiver longitude
|
||||||
|
|
||||||
|
// Declating variable for result value of delivery receiver longitude
|
||||||
|
$result = '';
|
||||||
|
|
||||||
|
// Declating variable for normalized value of delivery receiver longitude
|
||||||
|
$normalized = '';
|
||||||
|
|
||||||
|
// Normalizing receiver longitude
|
||||||
|
$normalized = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
|
||||||
|
|
||||||
|
if ($normalized >= -180 && $normalized <= 180) {
|
||||||
|
// Validated delivery receiver longitude
|
||||||
|
|
||||||
|
// Initialization buffer of delivery parameters
|
||||||
|
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
||||||
|
|
||||||
|
if (isset($delivery['company'])) {
|
||||||
|
// Initialized delivery company
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_longitude' => $normalized]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => $normalized]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
|
||||||
|
// Writing to the actual buffer copy
|
||||||
|
$delivery[$delivery['company']]['longitude'] = $normalized;
|
||||||
|
|
||||||
|
// Writing result value of delivery receiver longitude
|
||||||
|
$result = $normalized;
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($normalized);
|
||||||
|
|
||||||
|
// Writing readiness status to the buffer of the response
|
||||||
|
$response['ready'] = $this->model::ready(company::{$delivery['company']}, $delivery[$delivery['company']] ?? []);
|
||||||
|
|
||||||
|
if ($response['ready']) {
|
||||||
|
// Initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => true]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
} else {
|
||||||
|
// Not initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready = 'delivery_' . $delivery['company'] . '_ready' => false,
|
||||||
|
$name_cost = 'delivery_' . $delivery['company'] . '_cost' => null,
|
||||||
|
$name_days = 'delivery_' . $delivery['company'] . '_days' => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready => false,
|
||||||
|
$name_cost => null,
|
||||||
|
$name_days => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name_ready, $name_cost, $name_days);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery);
|
||||||
|
|
||||||
|
// Writing status of execution to the buffer of the response
|
||||||
|
$response['status'] = 'success';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery, $result, $normalized);
|
||||||
|
}
|
||||||
|
} else if (isset($latitude)) {
|
||||||
|
// Received delivery receiver latitude
|
||||||
|
|
||||||
|
// Declating variable for result value of delivery receiver latitude
|
||||||
|
$result = '';
|
||||||
|
|
||||||
|
// Declating variable for normalized value of delivery receiver latitude
|
||||||
|
$normalized = '';
|
||||||
|
|
||||||
|
// Normalizing receiver latitude
|
||||||
|
$normalized = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
|
||||||
|
|
||||||
|
if ($normalized >= -90 && $normalized <= 90) {
|
||||||
|
// Validated delivery receiver latitude
|
||||||
|
|
||||||
|
// Initialization buffer of delivery parameters
|
||||||
|
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
||||||
|
|
||||||
|
if (isset($delivery['company'])) {
|
||||||
|
// Initialized delivery company
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_latitude' => $normalized]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => $normalized]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
|
||||||
|
// Writing to the actual buffer copy
|
||||||
|
$delivery[$delivery['company']]['latitude'] = $normalized;
|
||||||
|
|
||||||
|
// Writing result value of delivery receiver latitude
|
||||||
|
$result = $normalized;
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($normalized);
|
||||||
|
|
||||||
|
// Writing readiness status to the buffer of the response
|
||||||
|
$response['ready'] = $this->model::ready(company::{$delivery['company']}, $delivery[$delivery['company']] ?? []);
|
||||||
|
|
||||||
|
if ($response['ready']) {
|
||||||
|
// Initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => true]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
} else {
|
||||||
|
// Not initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready = 'delivery_' . $delivery['company'] . '_ready' => false,
|
||||||
|
$name_cost = 'delivery_' . $delivery['company'] . '_cost' => null,
|
||||||
|
$name_days = 'delivery_' . $delivery['company'] . '_days' => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready => false,
|
||||||
|
$name_cost => null,
|
||||||
|
$name_days => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name_ready, $name_cost, $name_days);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery);
|
||||||
|
|
||||||
|
// Writing status of execution to the buffer of the response
|
||||||
|
$response['status'] = 'success';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery, $result, $normalized);
|
||||||
|
}
|
||||||
|
} else if (isset($apartament)) {
|
||||||
|
// Received delivery receiver apartament
|
||||||
|
|
||||||
|
// Declating variable for result value of delivery receiver apartament
|
||||||
|
$result = '';
|
||||||
|
|
||||||
|
// Declating variable for normalized value of delivery receiver apartament
|
||||||
|
$normalized = '';
|
||||||
|
|
||||||
|
// Normalizing receiver apartament
|
||||||
|
$normalized = filter_var($apartament, FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_ALLOW_FRACTION);
|
||||||
|
|
||||||
|
if ($normalized > 0 && $normalized <= 1000) {
|
||||||
|
// Validated delivery receiver apartament
|
||||||
|
|
||||||
|
// Initialization buffer of delivery parameters
|
||||||
|
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
||||||
|
|
||||||
|
if (isset($delivery['company'])) {
|
||||||
|
// Initialized delivery company
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_apartament' => $normalized]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => $normalized]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
|
||||||
|
// Writing to the actual buffer copy
|
||||||
|
$delivery[$delivery['company']]['apartment'] = $normalized;
|
||||||
|
|
||||||
|
// Writing result value of delivery receiver apartament
|
||||||
|
$result = $normalized;
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($normalized);
|
||||||
|
|
||||||
|
// Writing readiness status to the buffer of the response
|
||||||
|
$response['ready'] = $this->model::ready(company::{$delivery['company']}, $delivery[$delivery['company']] ?? []);
|
||||||
|
|
||||||
|
if ($response['ready']) {
|
||||||
|
// Initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_ready' => true]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [$name => true]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name);
|
||||||
|
} else {
|
||||||
|
// Not initialized required parameters
|
||||||
|
|
||||||
|
// Writing to the session buffer
|
||||||
|
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready = 'delivery_' . $delivery['company'] . '_ready' => false,
|
||||||
|
$name_cost = 'delivery_' . $delivery['company'] . '_cost' => null,
|
||||||
|
$name_days = 'delivery_' . $delivery['company'] . '_days' => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Writing to the account buffer
|
||||||
|
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||||
|
$name_ready => false,
|
||||||
|
$name_cost => null,
|
||||||
|
$name_days => null
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($name_ready, $name_cost, $name_days);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deinitializing unnecessary variables
|
||||||
|
unset($delivery);
|
||||||
|
|
||||||
|
// Writing status of execution to the buffer of the response
|
||||||
|
$response['status'] = 'success';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deinitializing unnecessary variables
|
// Deinitializing unnecessary variables
|
||||||
|
@ -709,7 +1111,7 @@ final class delivery extends core
|
||||||
from_street: 'Екатерининская 116', // @todo issues #13
|
from_street: 'Екатерининская 116', // @todo issues #13
|
||||||
to_location: $delivery[$delivery['company']]['location']['identifier'],
|
to_location: $delivery[$delivery['company']]['location']['identifier'],
|
||||||
to_street: $delivery[$delivery['company']]['street'],
|
to_street: $delivery[$delivery['company']]['street'],
|
||||||
tariff: $delivery[$delivery['company']]['type'] ?? 368,
|
tariff: $delivery[$delivery['company']]['tariff'] ?? 368,
|
||||||
products: $formatted,
|
products: $formatted,
|
||||||
date: new datetime(), // @todo weekdays only? + timezones
|
date: new datetime(), // @todo weekdays only? + timezones
|
||||||
errors: $this->errors['delivery']
|
errors: $this->errors['delivery']
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace mirzaev\arming_bot\models;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use mirzaev\arming_bot\models\core,
|
||||||
|
mirzaev\arming_bot\models\enumerations\delivery as company;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model of settings
|
||||||
|
*
|
||||||
|
* @package mirzaev\arming_bot\models
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class delivery extends core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Ready
|
||||||
|
*
|
||||||
|
* @param company $company Delivery company
|
||||||
|
* @param array $parameters Delivery company parameters
|
||||||
|
* @param array &$errors Registry of errors
|
||||||
|
*
|
||||||
|
* @return bool|null Is delivery data ready for creating order?
|
||||||
|
*/
|
||||||
|
public static function ready(company $company, array $parameters, array &$errors = []): ?bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!empty($parameters)) {
|
||||||
|
// Initialized delivery company data
|
||||||
|
|
||||||
|
if (
|
||||||
|
!empty($parameters['type'])
|
||||||
|
&& !empty($parameters['tariff'])
|
||||||
|
&& (!empty($parameters['location']['name']) || (!empty($parameters['longitude']) && !empty($parameters['latitude'])))
|
||||||
|
&& !empty($parameters['street'])
|
||||||
|
) {
|
||||||
|
// Initialized required parameters: company, type, tariff, location (or longitude with latitude), street
|
||||||
|
|
||||||
|
if ($parameters['type'] === 'door') {
|
||||||
|
// Delivery to the door
|
||||||
|
|
||||||
|
if (!empty($parameters['apartament'])) {
|
||||||
|
// Required parameters initialized: apartament
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// Not initialized required parameters
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if ($parameters['type'] === 'office') {
|
||||||
|
// Delivery to the office
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// Not identified delivery type
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized required parameters
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (exception $e) {
|
||||||
|
// Writing to the registry of errors
|
||||||
|
$errors[] = [
|
||||||
|
'text' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'stack' => $e->getTrace()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace mirzaev\arming_bot\models\enumerations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Types of deliveries
|
||||||
|
*
|
||||||
|
* @package mirzaev\arming_bot\models\enumerations
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
enum delivery: string
|
||||||
|
{
|
||||||
|
case cdek = 'CDEK';
|
||||||
|
}
|
|
@ -99,19 +99,32 @@ final class telegram extends core
|
||||||
*/
|
*/
|
||||||
public static function menu(context $ctx): void
|
public static function menu(context $ctx): void
|
||||||
{
|
{
|
||||||
// Инициализация клавиатуры
|
// Declaring keyboard buttond
|
||||||
$keyboard = [
|
$keyboard = [];
|
||||||
|
|
||||||
|
/* if ($ctx->get('account')) {
|
||||||
|
// Authenticated */
|
||||||
|
|
||||||
|
// Writing the catalog button
|
||||||
|
$keyboard[] = [
|
||||||
[
|
[
|
||||||
['text' => '🛒 Каталог', 'web_app' => ['url' => 'https://arming.dev.mirzaev.sexy']]
|
'text' => '🛒 Каталог',
|
||||||
],
|
'web_app' => ['url' => 'https://arming.dev.mirzaev.sexy']
|
||||||
[
|
|
||||||
['text' => '🏛️ О компании'],
|
|
||||||
['text' => '💬 Контакты']
|
|
||||||
],
|
|
||||||
[
|
|
||||||
['text' => '🎯 Сообщество']
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
$keyboard = array_merge(
|
||||||
|
$keyboard,
|
||||||
|
[[
|
||||||
|
['text' => '🏛️ О компании'],
|
||||||
|
['text' => '💬 Контакты']
|
||||||
|
]],
|
||||||
|
[[
|
||||||
|
['text' => '🎯 Сообщество']
|
||||||
|
]]
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
if ($ctx->get('account')?->access['settings']) $keyboard[] = [['text' => '⚙️ Настройки']];
|
if ($ctx->get('account')?->access['settings']) $keyboard[] = [['text' => '⚙️ Настройки']];
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,8 @@ $core->router
|
||||||
->write('/account/write', new route('account', 'write', 'account'), 'PATCH')
|
->write('/account/write', new route('account', 'write', 'account'), 'PATCH')
|
||||||
->write('/session/write', new route('session', 'write', 'session'), 'PATCH')
|
->write('/session/write', new route('session', 'write', 'session'), 'PATCH')
|
||||||
->write('/session/connect/telegram', new route('session', 'telegram', 'session'), 'PUT')
|
->write('/session/connect/telegram', new route('session', 'telegram', 'session'), 'PUT')
|
||||||
->write('/delivery/write', new route('delivery', 'write'), 'PATCH')
|
->write('/delivery/write', new route('delivery', 'write', 'delivery'), 'PATCH')
|
||||||
->write('/delivery/calculate', new route('delivery', 'calculate'), 'GET');
|
->write('/delivery/calculate', new route('delivery', 'calculate', 'delivery'), 'GET');
|
||||||
|
|
||||||
// Handling request
|
// Handling request
|
||||||
$core->start();
|
$core->start();
|
||||||
|
|
|
@ -351,7 +351,7 @@ core.modules.connect("damper").then(() => {
|
||||||
damper: core.damper(
|
damper: core.damper(
|
||||||
(...variables) => core.buffer.write.system(...variables),
|
(...variables) => core.buffer.write.system(...variables),
|
||||||
300,
|
300,
|
||||||
3,
|
2,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -148,7 +148,7 @@ core.modules.connect("damper").then(() => {
|
||||||
damper: core.damper(
|
damper: core.damper(
|
||||||
(...variables) => account.buffer.write.system(...variables),
|
(...variables) => account.buffer.write.system(...variables),
|
||||||
300,
|
300,
|
||||||
3,
|
2,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -494,7 +494,7 @@ core.modules.connect("damper").then(() => {
|
||||||
(...variables) =>
|
(...variables) =>
|
||||||
cart.product.system(...variables).then(cart.summary.system),
|
cart.product.system(...variables).then(cart.summary.system),
|
||||||
300,
|
300,
|
||||||
6,
|
5,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -226,7 +226,7 @@ core.modules.connect("damper").then(() => {
|
||||||
damper: core.damper(
|
damper: core.damper(
|
||||||
(...variables) => catalog.product.system(...variables),
|
(...variables) => catalog.product.system(...variables),
|
||||||
200,
|
200,
|
||||||
2,
|
1,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default function damper(func, timeout = 300, force) {
|
||||||
// Requested execution with ignoring the timer
|
// Requested execution with ignoring the timer
|
||||||
|
|
||||||
// Deleting the force argument
|
// Deleting the force argument
|
||||||
if (typeof force === "number") args.splice(force - 1, force);
|
if (typeof force === "number") args.splice(force, force);
|
||||||
|
|
||||||
// Writing promise handlers into the arguments variable
|
// Writing promise handlers into the arguments variable
|
||||||
args.push(resolve, reject);
|
args.push(resolve, reject);
|
||||||
|
@ -60,7 +60,7 @@ export default function damper(func, timeout = 300, force) {
|
||||||
// Normal execution
|
// Normal execution
|
||||||
|
|
||||||
// Deleting the force argument
|
// Deleting the force argument
|
||||||
if (typeof force === "number") args.splice(force - 1, force);
|
if (typeof force === "number") args.splice(force, force);
|
||||||
|
|
||||||
// Writing promise handlers into the arguments variable
|
// Writing promise handlers into the arguments variable
|
||||||
args.push(resolve, reject);
|
args.push(resolve, reject);
|
||||||
|
|
|
@ -22,11 +22,12 @@ export default class delivery {
|
||||||
* Choose a delivery company
|
* Choose a delivery company
|
||||||
*
|
*
|
||||||
* @param {HTMLInputElement} company The button for choose a delivery company <input> (radio)
|
* @param {HTMLInputElement} company The button for choose a delivery company <input> (radio)
|
||||||
* @param {bool} force Ignore the damper? (false)
|
* @param {bool} [calculate=true] Calculate delivery if the server has confirmed the data is ready
|
||||||
|
* @param {bool} [force=false] Ignore the damper? (false)
|
||||||
*
|
*
|
||||||
* @return {bool} Did the execution complete without errors?
|
* @return {bool} Did the execution complete without errors?
|
||||||
*/
|
*/
|
||||||
static company = (company, force = false) => {
|
static company = (company, calculate = true, force = false) => {
|
||||||
if (company instanceof HTMLInputElement) {
|
if (company instanceof HTMLInputElement) {
|
||||||
// Initialized the delivery company <input> (radio) element
|
// Initialized the delivery company <input> (radio) element
|
||||||
|
|
||||||
|
@ -107,7 +108,7 @@ export default class delivery {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculating delivery
|
// Calculating delivery
|
||||||
this.calculate();
|
if (calculate) this.calculate();
|
||||||
|
|
||||||
if (json.company) {
|
if (json.company) {
|
||||||
// Received company property
|
// Received company property
|
||||||
|
@ -190,6 +191,7 @@ export default class delivery {
|
||||||
section.outerHTML = json.delivery.html;
|
section.outerHTML = json.delivery.html;
|
||||||
|
|
||||||
// Reinitializing the deliveries <section> element
|
// Reinitializing the deliveries <section> element
|
||||||
|
// section = document.getElementById("address");
|
||||||
section = deliveries.nextElementSibling;
|
section = deliveries.nextElementSibling;
|
||||||
|
|
||||||
for (const javascript of json.delivery.javascript) {
|
for (const javascript of json.delivery.javascript) {
|
||||||
|
@ -273,11 +275,20 @@ export default class delivery {
|
||||||
* Write name of the location for delivery
|
* Write name of the location for delivery
|
||||||
*
|
*
|
||||||
* @param {HTMLInputElement} location The input element with name of the location <input>
|
* @param {HTMLInputElement} location The input element with name of the location <input>
|
||||||
* @param {bool} force Ignore the damper? (false)
|
* @param {bool} [first=false] Select first element in <datalist> element, if received
|
||||||
|
* @param {bool} [calculate=false] Calculate delivery if the server has confirmed the data is ready
|
||||||
|
* @param {bool} [map=true] Move the map cursor to the new coordinates after calculating?
|
||||||
|
* @param {bool} [force=false] Ignore the damper? (false)
|
||||||
*
|
*
|
||||||
* @return {bool} Did the execution complete without errors?
|
* @return {bool} Did the execution complete without errors?
|
||||||
*/
|
*/
|
||||||
static location = (location, force = false) => {
|
static location = (
|
||||||
|
location,
|
||||||
|
first = false,
|
||||||
|
calculate = true,
|
||||||
|
map = true,
|
||||||
|
force = false,
|
||||||
|
) => {
|
||||||
if (location instanceof HTMLInputElement) {
|
if (location instanceof HTMLInputElement) {
|
||||||
// Initialized the location <input> element
|
// Initialized the location <input> element
|
||||||
|
|
||||||
|
@ -349,7 +360,7 @@ export default class delivery {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculating delivery
|
// Calculating delivery
|
||||||
this.calculate();
|
if (calculate) this.calculate(map);
|
||||||
|
|
||||||
if (json.location) {
|
if (json.location) {
|
||||||
// Received location
|
// Received location
|
||||||
|
@ -386,12 +397,12 @@ export default class delivery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.locations) {
|
|
||||||
// Reveived locations suggestions
|
|
||||||
|
|
||||||
// Initializing the locations suggestions <datalist> element
|
// Initializing the locations suggestions <datalist> element
|
||||||
let locations = document.getElementById("locations");
|
let locations = document.getElementById("locations");
|
||||||
|
|
||||||
|
if (json.locations) {
|
||||||
|
// Reveived locations suggestions
|
||||||
|
|
||||||
if (!(locations instanceof HTMLDataListElement)) {
|
if (!(locations instanceof HTMLDataListElement)) {
|
||||||
// Not initialized the locations suggestions <datalist> element
|
// Not initialized the locations suggestions <datalist> element
|
||||||
|
|
||||||
|
@ -410,6 +421,16 @@ export default class delivery {
|
||||||
|
|
||||||
// Reinitializing the locations suggestions <datalist> element
|
// Reinitializing the locations suggestions <datalist> element
|
||||||
locations = document.getElementById("locations");
|
locations = document.getElementById("locations");
|
||||||
|
|
||||||
|
if (first && locations.firstelementchild?.value) {
|
||||||
|
// Requested selecting first <option> element in the locations <datalist> element
|
||||||
|
|
||||||
|
// Writing value from the first <option> element in the locations <datalist> element
|
||||||
|
location.value = locations.firstelementchild.value;
|
||||||
|
|
||||||
|
// Sending value to the server (enter into recursion)
|
||||||
|
this.location(location, true, force);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,11 +521,12 @@ export default class delivery {
|
||||||
* Write name of the street for delivery
|
* Write name of the street for delivery
|
||||||
*
|
*
|
||||||
* @param {HTMLInputElement} element The input element with name of the street <input>
|
* @param {HTMLInputElement} element The input element with name of the street <input>
|
||||||
* @param {bool} force Ignore the damper? (false)
|
* @param {bool} [calculate=true] Calculate delivery if the server has confirmed the data is ready
|
||||||
|
* @param {bool} [force=false] Ignore the damper? (false)
|
||||||
*
|
*
|
||||||
* @return {bool} Did the execution complete without errors?
|
* @return {bool} Did the execution complete without errors?
|
||||||
*/
|
*/
|
||||||
static street = (street, force = false) => {
|
static street = (street, calculate = true, force = false) => {
|
||||||
if (street instanceof HTMLInputElement) {
|
if (street instanceof HTMLInputElement) {
|
||||||
// Initialized the street <input> element
|
// Initialized the street <input> element
|
||||||
|
|
||||||
|
@ -582,7 +604,7 @@ export default class delivery {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculating delivery
|
// Calculating delivery
|
||||||
this.calculate();
|
if (calculate) this.calculate();
|
||||||
|
|
||||||
if (json.street) {
|
if (json.street) {
|
||||||
// Received street property
|
// Received street property
|
||||||
|
@ -648,6 +670,163 @@ export default class delivery {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Apartamet (interface)
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Write number of apartament for delivery
|
||||||
|
*
|
||||||
|
* @param {HTMLInputElement} element The input element with name of the street <input>
|
||||||
|
* @param {bool} [calculate=true] Calculate delivery if the server has confirmed the data is ready
|
||||||
|
* @param {bool} [force=false] Ignore the damper? (false)
|
||||||
|
*
|
||||||
|
* @return {bool} Did the execution complete without errors?
|
||||||
|
*/
|
||||||
|
static apartament = (apartament, calculate = true, force = false) => {
|
||||||
|
if (apartament instanceof HTMLInputElement) {
|
||||||
|
// Initialized the apartament <input> element
|
||||||
|
|
||||||
|
// Deleting statuses from the apartament <input> element
|
||||||
|
apartament.classList.remove("success", "fail");
|
||||||
|
|
||||||
|
// Initializing the order <button> element
|
||||||
|
const order = document.getElementById("order");
|
||||||
|
|
||||||
|
if (order instanceof HTMLButtonElement) {
|
||||||
|
// Initializeg the order <button> element
|
||||||
|
|
||||||
|
// Disabling the order <button> element
|
||||||
|
order.setAttribute("disabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initializing the delivery data request <section> element
|
||||||
|
const request = document.getElementById("delivery_request");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Resolved
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Render the result of the resolved request
|
||||||
|
*
|
||||||
|
* @param {object} json
|
||||||
|
*
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
const resolved = (json) => {
|
||||||
|
if (json) {
|
||||||
|
// Received JSON-response
|
||||||
|
|
||||||
|
if (json.status) {
|
||||||
|
// Reveived status of execution
|
||||||
|
|
||||||
|
// Deleting statuses from the apartament <input> element
|
||||||
|
apartament.classList.remove("success", "fail");
|
||||||
|
|
||||||
|
// Writing status of execution as CSS class
|
||||||
|
apartament.classList.add(json.status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.ready) {
|
||||||
|
// Received readiness status
|
||||||
|
|
||||||
|
if (order instanceof HTMLButtonElement) {
|
||||||
|
// Initializeg the order <button> element
|
||||||
|
|
||||||
|
// Enabling the order <button> element
|
||||||
|
order.removeAttribute("disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request instanceof HTMLElement) {
|
||||||
|
// Initializeg the delivery data request <section> element
|
||||||
|
|
||||||
|
// Hiding the delivery data request <section> element
|
||||||
|
request.classList.add("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
core.modules.connect("telegram").then(() => {
|
||||||
|
// Imported the telegram module
|
||||||
|
|
||||||
|
core.telegram.api.HapticFeedback.notificationOccurred("success");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Not received readiness status or readiness status is false
|
||||||
|
|
||||||
|
if (request instanceof HTMLElement) {
|
||||||
|
// Initializeg the delivery data request <section> element
|
||||||
|
|
||||||
|
// Hiding the delivery data request <section> element
|
||||||
|
request.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculating delivery
|
||||||
|
if (calculate) this.calculate();
|
||||||
|
|
||||||
|
if (json.apartament) {
|
||||||
|
// Received apartament property
|
||||||
|
|
||||||
|
if (apartament.value !== json.apartament) {
|
||||||
|
// The value entered differs from what was written on the server
|
||||||
|
|
||||||
|
// Writing street property to the apartament element <input>
|
||||||
|
apartament.value = json.apartament;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Rejected
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Render the result of the rejected request
|
||||||
|
*
|
||||||
|
* @param {object} json
|
||||||
|
*
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
const rejected = (json) => {
|
||||||
|
if (json) {
|
||||||
|
// Received JSON-response
|
||||||
|
|
||||||
|
if (json.status) {
|
||||||
|
// Reveived status of execution
|
||||||
|
|
||||||
|
// Deleting statuses from the apartament <input> element
|
||||||
|
apartament.classList.remove("success", "fail");
|
||||||
|
|
||||||
|
// Writing status of execution as CSS class
|
||||||
|
apartament.classList.add(json.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
core.modules.connect("damper").then(
|
||||||
|
() => {
|
||||||
|
// Imported the damper module
|
||||||
|
|
||||||
|
// Execute under damper
|
||||||
|
this.write.damper("apartament", apartament.value, force)
|
||||||
|
.then(resolved, rejected);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
// Not imported the damper module
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
this.write.system("apartament", apartament.value, force)
|
||||||
|
.then(resolved, rejected);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Write (interface)
|
* @name Write (interface)
|
||||||
*
|
*
|
||||||
|
@ -661,21 +840,23 @@ export default class delivery {
|
||||||
* @description
|
* @description
|
||||||
* Calculate delivery by validated data from buffers
|
* Calculate delivery by validated data from buffers
|
||||||
*
|
*
|
||||||
|
* @param {bool} [map=false] Move the map cursor to the new coordinates after calculating?
|
||||||
|
*
|
||||||
* @return {bool} Did the execution complete without errors?
|
* @return {bool} Did the execution complete without errors?
|
||||||
*/
|
*/
|
||||||
static calculate = () => {
|
static calculate = (map = false) => {
|
||||||
core.modules.connect("damper").then(
|
core.modules.connect("damper").then(
|
||||||
() => {
|
() => {
|
||||||
// Imported the damper module
|
// Imported the damper module
|
||||||
|
|
||||||
// Execute under damper
|
// Execute under damper
|
||||||
this.calculate.damper();
|
this.calculate.damper(map);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
// Not imported the damper module
|
// Not imported the damper module
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
this.calculate.system();
|
this.calculate.system(map);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -707,7 +888,7 @@ core.modules.connect("damper").then(() => {
|
||||||
damper: core.damper(
|
damper: core.damper(
|
||||||
(...variables) => delivery.write.system(...variables),
|
(...variables) => delivery.write.system(...variables),
|
||||||
400,
|
400,
|
||||||
3,
|
2,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -723,6 +904,8 @@ core.modules.connect("damper").then(() => {
|
||||||
*
|
*
|
||||||
* @memberof delivery.calculate
|
* @memberof delivery.calculate
|
||||||
*
|
*
|
||||||
|
* @param {bool} [map=false] Move the map cursor to the new coordinates after calculating?
|
||||||
|
*
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
damper: core.damper(
|
damper: core.damper(
|
||||||
|
@ -820,9 +1003,12 @@ Object.assign(
|
||||||
*
|
*
|
||||||
* @memberof delivery.calculate
|
* @memberof delivery.calculate
|
||||||
*
|
*
|
||||||
|
* @param {bool} [map=false] Move the map cursor to the new coordinates after calculating?
|
||||||
|
*
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
async system(
|
async system(
|
||||||
|
map = false,
|
||||||
resolve = () => {},
|
resolve = () => {},
|
||||||
reject = () => {},
|
reject = () => {},
|
||||||
) {
|
) {
|
||||||
|
@ -1035,6 +1221,7 @@ Object.assign(
|
||||||
document.dispatchEvent(
|
document.dispatchEvent(
|
||||||
new CustomEvent("core.delivery.calculated", {
|
new CustomEvent("core.delivery.calculated", {
|
||||||
detail: {
|
detail: {
|
||||||
|
map,
|
||||||
json,
|
json,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -76,7 +76,7 @@ core.modules.connect("damper").then(() => {
|
||||||
damper: core.damper(
|
damper: core.damper(
|
||||||
(...variables) => session.buffer.write.system(...variables),
|
(...variables) => session.buffer.write.system(...variables),
|
||||||
300,
|
300,
|
||||||
3,
|
2,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -53,23 +53,34 @@ main>section#delivery>div.column>section {
|
||||||
gap: 0.7rem;
|
gap: 0.7rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
main>section#delivery>div.column>section.cdek>div#address {
|
main>section#delivery>div.column>section.cdek#address>div {
|
||||||
flex-flow: row wrap;
|
flex-flow: row wrap;
|
||||||
gap: 0.7rem;
|
gap: 0.7rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
main>section#delivery>div.column>section.cdek>div#address>input#location {
|
main>section#delivery>div.column>section.cdek#address>div.merged {
|
||||||
|
margin-top: -0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
main>section#delivery>div.column>section.cdek#address>div>input#location {
|
||||||
min-width: max(6rem, 20%);
|
min-width: max(6rem, 20%);
|
||||||
width: min(6rem, 100%);
|
width: min(6rem, 100%);
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
main>section#delivery>div.column>section.cdek>div#address>input#street {
|
main>section#delivery>div.column>section.cdek#address>div>input#street {
|
||||||
min-width: max(10rem, 30%);
|
min-width: max(10rem, 30%);
|
||||||
width: min(10rem, 100%);
|
width: min(10rem, 100%);
|
||||||
flex-grow: 10;
|
flex-grow: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main>section#delivery>div.column>section.cdek#address>div>input#apartament {
|
||||||
|
width: min(4rem, 100%);
|
||||||
|
flex-shrink: 1;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
main>section#delivery>div.column>section.cdek>div#map {
|
main>section#delivery>div.column>section.cdek>div#map {
|
||||||
height: 203px;
|
height: 203px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -81,6 +92,8 @@ main>section#delivery>div.column>section.cdek>div#map * {
|
||||||
|
|
||||||
main>section#delivery>div.column>section.cdek>div#map:not(.office, .door)>div>div:first-child,
|
main>section#delivery>div.column>section.cdek>div#map:not(.office, .door)>div>div:first-child,
|
||||||
main>section#delivery>div.column>section.cdek>div#map>div>div:last-child a[href="https://cdek.ru"],
|
main>section#delivery>div.column>section.cdek>div#map>div>div:last-child a[href="https://cdek.ru"],
|
||||||
|
main>section#delivery>div.column>section.cdek>div#map>div>div:last-child>div:first-child>div>ymaps>ymaps:nth-of-type(3)>ymaps:last-child,
|
||||||
|
main>section#delivery>div.column>section.cdek>div#map>div>div:last-child>div:first-child>div>ymaps>ymaps:nth-of-type(4),
|
||||||
main>section#delivery>div.column>section.cdek>div#map>div>div:last-child>div:first-child>div>ymaps>ymaps:last-of-type {
|
main>section#delivery>div.column>section.cdek>div#map>div>div:last-child>div:first-child>div>ymaps>ymaps:last-of-type {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +154,7 @@ main>section#delivery>div.column>section.cdek>div#map.office.door>div>div:last-c
|
||||||
border-radius: 0.75rem !important;
|
border-radius: 0.75rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* main>section#delivery>div.column:not(:has(div#deliveries>input:checked))>div#address {
|
/* main>section#delivery>div.column:not(:has(div#deliveries>input:checked))#address>div {
|
||||||
display: none;
|
display: none;
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
|
|
@ -289,6 +289,7 @@ input {
|
||||||
.success {
|
.success {
|
||||||
/* color: var(--tg-theme-hint-color, green); */
|
/* color: var(--tg-theme-hint-color, green); */
|
||||||
color: #697d30;
|
color: #697d30;
|
||||||
|
color: #3adb40;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fail {
|
.fail {
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
var cdek;
|
|
||||||
var ready = false;
|
|
||||||
var moving = true;
|
|
||||||
|
|
||||||
function init(location) {
|
|
||||||
import('https://cdn.jsdelivr.net/npm/@cdek-it/widget@3')
|
import('https://cdn.jsdelivr.net/npm/@cdek-it/widget@3')
|
||||||
.then(module => {
|
.then(module => {
|
||||||
|
|
||||||
|
let cdek;
|
||||||
|
let ready = false;
|
||||||
|
|
||||||
|
const map = document.getElementById('map');
|
||||||
|
|
||||||
|
function init(location) {
|
||||||
|
|
||||||
cdek = new window.CDEKWidget({
|
cdek = new window.CDEKWidget({
|
||||||
from: {
|
from: {
|
||||||
code: 248,
|
code: 248,
|
||||||
|
@ -29,25 +33,33 @@
|
||||||
office: [234, 136, 185, 368, 378, 498, 2323, 2360, 510, 291],
|
office: [234, 136, 185, 368, 378, 498, 2323, 2360, 510, 291],
|
||||||
door: [233, 137, 186, 2322, 294],
|
door: [233, 137, 186, 2322, 294],
|
||||||
},
|
},
|
||||||
defaultLocation: [location?.longitude || {{ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.data.longitude ?? 37.622513 }}, location?.latitude || {{ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.data.latitude ?? 55.75322 }}],
|
defaultLocation: [location?.longitude || {{ session.buffer.delivery[session.buffer.delivery.company].longitude ?? session.buffer.delivery[session.buffer.delivery.company].location.data.longitude ?? 37.622513 }}, location?.latitude || {{ session.buffer.delivery[session.buffer.delivery.company].latitude ?? session.buffer.delivery[session.buffer.delivery.company].location.data.latitude ?? 55.75322 }}],
|
||||||
onReady() {
|
onReady() {
|
||||||
// const map = document.getElementById('map');
|
|
||||||
|
|
||||||
// map?.style.setProperty('--animation-end-height', '240px');
|
// map?.style.setProperty('--animation-end-height', '240px');
|
||||||
// map?.classList.add('animated', 'slide-down');
|
// map?.classList.add('animated', 'slide-down');
|
||||||
},
|
},
|
||||||
onCalculate(tariffs, address) {
|
onCalculate(tariffs, address) {
|
||||||
// Deleting the delivery cost <span> element
|
// Deleting the delivery cost <span> element
|
||||||
document.getElementById("cost_delivery")?.remove();
|
//document.getElementById("cost_delivery")?.remove();
|
||||||
|
|
||||||
// Deleting the delivery days <span> element
|
// Deleting the delivery days <span> element
|
||||||
document.getElementById("shipping")?.remove();
|
//document.getElementById("shipping")?.remove();
|
||||||
|
|
||||||
// Disablind the order button
|
// Disablind the order button
|
||||||
document.getElementById("order")?.setAttribute('disabled', true);
|
//document.getElementById("order")?.setAttribute('disabled', true);
|
||||||
|
|
||||||
|
//
|
||||||
|
// map.style.setProperty('height', '300px');
|
||||||
},
|
},
|
||||||
onChoose(type, tariff, address) {
|
onChoose(type, tariff, address) {
|
||||||
moving = false;
|
//
|
||||||
|
// map.style.removeProperty('height');
|
||||||
|
|
||||||
|
//
|
||||||
|
const apartament = document.getElementById('apartament');
|
||||||
|
|
||||||
|
if (type === 'door') apartament.classList.remove('hidden');
|
||||||
|
else apartament.classList.add('hidden');
|
||||||
|
|
||||||
// Deleting the delivery cost <span> element
|
// Deleting the delivery cost <span> element
|
||||||
document.getElementById("cost_delivery")?.remove();
|
document.getElementById("cost_delivery")?.remove();
|
||||||
|
@ -62,39 +74,96 @@
|
||||||
() => {
|
() => {
|
||||||
// Imported the damper module
|
// Imported the damper module
|
||||||
|
|
||||||
|
// Execute under damper
|
||||||
|
if (type)
|
||||||
|
core.delivery.write.damper("type", type, true);
|
||||||
|
|
||||||
// Execute under damper
|
// Execute under damper
|
||||||
if (tariff)
|
if (tariff)
|
||||||
core.delivery.write.damper("type", tariff.tariff_code, true);
|
core.delivery.write.damper("tariff", tariff.tariff_code, true);
|
||||||
|
|
||||||
|
// Execute under damper
|
||||||
|
if (address.location) {
|
||||||
|
core.delivery.write.damper("longitude", address.location[0], true);
|
||||||
|
core.delivery.write.damper("latitude", address.location[1], true);
|
||||||
|
} else if (address.position) {
|
||||||
|
console.log(address.position);
|
||||||
|
core.delivery.write.damper("longitude", address.position[0], true);
|
||||||
|
core.delivery.write.damper("latitude", address.position[1], true);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
// Not imported the damper module
|
// Not imported the damper module
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
if (type)
|
||||||
|
core.delivery.write.system("type", type, true);
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
if (tariff)
|
if (tariff)
|
||||||
core.delivery.write.system("type", tariff.tariff_code, true);
|
core.delivery.write.system("tariff", tariff.tariff_code, true);
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
if (address.location) {
|
||||||
|
core.delivery.write.system("longitude", address.location[0], true);
|
||||||
|
core.delivery.write.system("latitude", address.location[1], true);
|
||||||
|
} else if (address.position) {
|
||||||
|
core.delivery.write.system("longitude", address.position[0], true);
|
||||||
|
core.delivery.write.system("latitude", address.position[1], true);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
setTimeout(() => {
|
|
||||||
|
|
||||||
//
|
//
|
||||||
const location = document.getElementById('location');
|
const location = document.getElementById('location');
|
||||||
|
|
||||||
if (location instanceof HTMLInputElement) {
|
if (location instanceof HTMLInputElement) {
|
||||||
//
|
//
|
||||||
|
/**
|
||||||
|
// Declaring location value buffer
|
||||||
|
let value = address.city;
|
||||||
|
|
||||||
|
// Declaring variables for structure of the address
|
||||||
|
let country, region, sub_region;
|
||||||
|
|
||||||
|
if (type === 'office') {
|
||||||
|
// Office
|
||||||
|
|
||||||
//
|
//
|
||||||
|
region = address.region;
|
||||||
|
} else {
|
||||||
|
// Door
|
||||||
|
|
||||||
|
// Initializing components of the address
|
||||||
|
const components = address.components.reverse();
|
||||||
|
|
||||||
|
//
|
||||||
|
country = components[0].name;
|
||||||
|
region = components[1].name;
|
||||||
|
sub_region = components[2].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (region && region !== address.city)
|
||||||
|
value += ", " + region;
|
||||||
|
if (sub_region && sub_region !== region && sub_region !== address.city)
|
||||||
|
value += ", " + sub_region;
|
||||||
|
if (country)
|
||||||
|
value += ", " + country;
|
||||||
|
|
||||||
|
//
|
||||||
|
location.value = value;
|
||||||
|
*/
|
||||||
|
|
||||||
location.value = address.city;
|
location.value = address.city;
|
||||||
|
|
||||||
//
|
//
|
||||||
core.delivery.location(location, false, true);
|
core.delivery.location(location, true, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
//
|
//
|
||||||
const street = document.getElementById('street');
|
const street = document.getElementById('street');
|
||||||
|
|
||||||
if (type === 'office') {
|
if (type === 'office') {
|
||||||
//
|
// Office
|
||||||
|
|
||||||
if (street instanceof HTMLInputElement) {
|
if (street instanceof HTMLInputElement) {
|
||||||
//
|
//
|
||||||
|
@ -103,10 +172,10 @@
|
||||||
street.value = address.address;
|
street.value = address.address;
|
||||||
|
|
||||||
//
|
//
|
||||||
core.delivery.street(street, true);
|
core.delivery.street(street, true, false, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//
|
// Door
|
||||||
|
|
||||||
if (street instanceof HTMLInputElement) {
|
if (street instanceof HTMLInputElement) {
|
||||||
//
|
//
|
||||||
|
@ -115,12 +184,9 @@
|
||||||
street.value = address.name;
|
street.value = address.name;
|
||||||
|
|
||||||
//
|
//
|
||||||
core.delivery.street(street, true);
|
core.delivery.street(street, true, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
|
||||||
|
|
||||||
map = true;
|
|
||||||
|
|
||||||
// Initializing the delivery data request <section> element
|
// Initializing the delivery data request <section> element
|
||||||
const request = document.getElementById("delivery_request");
|
const request = document.getElementById("delivery_request");
|
||||||
|
@ -130,9 +196,7 @@
|
||||||
|
|
||||||
// Hiding the delivery data request <section> element
|
// Hiding the delivery data request <section> element
|
||||||
request.classList.add("hidden");
|
request.classList.add("hidden");
|
||||||
}}, 1000);
|
}
|
||||||
}, 500);
|
|
||||||
}, 500);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -144,7 +208,6 @@
|
||||||
length: Math.ceil({{ product.z is empty ? 0 : product.z }})
|
length: Math.ceil({{ product.z is empty ? 0 : product.z }})
|
||||||
});
|
});
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,7 +226,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('core.delivery.calculated', (event) => {
|
document.addEventListener('core.delivery.calculated', (event) => {
|
||||||
if (map && event.detail.json.longitude && event.detail.json.latitude)
|
if (event.detail.map && event.detail.json.longitude && event.detail.json.latitude)
|
||||||
cdek?.updateLocation([event.detail.json.longitude, event.detail.json.latitude]);
|
cdek?.updateLocation([event.detail.json.longitude, event.detail.json.latitude]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -187,3 +250,4 @@
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
});
|
||||||
|
|
|
@ -1,20 +1,26 @@
|
||||||
<section class="cdek column">
|
<section id="address" class="cdek column">
|
||||||
<div id="address" class="row">
|
<div class="row">
|
||||||
<input id="location"
|
<input id="location"
|
||||||
class="identifier{% if session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.identifier ?? session.buffer.delivery.location %} success{% endif %}"
|
class="identifier{% if session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.identifier ?? session.buffer.delivery.location %} success{% endif %}"
|
||||||
|
|
||||||
placeholder="{{ language.name == 'ru' ? 'Город' : 'location' }}" value="{{
|
placeholder="{{ language.name == 'ru' ? 'Город' : 'location' }}" value="{{
|
||||||
session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.name
|
session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.name
|
||||||
? session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.name
|
? session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.name
|
||||||
~ ', '
|
~ ', '
|
||||||
~ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.structure|reverse|join(', ')
|
~ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.structure|reverse|join(', ')
|
||||||
: session.buffer.delivery.location }}"
|
: session.buffer.delivery.location }}" "
|
||||||
onkeyup="core.delivery.location(this)" oninput="core.delivery.location(this)" tabindex="6" />
|
onkeyup=" core.delivery.location(this)" oninput="core.delivery.location(this)" tabindex="6" />
|
||||||
|
</div>
|
||||||
|
<div class="row merged">
|
||||||
<input id="street" {% if session.buffer.delivery[account.buffer.delivery.company ??
|
<input id="street" {% if session.buffer.delivery[account.buffer.delivery.company ??
|
||||||
session.buffer.delivery.company].street %} class="success" {% endif %}
|
session.buffer.delivery.company].street %} class="success" {% endif %}
|
||||||
placeholder="{{ language.name == 'ru' ? 'Улица' : 'Street' }}"
|
placeholder="{{ language.name == 'ru' ? 'Улица' : 'Street' }}"
|
||||||
value="{{ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].street ?? session.buffer.delivery.street }}"
|
value="{{ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].street ?? session.buffer.delivery.street }}"
|
||||||
onkeyup="core.delivery.street(this)" oninput="core.delivery.street(this)" tabindex="6" />
|
onkeyup="core.delivery.street(this)" oninput="core.delivery.street(this)" tabindex="6" />
|
||||||
|
<input id="apartament" class="{% if session.buffer.delivery[account.buffer.delivery.company ??
|
||||||
|
session.buffer.delivery.company].apartament %} success{% endif %}{% if session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].type != 'door' %} hidden{% endif %}"
|
||||||
|
placeholder="{{ language.name == 'ru' ? 'Квартира' : 'Apartament' }}"
|
||||||
|
value="{{ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].apartament ?? session.buffer.delivery.apartament }}"
|
||||||
|
onkeyup="core.delivery.apartament(this)" oninput="core.delivery.apartament(this)" tabindex="6" />
|
||||||
</div>
|
</div>
|
||||||
<div id="map" class="rounded">
|
<div id="map" class="rounded">
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue