update delivery
This commit is contained in:
parent
58f065f312
commit
557eebc91f
|
@ -148,7 +148,7 @@ final class catalog extends core
|
|||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: ['catalog_filters_brand' => $brand ?? null]));
|
||||
|
||||
// Writing to the current implementator of the buffer
|
||||
$this->session->buffer = ['catalog' => ['filters' => ['brand' => $brand ?? null]]] + $this->session->buffer;
|
||||
$this->session->buffer = ['catalog' => ['filters' => ['brand' => $brand ?? null]]] + $this->session->buffer ?? [];
|
||||
|
||||
// Initialize buffer of filters query (AQL)
|
||||
$_sort = 'd.position ASC, d.name ASC, d.created DESC';
|
||||
|
|
|
@ -78,7 +78,7 @@ final class delivery extends core
|
|||
'ready' => false
|
||||
];
|
||||
|
||||
if (!empty($company)) {
|
||||
if (isset($company)) {
|
||||
// Received company name
|
||||
|
||||
if (mb_strlen($company) < 65) {
|
||||
|
@ -113,6 +113,15 @@ final class delivery extends core
|
|||
|
||||
// Writing readiness status to the buffer of the response
|
||||
$response['ready'] = true;
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,7 +134,7 @@ final class delivery extends core
|
|||
// Deinitializing variable for normalized value of the parameter
|
||||
unset($normalized);
|
||||
}
|
||||
} else if (!empty($location)) {
|
||||
} else if (isset($location)) {
|
||||
// Received location name
|
||||
|
||||
if (mb_strlen($location) < 257) {
|
||||
|
@ -143,6 +152,12 @@ final class delivery extends core
|
|||
// 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
|
||||
|
||||
if (!empty($separated)) {
|
||||
// Serapated location name
|
||||
|
||||
|
@ -155,12 +170,6 @@ final class delivery extends core
|
|||
// Deinitializing unnecessary variables
|
||||
unset($separated, $value);
|
||||
|
||||
// Initialization buffer of delivery parameters
|
||||
$delivery = $this->account?->buffer['delivery'] ?? $this->session?->buffer['delivery'] ?? [];
|
||||
|
||||
if (isset($delivery['company'])) {
|
||||
// Initialized delivery company
|
||||
|
||||
// Declaring of universalized locations buffer
|
||||
$locations = null;
|
||||
|
||||
|
@ -185,7 +194,7 @@ final class delivery extends core
|
|||
}
|
||||
|
||||
// Deinitializing of response data from CDEK
|
||||
unset($cdek, $location);
|
||||
unset($cdek);
|
||||
}
|
||||
|
||||
if (!empty($locations)) {
|
||||
|
@ -197,13 +206,13 @@ final class delivery extends core
|
|||
// Initialization of 80% of received input values (required minimum to match location characteristics)
|
||||
$minimum = count($normalized) * 80 / 100;
|
||||
|
||||
foreach ($locations as $location) {
|
||||
foreach ($locations as $_location) {
|
||||
// Iterating over locations
|
||||
|
||||
// Declaring variable with score of matching input values with location characteristics
|
||||
$score = 0;
|
||||
|
||||
foreach ([$location['name'], ...$location['structure']] as $value) {
|
||||
foreach ([$_location['name'], ...$_location['structure']] as $value) {
|
||||
// Iterating over location characteristics
|
||||
|
||||
foreach ($normalized as $_value) {
|
||||
|
@ -219,7 +228,7 @@ final class delivery extends core
|
|||
// More than $minimum matches found
|
||||
|
||||
// Writing to buffer of validated locations by normalized parts of location name
|
||||
$buffer[] = $location;
|
||||
$buffer[] = $_location;
|
||||
|
||||
// Exit from iteration of location characteristics
|
||||
break 2;
|
||||
|
@ -236,7 +245,7 @@ final class delivery extends core
|
|||
}
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($location);
|
||||
unset($_location);
|
||||
|
||||
// Reinitializating locations from buffer of validated locations by input values
|
||||
$locations = $buffer;
|
||||
|
@ -253,10 +262,13 @@ final class delivery extends core
|
|||
// Deinitializing unnecessary variables
|
||||
unset($name);
|
||||
|
||||
// Writing result value of location name
|
||||
$result = $locations[0]['name'] . ', ' . implode(', ', array_reverse($locations[0]['structure']));
|
||||
|
||||
// Writing location data to the buffer of the response
|
||||
/* $response['location'] = [
|
||||
'identifier' => $locations[0]['identifier'],
|
||||
'input' => $result = $locations[0]['name'] . ', ' . implode(', ', array_reverse($locations[0]['structure']))
|
||||
'input' => $result
|
||||
]; */
|
||||
|
||||
if (!empty($delivery[$delivery['company']]['street'])) {
|
||||
|
@ -264,6 +276,34 @@ final class delivery extends core
|
|||
|
||||
// Writing readiness status to the buffer of the response
|
||||
$response['ready'] = true;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Writing status of execution to the buffer of the response
|
||||
|
@ -275,29 +315,39 @@ final class delivery extends core
|
|||
// Not identificated location
|
||||
|
||||
// Writing to the session buffer
|
||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_location' => null]));
|
||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||
$name_location = 'delivery_' . $delivery['company'] . '_location' => null,
|
||||
$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 => null]));
|
||||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||
$name_location => null,
|
||||
$name_ready => false,
|
||||
$name_cost => null,
|
||||
$name_days => null
|
||||
]));
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($name);
|
||||
unset($name_location, $name_ready, $name_cost, $name_days);
|
||||
|
||||
// Declaring buffer of data to send
|
||||
$buffer = [];
|
||||
|
||||
foreach ($locations as $location) {
|
||||
foreach ($locations as $_location) {
|
||||
// Iterating over locations
|
||||
|
||||
// Writing to buffer of data to send
|
||||
$buffer[] = [
|
||||
'name' => $location['name'],
|
||||
'structure' => $location['structure']
|
||||
'name' => $_location['name'],
|
||||
'structure' => $_location['structure']
|
||||
];
|
||||
}
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($location);
|
||||
unset($_location);
|
||||
|
||||
// Writing locations into response buffer
|
||||
$response['locations'] = $buffer;
|
||||
|
@ -309,33 +359,66 @@ final class delivery extends core
|
|||
// Not found locations
|
||||
|
||||
// Writing to the session buffer
|
||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [$name = 'delivery_' . $delivery['company'] . '_location' => null]));
|
||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||
$name_location = 'delivery_' . $delivery['company'] . '_location' => null,
|
||||
$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 => null]));
|
||||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: [
|
||||
$name_location => null,
|
||||
$name_ready => false,
|
||||
$name_cost => null,
|
||||
$name_days => null
|
||||
]));
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($name);
|
||||
unset($name_location, $name_ready, $name_cost, $name_days);
|
||||
}
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($locations);
|
||||
unset($normalized);
|
||||
} else {
|
||||
// Value is empty after separating
|
||||
|
||||
// Not initialized required parameters
|
||||
|
||||
// Writing to the session buffer
|
||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: [
|
||||
$name_location = 'delivery_' . $delivery['company'] . '_location' => null,
|
||||
$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_location => null,
|
||||
$name_ready => false,
|
||||
$name_cost => null,
|
||||
$name_days => null
|
||||
]));
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($name_location, $name_ready, $name_cost, $name_days);
|
||||
}
|
||||
}
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($delivery, $normalized);
|
||||
}
|
||||
|
||||
// Writing to the session buffer
|
||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: ['delivery_location' => $result]));
|
||||
$this->core->request(new request('PATCH', '/session/write', protocol::http_3, parameters: ['delivery_location' => empty($result) ? $location : $result]));
|
||||
|
||||
// Writing to the account buffer
|
||||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: ['delivery_location' => $result]));
|
||||
$this->core->request(new request('PATCH', '/account/write', protocol::http_3, parameters: ['delivery_location' => empty($result) ? $location : $result]));
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($result, $normalized);
|
||||
unset($location, $result, $normalized);
|
||||
}
|
||||
} else if (!empty($street)) {
|
||||
} else if (isset($street)) {
|
||||
// Received sreet
|
||||
|
||||
if (mb_strlen($street) < 129) {
|
||||
|
@ -365,11 +448,39 @@ final class delivery extends core
|
|||
// Deinitializing unnecessary variables
|
||||
unset($name);
|
||||
|
||||
if (!empty($delivery[$delivery['company']]['location'])) {
|
||||
if (!empty($normalized) && !empty($delivery[$delivery['company']]['location'])) {
|
||||
// Required parameters initialized: company, location, street
|
||||
|
||||
// Writing readiness status to the buffer of the response
|
||||
$response['ready'] = true;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Writing status of execution to the buffer of the response
|
||||
|
|
|
@ -0,0 +1,477 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace mirzaev\arming_bot\controllers;
|
||||
|
||||
// Files of the project
|
||||
use mirzaev\arming_bot\controllers\core,
|
||||
mirzaev\arming_bot\models\cart as model,
|
||||
mirzaev\arming_bot\models\product,
|
||||
mirzaev\arming_bot\models\menu,
|
||||
mirzaev\arming_bot\models\enumerations\language;
|
||||
|
||||
// Framework for PHP
|
||||
use mirzaev\minimal\http\enumerations\content,
|
||||
mirzaev\minimal\http\enumerations\status;
|
||||
|
||||
/**
|
||||
* Controller of cart
|
||||
*
|
||||
* @package mirzaev\arming_bot\controllers
|
||||
*
|
||||
* @param model|null $cart Instance of the cart
|
||||
* @param array $errors Registry of errors
|
||||
*
|
||||
* @method null index() HTML-document with shopping cart and delivery settings
|
||||
* @method null product(int|string|null $identifier, ?string $type, int|string|null $amount) Change status of the product in the cart
|
||||
* @method null summary() Information about products in the cart
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class cart extends core
|
||||
{
|
||||
/**
|
||||
* Cart
|
||||
*
|
||||
* @var model|null $cart Instance of the cart
|
||||
*/
|
||||
protected readonly ?model $cart;
|
||||
|
||||
/**
|
||||
* Errors
|
||||
*
|
||||
* @var array $errors Registry of errors
|
||||
*/
|
||||
protected array $errors = [
|
||||
'session' => [],
|
||||
'account' => [],
|
||||
'menu' => [],
|
||||
'cart' => []
|
||||
];
|
||||
|
||||
/**
|
||||
* Index
|
||||
*
|
||||
* HTML-document with shopping cart and delivery settings
|
||||
*
|
||||
* @param null
|
||||
*/
|
||||
public function index(): null
|
||||
{
|
||||
if (isset($menu)) {
|
||||
//
|
||||
|
||||
} else {
|
||||
// Not received ... menu
|
||||
|
||||
// Search for filters and write to the buffer of global variables of view templater
|
||||
$this->view->menu = menu::_read(
|
||||
return: 'MERGE(d, { name: d.name.@language })',
|
||||
sort: 'd.style.order ASC, d.created DESC, d._key DESC',
|
||||
amount: 4,
|
||||
parameters: ['language' => $this->language->name],
|
||||
errors: $this->errors['menu']
|
||||
);
|
||||
}
|
||||
|
||||
// Initializing the cart
|
||||
$this->cart ??= $this->account?->cart() ?? $this->session?->cart();
|
||||
|
||||
// Initializing the cart data
|
||||
$this->view->cart = [
|
||||
'summary' => $this->cart?->summary(currency: $this->currency),
|
||||
'products' => $this->cart?->products(language: $this->language, currency: $this->currency)
|
||||
];
|
||||
|
||||
// Initializing types of avaiabld deliveries
|
||||
$this->view->deliveries = [
|
||||
'cdek' => [
|
||||
'label' => 'CDEK'
|
||||
]
|
||||
];
|
||||
|
||||
if (str_contains($this->request->headers['accept'], content::json->value)) {
|
||||
// Request for JSON response
|
||||
|
||||
// Sending response
|
||||
$this->response
|
||||
->start()
|
||||
->clean()
|
||||
->sse()
|
||||
->json([
|
||||
'main' => '',
|
||||
'errors' => $this->errors
|
||||
])
|
||||
->validate($this->request)
|
||||
?->body()
|
||||
->end();
|
||||
} else if (str_contains($this->request->headers['accept'], content::any->value)) {
|
||||
// Request for any response
|
||||
|
||||
// Render page
|
||||
$page = $this->view->render('cart/page.html', [
|
||||
'h2' => $this->language === language::ru ? 'Корзина' : 'Cart' // @see https://git.mirzaev.sexy/mirzaev/huesos/issues/1
|
||||
]);
|
||||
|
||||
// Sending response
|
||||
$this->response
|
||||
->start()
|
||||
->clean()
|
||||
->sse()
|
||||
->write($page)
|
||||
->validate($this->request)
|
||||
?->body()
|
||||
->end();
|
||||
|
||||
// Deinitializing rendered page
|
||||
unset($page);
|
||||
}
|
||||
|
||||
// Exit (success/fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Product
|
||||
*
|
||||
* Change status of the product in the cart
|
||||
*
|
||||
* @param int|string|null $identifier Product identifier
|
||||
* @param string|null $type Action type (toggle, write, delete, set)
|
||||
* @param int|string|null $amount Amount of actions with the product (for write, delete and differently used by set)
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* @todo
|
||||
* 1. Add a limit on adding products to the cart based on the number of products in stock
|
||||
*/
|
||||
public function product(
|
||||
int|string|null $identifier = null,
|
||||
?string $type = null,
|
||||
int|string|null $amount = null
|
||||
): null {
|
||||
if (str_contains($this->request->headers['accept'], content::json->value)) {
|
||||
// Request for JSON response
|
||||
|
||||
// Declaring buffer with amount of the product in the cart
|
||||
$cart = 0;
|
||||
|
||||
// Validating @todo add throwing errors
|
||||
if (isset($identifier) && preg_match('/[\d]+/', urldecode($identifier), $matches)) $identifier = (int) $matches[0];
|
||||
else unset($identifier);
|
||||
|
||||
if (isset($identifier)) {
|
||||
// Received and validated identfier of the product
|
||||
|
||||
// Search for the product
|
||||
$product = product::read(
|
||||
filter: "d.identifier == @identifier && d.deleted != true && d.hidden != true",
|
||||
sort: 'd.created DESC',
|
||||
amount: 1,
|
||||
parameters: ['identifier' => $identifier],
|
||||
errors: $this->errors['cart']
|
||||
);
|
||||
|
||||
if ($product instanceof product) {
|
||||
// Initialized the product
|
||||
|
||||
// Initializing the cart
|
||||
$this->cart ??= $this->account?->cart() ?? $this->session?->cart();
|
||||
|
||||
if ($this->cart instanceof model) {
|
||||
// Initialized the cart
|
||||
|
||||
// Initializing buffer with amount of the product in the cart
|
||||
$cart = $this->cart->count(product: $product, limit: 100, errors: $this->errors['cart']) ?? 0;
|
||||
|
||||
if ($this->cart instanceof model) {
|
||||
// Initialized the cart
|
||||
|
||||
// Validating @todo add throwing errors
|
||||
if (isset($type) && preg_match('/[\w]+/', urldecode($type), $matches)) $type = $matches[0];
|
||||
else unset($type);
|
||||
|
||||
if (isset($type)) {
|
||||
// Received and validated type of action with the product
|
||||
|
||||
if ($type === 'toggle') {
|
||||
// Write the product to the cart if is not in the cart and vice versa
|
||||
|
||||
if ($cart > 0) {
|
||||
// The cart has the product
|
||||
|
||||
// Deleting the product from the cart
|
||||
$this->cart->delete(product: $product, amount: $cart, errors: $this->errors['cart']);
|
||||
|
||||
// Reinitializing the buffer with amount of the product in the cart
|
||||
$cart = 0;
|
||||
} else {
|
||||
// The cart has no the product
|
||||
|
||||
// Writing the product to the cart
|
||||
$this->cart->write(product: $product, amount: 1, errors: $this->errors['cart']);
|
||||
|
||||
// Reinitializing the buffer with amount of the product in the cart
|
||||
$cart = 1;
|
||||
}
|
||||
} else {
|
||||
// Received not the "toggle" command
|
||||
|
||||
// Validating @todo add throwing errors
|
||||
if (isset($amount) && preg_match('/[\d]+/', urldecode($amount), $matches)) $amount = (int) $matches[0];
|
||||
else unset($amount);
|
||||
|
||||
if (isset($amount)) {
|
||||
// Received and validated amount parameter for action with the product
|
||||
|
||||
if ($type === 'write') {
|
||||
// Increase amount of the product in the cart
|
||||
|
||||
if ($cart + $amount < 101) {
|
||||
// Validated amount to wrting
|
||||
|
||||
// Writing the product to the cart
|
||||
$this->cart->write(product: $product, amount: $amount, errors: $this->errors['cart']);
|
||||
|
||||
// Reinitialize the buffer with amount of the product in the cart
|
||||
$cart += $amount;
|
||||
}
|
||||
} else if ($type === 'delete') {
|
||||
// Decrease amount of the product in the cart
|
||||
|
||||
if ($cart - $amount > -1) {
|
||||
// Validated amount to deleting
|
||||
|
||||
// Deleting the product from the cart
|
||||
$this->cart->delete(product: $product, amount: $amount, errors: $this->errors['cart']);
|
||||
|
||||
// Reinitialize the buffer with amount of the product in the cart
|
||||
$cart -= $amount;
|
||||
}
|
||||
} else if ($type === 'set') {
|
||||
// Set amount of the product in the cart
|
||||
|
||||
if ($amount > -1 && $amount < 101) {
|
||||
// Validated amount to setting
|
||||
|
||||
if ($amount > $cart) {
|
||||
// Requested amount more than actual amount of the product in the cart
|
||||
|
||||
// Writing the product to the cart
|
||||
$this->cart->write(product: $product, amount: $amount - $cart, errors: $this->errors['cart']);
|
||||
} else {
|
||||
// Requested amount less than actual amount of the product in the cart
|
||||
|
||||
// Deleting the product from the cart
|
||||
$this->cart->delete(product: $product, amount: $cart - $amount, errors: $this->errors['cart']);
|
||||
}
|
||||
|
||||
// Reinitializing the buffer with amount of the product in the cart
|
||||
$cart = $amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sending response
|
||||
$this->response
|
||||
->start()
|
||||
->clean()
|
||||
->sse()
|
||||
->json([
|
||||
'amount' => $cart, // $cart does not store a real value, but is calculated without a repeated request to ArangoDB
|
||||
'errors' => $this->errors
|
||||
])
|
||||
->validate($this->request)
|
||||
?->body()
|
||||
->end();
|
||||
|
||||
// Deinitializing buffer with amount of the product in the cart
|
||||
unset($cart);
|
||||
}
|
||||
|
||||
// Exit (success/fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary
|
||||
*
|
||||
* Information about products in the cart
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function summary(): null
|
||||
{
|
||||
if (str_contains($this->request->headers['accept'], content::json->value)) {
|
||||
// Request for JSON response
|
||||
|
||||
// Initializing the cart
|
||||
$this->cart ??= $this->account?->cart() ?? $this->session?->cart();
|
||||
|
||||
if ($this->cart instanceof model) {
|
||||
// Initialized the cart
|
||||
|
||||
// Initializing summary data of the cart
|
||||
$summary = $this->cart?->summary(currency: $this->currency, errors: $this->errors['cart']);
|
||||
|
||||
// Sending response
|
||||
$this->response
|
||||
->start()
|
||||
->clean()
|
||||
->sse()
|
||||
->json([
|
||||
'cost' => $summary['cost'] ?? 0,
|
||||
'amount' => $summary['amount'] ?? 0,
|
||||
'errors' => $this->errors
|
||||
])
|
||||
->validate($this->request)
|
||||
?->body()
|
||||
->end();
|
||||
|
||||
// Deinitializing summary data of the cart
|
||||
unset($summary);
|
||||
}
|
||||
}
|
||||
|
||||
// Exit (success/fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Share
|
||||
*
|
||||
* Share the cart
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function share(): null
|
||||
{
|
||||
if (str_contains($this->request->headers['accept'], content::json->value)) {
|
||||
// Request for JSON response
|
||||
|
||||
// Initializing the cart
|
||||
$this->cart ??= $this->account?->cart() ?? $this->session?->cart();
|
||||
|
||||
if ($this->cart instanceof model) {
|
||||
// Initialized the cart
|
||||
|
||||
if ($share = $this->cart->share ?? $this->cart->share()) {
|
||||
// The cart is available for sharing
|
||||
|
||||
// Sending response
|
||||
$this->response
|
||||
->start()
|
||||
->clean()
|
||||
->sse()
|
||||
->json([
|
||||
'share' => $share,
|
||||
'errors' => $this->errors
|
||||
])
|
||||
->validate($this->request)
|
||||
?->body()
|
||||
->end();
|
||||
}
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($hash);
|
||||
}
|
||||
}
|
||||
|
||||
// Exit (success/fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pay
|
||||
*
|
||||
* Pay for the cart
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function pay(): null
|
||||
{
|
||||
if (str_contains($this->request->headers['accept'], content::json->value)) {
|
||||
// Request for JSON response
|
||||
|
||||
// Initializing the cart
|
||||
$this->cart ??= $this->account?->cart() ?? $this->session?->cart();
|
||||
|
||||
if ($this->cart instanceof model) {
|
||||
// Initialized the cart
|
||||
|
||||
if ($share = $this->cart->share ?? $this->cart->share()) {
|
||||
// The cart is available for sharing
|
||||
|
||||
// Sending response
|
||||
$this->response
|
||||
->start()
|
||||
->clean()
|
||||
->sse()
|
||||
->json([
|
||||
'share' => $share,
|
||||
'errors' => $this->errors
|
||||
])
|
||||
->validate($this->request)
|
||||
?->body()
|
||||
->end();
|
||||
}
|
||||
|
||||
// Deinitializing unnecessary variables
|
||||
unset($hash);
|
||||
}
|
||||
}
|
||||
|
||||
// Exit (success/fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Robokassa
|
||||
*
|
||||
* HTML-document with robokassa iframe
|
||||
*
|
||||
* @param null
|
||||
*
|
||||
* @todo THIS MUST BE A PAYMENT OF ORDER IN THE FUTURE, NOT CART
|
||||
*/
|
||||
public function robokassa(): null
|
||||
{
|
||||
// Initializing the cart
|
||||
$this->cart ??= $this->account?->cart() ?? $this->session?->cart();
|
||||
|
||||
// Initializing the cart data
|
||||
$this->view->cart = $this->cart;
|
||||
$this->view->summary = $this->cart?->summary(currency: $this->currency);
|
||||
|
||||
if (str_contains($this->request->headers['accept'], content::any->value)) {
|
||||
// Request for any response
|
||||
|
||||
// Render page
|
||||
$page = $this->view->render('iframes/robokassa.html');
|
||||
|
||||
// Sending response
|
||||
$this->response
|
||||
->start()
|
||||
->clean()
|
||||
->sse()
|
||||
->write($page)
|
||||
->validate($this->request)
|
||||
?->body()
|
||||
->end();
|
||||
|
||||
// Deinitializing rendered page
|
||||
unset($page);
|
||||
}
|
||||
|
||||
// Exit (success/fail)
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -49,6 +49,9 @@ export default class delivery {
|
|||
order.setAttribute("disabled", true);
|
||||
}
|
||||
|
||||
// Initializing the delivery data request <section> element
|
||||
const request = document.getElementById("delivery_request");
|
||||
|
||||
/**
|
||||
* @name Resolved
|
||||
*
|
||||
|
@ -86,9 +89,25 @@ export default class delivery {
|
|||
order.removeAttribute("disabled");
|
||||
}
|
||||
|
||||
if (request instanceof HTMLElement) {
|
||||
// Initializeg the delivery data request <section> element
|
||||
|
||||
// Hiding the delivery data request <section> element
|
||||
request.classList.add("deleted");
|
||||
}
|
||||
} 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("deleted");
|
||||
}
|
||||
}
|
||||
|
||||
// Calculating delivery
|
||||
this.calculate();
|
||||
}
|
||||
|
||||
if (json.company) {
|
||||
// Received company property
|
||||
|
@ -181,6 +200,9 @@ export default class delivery {
|
|||
order.setAttribute("disabled", true);
|
||||
}
|
||||
|
||||
// Initializing the delivery data request <section> element
|
||||
const request = document.getElementById("delivery_request");
|
||||
|
||||
/**
|
||||
* @name Resolved
|
||||
*
|
||||
|
@ -215,9 +237,25 @@ export default class delivery {
|
|||
order.removeAttribute("disabled");
|
||||
}
|
||||
|
||||
if (request instanceof HTMLElement) {
|
||||
// Initializeg the delivery data request <section> element
|
||||
|
||||
// Hiding the delivery data request <section> element
|
||||
request.classList.add("deleted");
|
||||
}
|
||||
} 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("deleted");
|
||||
}
|
||||
}
|
||||
|
||||
// Calculating delivery
|
||||
this.calculate();
|
||||
}
|
||||
|
||||
if (json.location) {
|
||||
// Received location
|
||||
|
@ -389,6 +427,9 @@ export default class delivery {
|
|||
order.setAttribute("disabled", true);
|
||||
}
|
||||
|
||||
// Initializing the delivery data request <section> element
|
||||
const request = document.getElementById("delivery_request");
|
||||
|
||||
/**
|
||||
* @name Resolved
|
||||
*
|
||||
|
@ -423,15 +464,31 @@ export default class delivery {
|
|||
order.removeAttribute("disabled");
|
||||
}
|
||||
|
||||
if (request instanceof HTMLElement) {
|
||||
// Initializeg the delivery data request <section> element
|
||||
|
||||
// Hiding the delivery data request <section> element
|
||||
request.classList.add("deleted");
|
||||
}
|
||||
|
||||
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("deleted");
|
||||
}
|
||||
}
|
||||
|
||||
// Calculating delivery
|
||||
this.calculate();
|
||||
}
|
||||
|
||||
if (json.street) {
|
||||
// Received street property
|
||||
|
@ -555,7 +612,7 @@ core.modules.connect("damper").then(() => {
|
|||
*/
|
||||
damper: core.damper(
|
||||
(...variables) => delivery.write.system(...variables),
|
||||
1200,
|
||||
400,
|
||||
3,
|
||||
),
|
||||
},
|
||||
|
@ -576,7 +633,7 @@ core.modules.connect("damper").then(() => {
|
|||
*/
|
||||
damper: core.damper(
|
||||
(...variables) => delivery.calculate.system(...variables),
|
||||
300,
|
||||
200,
|
||||
),
|
||||
},
|
||||
);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
@charset "UTF-8";
|
||||
|
||||
@keyframes slide-down-revert {
|
||||
0% {
|
||||
transform: translate(0, 0%);
|
||||
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translate(0, -100%);
|
||||
clip-path: polygon(0% 100%, 100% 100%, 100% 200%, 0% 200%);
|
||||
}
|
||||
}
|
||||
|
||||
.slide.down.revert.animated {
|
||||
animation-duration: var(--animation-duration, 0.2s);
|
||||
animation-name: slide-down-revert;
|
||||
animation-fill-mode: forwards;
|
||||
animation-timing-function: cubic-bezier(1, 0, 1, 1);
|
||||
}
|
|
@ -1,15 +1,18 @@
|
|||
@charset "UTF-8";
|
||||
|
||||
main>section:is(#summary, #products, #delivery) {
|
||||
main>section:is(#summary, #products, #delivery, #delivery_request) {
|
||||
width: var(--width);
|
||||
gap: var(--gap);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
main>section:is(#summary, #delivery) {
|
||||
background-color: var(--tg-theme-section-bg-color);
|
||||
}
|
||||
|
||||
main>section#delivery>div.column {
|
||||
padding: 1rem;
|
||||
gap: var(--gap);
|
||||
background-color: var(--tg-theme-section-bg-color);
|
||||
}
|
||||
|
||||
main>section#delivery>div.column>div#deliveries>input {
|
||||
|
@ -70,16 +73,41 @@ main:has(section#summary.disabled:hover)>section#delivery>div {
|
|||
filter: brightness(1.2);
|
||||
}
|
||||
|
||||
section#delivery>div.column>div#deliveries>input:not(:checked)+section#delivery_request {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
main>section#delivery_request>p:only-of-type {
|
||||
margin: unset;
|
||||
width: 100%;
|
||||
height: 1rem;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0 1rem;
|
||||
}
|
||||
|
||||
main>section#delivery_request>p:only-of-type>i.icon {
|
||||
/* color: var(--tg-theme-accent-text-color); */
|
||||
color: var(--tg-theme-text-color);
|
||||
}
|
||||
|
||||
main>section#delivery_request>p:only-of-type>span:only-of-type {
|
||||
margin: 0 auto;
|
||||
/* color: var(--tg-theme-accent-text-color); */
|
||||
color: var(--tg-theme-text-color);
|
||||
color: var(--tg-theme-hint-color);
|
||||
}
|
||||
|
||||
main>section#summary>div {
|
||||
container-type: inline-size;
|
||||
container-name: summary;
|
||||
height: 2rem;
|
||||
padding-left: 1rem;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
overflow: hidden;
|
||||
pointer-events: auto;
|
||||
border-radius: 1.375rem;
|
||||
background-color: var(--tg-theme-section-bg-color);
|
||||
}
|
||||
|
||||
main>section#summary>div>span {
|
||||
|
@ -104,14 +132,15 @@ main>section#summary>div>button#order * {
|
|||
main>section#summary.disabled,
|
||||
main>section#summary>div:has(button#order:disabled),
|
||||
main:not(:has(section#delivery>div.column>div#deliveries>input:checked))>section#summary>div:has(button#order:enabled) {
|
||||
cursor: not-allowed;
|
||||
/* cursor: not-allowed; */
|
||||
}
|
||||
|
||||
main>section#summary.disabled,
|
||||
main>section#summary>div>button#order:disabled,
|
||||
main:not(:has(section#delivery>div.column>div#deliveries>input:checked))>section#summary>div>button#order:enabled {
|
||||
pointer-events: none;
|
||||
filter: grayscale(1);
|
||||
/* pointer-events: none;
|
||||
filter: grayscale(1); */
|
||||
display: none;
|
||||
}
|
||||
|
||||
main>section#products>article.product {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
@charset "UTF-8";
|
||||
|
||||
i.icon.pin {
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
margin-top: -4px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
display: block;
|
||||
border: 2px solid;
|
||||
border-radius: 100% 100% 0 100%;
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
i.icon.pin.small {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
}
|
||||
|
||||
i.icon.pin::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 3px;
|
||||
top: 3px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
border: 2px solid;
|
||||
border-radius: 40px;
|
||||
}
|
||||
|
||||
i.icon.pin.small::before {
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
}
|
|
@ -66,10 +66,14 @@ main {
|
|||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 26px;
|
||||
gap: calc(var(--gap) + 10px);
|
||||
transition: 0s;
|
||||
}
|
||||
|
||||
main > *.merged {
|
||||
margin-top: -14px;
|
||||
}
|
||||
|
||||
main>*[data-section] {
|
||||
width: var(--width);
|
||||
}
|
||||
|
@ -261,6 +265,10 @@ input {
|
|||
border-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.rounded.smoother {
|
||||
border-radius: 1.375rem;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
@ -284,6 +292,10 @@ input {
|
|||
color: var(--tg-theme-hint-color);
|
||||
}
|
||||
|
||||
.deleted {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.unselectable {
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
|
|
|
@ -14,7 +14,12 @@
|
|||
</div>
|
||||
<div id="address" class="row">
|
||||
<input id="location" class="identifier{% if session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].location.identifier %} success{% endif %}" placeholder="{{ language.name == 'ru' ? 'Город' : 'location' }}"
|
||||
value="{{ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company] ? 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.location ?? account.buffer.delivery.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.structure|reverse|join(', ')
|
||||
: (session.buffer.delivery.location ?? account.buffer.delivery.location) }}"
|
||||
onkeyup="core.delivery.location(this)" oninput="core.delivery.location(this)" tabindex="6" />
|
||||
<input id="street"{% if session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].street %} class="success"{% endif %} placeholder="{{ language.name == 'ru' ? 'Улица' : 'Street' }}"
|
||||
value="{{ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company] ? session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].street : (session.buffer.delivery.street ?? session.buffer.delivery.street) }}"
|
||||
|
@ -22,4 +27,11 @@
|
|||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="delivery_request" class="rounded row unselectable merged {% if session.buffer.delivery[account.buffer.delivery.company ??
|
||||
session.buffer.delivery.company].ready %}deleted{% endif %}">
|
||||
<p>
|
||||
<!-- <i class="icon pin small"></i> -->
|
||||
<span>{{ language.name == 'ru' ? 'Укажите данные для доставки' : 'Enter delivery information' }}</span>
|
||||
</p>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% if cart.products is not empty %}
|
||||
<section id="summary"
|
||||
class="column unselectable">
|
||||
class="rounded column unselectable">
|
||||
<div class="row">
|
||||
<span id="amount">{{ cart.summary.amount ?? 0 }}</span>
|
||||
<span>{{ language.name == "ru" ? "товаров на сумму" : "products worth" }}</span>
|
||||
|
@ -12,8 +12,7 @@
|
|||
<span id="shipping" class="delivery days hint">{{ session.buffer.delivery[account.buffer.delivery.company ?? session.buffer.delivery.company].days }}</span>
|
||||
{% endif %}
|
||||
<button id="order" onclick="core.cart.share(this)" {% if session.buffer.delivery[account.buffer.delivery.company ??
|
||||
session.buffer.delivery.company].location is empty or session.buffer.delivery[account.buffer.delivery.company ??
|
||||
session.buffer.delivery.company].street is empty %} disabled="true" {% endif %}
|
||||
session.buffer.delivery.company].ready == false %} disabled="true" {% endif %}
|
||||
title="{{ language.name == 'ru' ? 'Оформить заказ' : 'Place an order' }}"><i class="icon arrow"></i></button>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<link type="text/css" rel="stylesheet" href="/themes/{{ theme }}/css/icons/plus.css" />
|
||||
<link type="text/css" rel="stylesheet" href="/themes/{{ theme }}/css/icons/minus.css" />
|
||||
<link type="text/css" rel="stylesheet" href="/themes/{{ theme }}/css/icons/arrow.css" />
|
||||
<link type="text/css" rel="stylesheet" href="/themes/{{ theme }}/css/icons/pin.css" />
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
|
|
@ -24,4 +24,5 @@
|
|||
--days-short: "{{ language.name == 'ru' ? 'дн' : 'd' }}";
|
||||
}
|
||||
</style>
|
||||
<link type="text/css" rel="stylesheet" href="/themes/{{ theme }}/css/animations.css" />
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue