Set specific subscription addons to zero-priced where applicable.

Introduced logic to handle free subscription addons by setting their price to zero based on a predefined list. Updated affected areas to apply this change consistently when adding or modifying order items. This ensures correct pricing and aligns with business rules for these products.
This commit is contained in:
Jepp9350
2025-04-22 13:01:23 +02:00
parent 6edb1fdd8d
commit 9025ad79b7
@@ -907,13 +907,22 @@ class collected_order_invoices_o extends db
);
// Add the addons to the transaction
foreach ( $vehicle['addons'] as $addon ) {
$tmp_subscription_price = (int)self::getWashSubscriptionPrice((new products_o)->select((int)$addon['product_id'])->price->value()) / 2;
// If the product is in the free list, set the price to 0
$free_subscription_addons = [
23, // Spot Free- Varevogn
24, // Spot Free- Lastbil
];
if (in_array($addon['product_id'], $free_subscription_addons)) {
$tmp_subscription_price = 0;
}
$order_items_o->add(
(int)$transaction->id,
(int)$addon['product_id'],
(string)$vehicle['reg'],
(string)'',
(int)1857,
(int)self::getWashSubscriptionPrice((new products_o)->select((int)$addon['product_id'])->price->value()) / 2,
(int)$tmp_subscription_price,
(int)2,
(int)$order_items_o->id
);
@@ -953,6 +962,16 @@ class collected_order_invoices_o extends db
if (isset($order_item_addons_hidden[$order['reg_1']][$order_item['product_id']]) && count($order_item_addons_hidden[$order['reg_1']][$order_item['product_id']]) >= 2) {
continue;
}
// Check if the product is in the free list, set the price to 0
$free_subscription_addons = [
23, // Spot Free- Varevogn
24, // Spot Free- Lastbil
];
if (in_array($order_item['product_id'], $free_subscription_addons)) {
$tmp_subscription_price = (int)0;
} else {
$tmp_subscription_price = (int)self::getWashSubscriptionPrice((new products_o())->select((int)$order_item['product_id'])->price->value()) / 2;
}
// Add the order item to the hidden order items
$order_item_addons_hidden[$order['reg_1']][$order_item['product_id']][] = $order_item['id'];
// Set the order item to be hidden
@@ -960,7 +979,7 @@ class collected_order_invoices_o extends db
$order_item_object->select((int)$order_item['id']);
$order_item_object->requireSelected();
$order_item_object->include_in_invoice->set(0);
$order_item_object->price->set((int)self::getWashSubscriptionPrice((new products_o())->select((int)$order_item['product_id'])->price->value()) / 2);
$order_item_object->price->set($tmp_subscription_price);
}
}
}