Add department pricing normalization for order bookings
This commit is contained in:
@@ -37,6 +37,20 @@ function order_booking_create_department(string $name): array
|
||||
]);
|
||||
}
|
||||
|
||||
function order_booking_create_department_price(int $departmentId, int $productId, int $price): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
$statement = $db->prepare(
|
||||
'INSERT INTO `product_department_prices` (`department_id`, `product_id`, `price`)
|
||||
VALUES (?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE `price` = VALUES(`price`)'
|
||||
);
|
||||
$statement->bind_param('iii', $departmentId, $productId, $price);
|
||||
$statement->execute();
|
||||
$statement->close();
|
||||
}
|
||||
|
||||
it('lets customers create their own order bookings without booking permissions', function (): void {
|
||||
api_test_covers('POST /order-bookings', 'auth');
|
||||
|
||||
@@ -65,6 +79,50 @@ it('lets customers create their own order bookings without booking permissions',
|
||||
api_fixtures()->cleanupDeleteById('order_bookings', $bookingId);
|
||||
});
|
||||
|
||||
it('normalizes booking item prices from server-side customer and department pricing', function (): void {
|
||||
api_test_covers('POST /order-bookings', 'pricing');
|
||||
|
||||
$session = api_fixtures()->createUserSession(['user']);
|
||||
$department = order_booking_create_department('Own Booking Pricing Department');
|
||||
$product = api_fixtures()->createProduct([
|
||||
'name' => 'Booking Price Normalized Product',
|
||||
'price' => 0,
|
||||
'is_wash' => 0,
|
||||
'display_in_booking_form' => 1,
|
||||
]);
|
||||
order_booking_create_department_price((int)$department['id'], (int)$product['id'], 425);
|
||||
|
||||
$payload = order_booking_create_payload($session['user'], $department, $product, 'PRICEFIX1');
|
||||
$payload['items'][0]['price'] = 0;
|
||||
|
||||
$response = api_client()->post('/order-bookings', $payload, $session['headers']);
|
||||
|
||||
$response
|
||||
->assertStatus(200)
|
||||
->assertEnvelope()
|
||||
->assertSuccess();
|
||||
|
||||
$bookingId = (int)($response->data()['id'] ?? 0);
|
||||
expect($bookingId)->toBeGreaterThan(0);
|
||||
|
||||
$responseItems = $response->data()['items'] ?? [];
|
||||
expect($responseItems)
|
||||
->toBeArray()
|
||||
->and((int)($responseItems[0]['price'] ?? 0))->toBe(425);
|
||||
|
||||
$row = api_fixtures()->fetchRowById('order_bookings', $bookingId);
|
||||
$storedItems = json_decode((string)($row['items'] ?? '[]'), true);
|
||||
expect($storedItems)
|
||||
->toBeArray()
|
||||
->and((int)($storedItems[0]['price'] ?? 0))->toBe(425);
|
||||
|
||||
api_fixtures()->cleanupDeleteWhere('product_department_prices', [
|
||||
'department_id' => (int)$department['id'],
|
||||
'product_id' => (int)$product['id'],
|
||||
]);
|
||||
api_fixtures()->cleanupDeleteById('order_bookings', $bookingId);
|
||||
});
|
||||
|
||||
it('blocks subusers creating own customer order bookings without the bookings add node', function (): void {
|
||||
api_test_covers('POST /order-bookings', 'auth');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user