Add customer product fixed price overrides
This commit is contained in:
@@ -49,6 +49,67 @@ it('requires notes when adding the extraordinary chemistry product to an order',
|
||||
expect($response->data()['notes'] ?? null)->toBe('Graffiti removal on left side');
|
||||
});
|
||||
|
||||
it('uses a product fixed price instead of the best discount when adding an order item', function (): void {
|
||||
api_test_covers('POST /order/items', 'pricing');
|
||||
api_test_covers('GET /products', 'pricing');
|
||||
|
||||
$customer = api_fixtures()->createUser(['display_name' => 'Fixed Price Customer']);
|
||||
$department = api_fixtures()->createDepartment();
|
||||
$cashier = api_fixtures()->createUser(['display_name' => 'Fixed Price Cashier']);
|
||||
$category = api_fixtures()->createCategory(['name' => 'Fixed Price Category']);
|
||||
$product = api_fixtures()->createProduct([
|
||||
'name' => 'Fixed Price Product',
|
||||
'price' => 1000,
|
||||
'category' => $category['id'],
|
||||
'apply_category_discount' => 1,
|
||||
]);
|
||||
|
||||
api_fixtures()->createPriceOverride([
|
||||
'user_id' => $customer['id'],
|
||||
'is_category' => 1,
|
||||
'product_or_category_id' => (string)$category['id'],
|
||||
'percentage' => 80,
|
||||
]);
|
||||
api_fixtures()->createPriceOverride([
|
||||
'user_id' => $customer['id'],
|
||||
'is_category' => 0,
|
||||
'product_or_category_id' => (string)$product['id'],
|
||||
'percentage' => 10,
|
||||
'fixed_price' => 350,
|
||||
]);
|
||||
|
||||
$order = api_fixtures()->createOrder([
|
||||
'customer_id' => $customer['customer_number'],
|
||||
'department_id' => $department['id'],
|
||||
'cashier_id' => $cashier['id'],
|
||||
'reference' => 'FIXED-PRICE',
|
||||
]);
|
||||
$session = api_fixtures()->createUserSession(['add_order_items', 'list_products']);
|
||||
|
||||
$productResponse = api_client()->get(
|
||||
'/products?final_price=true&id=' . $product['id'] . '&customer_id=' . $customer['customer_number'],
|
||||
$session['headers']
|
||||
);
|
||||
$productResponse
|
||||
->assertStatus(200)
|
||||
->assertEnvelope()
|
||||
->assertSuccess();
|
||||
expect($productResponse->data()['price'] ?? null)->toBe(350);
|
||||
|
||||
$response = api_client()->post('/order/items', [
|
||||
'order_id' => $order['id'],
|
||||
'product_id' => $product['id'],
|
||||
'quantity' => 1,
|
||||
], $session['headers']);
|
||||
|
||||
$response
|
||||
->assertStatus(200)
|
||||
->assertEnvelope()
|
||||
->assertSuccess();
|
||||
|
||||
expect($response->data()['price'] ?? null)->toBe(350);
|
||||
});
|
||||
|
||||
it('does not allow clearing notes for order items whose product requires notes', function (): void {
|
||||
api_test_covers('PUT /order/items', 'validation');
|
||||
|
||||
@@ -63,7 +124,7 @@ it('does not allow clearing notes for order items whose product requires notes',
|
||||
]);
|
||||
$product = api_fixtures()->createProduct([
|
||||
'id' => 902702,
|
||||
'name' => 'API Note Required Product',
|
||||
'name' => \objects\products_o::EXTRAORDINARY_CHEMISTRY_PRODUCT_NAME,
|
||||
'price' => 199,
|
||||
'requires_note' => 1,
|
||||
]);
|
||||
@@ -75,7 +136,7 @@ it('does not allow clearing notes for order items whose product requires notes',
|
||||
'quantity' => 1,
|
||||
'notes' => 'Initial note',
|
||||
]);
|
||||
$session = api_fixtures()->createUserSession(['edit_order_items']);
|
||||
$session = api_fixtures()->createUserSession(['edit_order_items', 'list_order_items']);
|
||||
|
||||
api_client()
|
||||
->put('/order/items', [
|
||||
|
||||
Reference in New Issue
Block a user