Add new properties and routes for product and booking enhancements
- Added `virtual_cart` property in `bookings_o` and enhanced its structure method. - Introduced `display_in_booking_form` and `order_priority` properties in `products_o` with updates to object structure, parsing, and routes. - Enabled handling of product attributes `display_in_booking_form` and `order_priority` in `productsRoute`. - Added `booked_invoice_id` reset logic in `collected_order_invoices_o`. - Introduced `machineButtonPressRoute` to log button press incidents and send Slack notifications.
This commit is contained in:
@@ -35,6 +35,7 @@ class bookings_o extends db
|
||||
public object_property $wash_certificate_pdf;
|
||||
public object_property $status;
|
||||
public object_property $data;
|
||||
public object_property $virtual_cart;
|
||||
|
||||
public function structure(): void
|
||||
{
|
||||
@@ -106,6 +107,7 @@ class bookings_o extends db
|
||||
$this->wash_certificate_pdf = new object_property($this->table, $this->id, 'wash_certificate_pdf', 'string', true);
|
||||
$this->status = new object_property($this->table, $this->id, 'status', 'string', true);
|
||||
$this->data = new object_property($this->table, $this->id, 'data', 'string', true);
|
||||
$this->virtual_cart = new object_property($this->table, $this->id, 'virtual_cart', 'int', false);
|
||||
}
|
||||
|
||||
public function parseBookings(array $listObjectsWithPaginationIfSet): array
|
||||
|
||||
@@ -1277,6 +1277,7 @@ class collected_order_invoices_o extends db
|
||||
// Clear the external_id and processor fields
|
||||
$this->external_id->set(null);
|
||||
$this->processor->set(null);
|
||||
$this->booked_invoice_id->set(null);
|
||||
// Object changed
|
||||
self::objectChanged();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,16 @@ class products_o extends db
|
||||
* @var object_property $is_wash
|
||||
*/
|
||||
public object_property $is_wash;
|
||||
/**
|
||||
* Should the item be displayed in the booking form?
|
||||
* @var object_property $display_in_booking_form
|
||||
*/
|
||||
public object_property $display_in_booking_form;
|
||||
/**
|
||||
* Order priority integer (lower = higher priority)
|
||||
* @var object_property $order_priority
|
||||
*/
|
||||
public object_property $order_priority;
|
||||
/**
|
||||
* The timestamp of when the object was created
|
||||
* @var object_property
|
||||
@@ -106,6 +116,8 @@ class products_o extends db
|
||||
$this->apply_category_discount = new object_property($this->table, $this->id, 'apply_category_discount', 'bool', false);
|
||||
$this->requires_note = new object_property($this->table, $this->id, 'requires_note', 'bool', false);
|
||||
$this->is_wash = new object_property($this->table, $this->id, 'is_wash', 'bool', false);
|
||||
$this->display_in_booking_form = new object_property($this->table, $this->id, 'display_in_booking_form', 'bool', false);
|
||||
$this->order_priority = new object_property($this->table, $this->id, 'order_priority', 'int', false);
|
||||
$this->created_at = new object_property($this->table, $this->id, 'created_at', 'string', false);
|
||||
$this->updated_at = new object_property($this->table, $this->id, 'updated_at', 'string', false);
|
||||
}
|
||||
@@ -196,6 +208,8 @@ class products_o extends db
|
||||
'apply_category_discount' => (bool)$this->apply_category_discount->value(),
|
||||
'requires_note' => (bool)$this->requires_note->value(),
|
||||
'is_wash' => (bool)$this->is_wash->value(),
|
||||
'display_in_booking_form' => (bool)$this->display_in_booking_form->value(),
|
||||
'order_priority' => (int)$this->order_priority->value(),
|
||||
'created_at' => (string)$this->created_at->value(),
|
||||
'updated_at' => (string)$this->updated_at->value(),
|
||||
];
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace routes;
|
||||
|
||||
use classes\authentication;
|
||||
use classes\slack;
|
||||
use objects\customer_vehicles_o;
|
||||
use objects\logs_o;
|
||||
use objects\orders_o;
|
||||
use objects\plate_scans_o;
|
||||
use objects\users_o;
|
||||
use traits\route_t;
|
||||
|
||||
class machineButtonPressRoute
|
||||
{
|
||||
use route_t;
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
|
||||
self::get('/relay/button/press/post', function () {
|
||||
/**
|
||||
* This is here because the post method is not supported by the software some of the cameras are running on.
|
||||
*/
|
||||
global $response;
|
||||
self::requirePlateScannerAuth();
|
||||
$plate_scanner = (new authentication())->get_plate_scanner();
|
||||
self::requireParameters(['token']);
|
||||
// Validate the token
|
||||
self::requireType('token', 'string');
|
||||
self::requireMinLength('token', 1);
|
||||
self::requireMaxLength('token', 100);
|
||||
// TODO: Implement action
|
||||
$slack = new slack();
|
||||
$slack->send_department_booking_notification((int)$plate_scanner->department_id->value(), 'Button was pressed on the machine with the plate scanner: ' . $plate_scanner->id);
|
||||
// Log the incident
|
||||
(new logs_o())->add('relay', $plate_scanner->department_id->value(), 1, 0, 'TRIGGER_BUTTON_PRESS', 'Button was pressed on the machine with the plate scanner: ' . $plate_scanner->id);
|
||||
// Return a success message
|
||||
$response->success(['message' => 'Button press recorded.', 'scanner' => $plate_scanner->name->value()], 201);
|
||||
}, [
|
||||
'add_button_press' => 'Add a button press'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,8 @@ class productsRoute
|
||||
'updated_at' => (string)$product['updated_at'],
|
||||
'addons' => (new product_options_o())->getProductOptions($product['id']),
|
||||
'is_wash' => (bool)$product['is_wash'],
|
||||
'display_in_booking_form' => (bool)$product['display_in_booking_form'],
|
||||
'order_priority' => (int)$product['order_priority'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -342,6 +344,12 @@ class productsRoute
|
||||
if (self::isParametersSet(['is_wash'])) {
|
||||
$product->is_wash->set($response->getRequestParameter('is_wash') ? 1 : 0);
|
||||
}
|
||||
if (self::isParametersSet(['display_in_booking_form'])) {
|
||||
$product->display_in_booking_form->set($response->getRequestParameter('display_in_booking_form') ? 1 : 0);
|
||||
}
|
||||
if (self::isParametersSet(['order_priority'])) {
|
||||
$product->order_priority->set((int)$response->getRequestParameter('order_priority') ?? '');
|
||||
}
|
||||
(new logs_o())->add('products', 'global', 1, $user->id, 'EDIT_PRODUCT', 'Product id: ' . $id);
|
||||
// Return a success message
|
||||
$response->success(['message' => 'Product edited successfully']);
|
||||
|
||||
Reference in New Issue
Block a user