Skip to content

Commit 6e20e07

Browse files
committed
feat: Enhance Bundle Configuration and Pricing Logic
- Updated BundleConfigurationRequest to allow configurations with only solar panel size. - Refactored BundleConfiguration model to dynamically calculate total price and weight based on selected options. - Added BundleBuilder component to the frontend for user-friendly bundle configuration. - Integrated new bundle configuration API endpoints and improved error handling in tests. - Created comprehensive tests for Bundle API and Shipping API to ensure functionality and validation.
1 parent 7e9d6af commit 6e20e07

File tree

7 files changed

+1163
-26
lines changed

7 files changed

+1163
-26
lines changed

backend/app/Http/Requests/BundleConfigurationRequest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ public function withValidator($validator): void
119119

120120
// Solar panel size is always required, but we already validate that
121121

122-
if (!$hasOptions) {
123-
$validator->errors()->add('configuration', 'Please select at least one optional component or ensure solar panel size is specified.');
124-
}
122+
// Allow configurations with just solar panel size (basic kit)
123+
// The solar panel size is already validated as required above
125124
});
126125
}
127126
}

backend/app/Models/BundleConfiguration.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,44 +97,47 @@ public function generateShareToken(): void
9797
*/
9898
public function calculateTotals(): void
9999
{
100-
$totalPrice = $this->bundle->price; // Base price
100+
$totalPrice = $this->bundle->price ?? 0; // Base price
101101
$totalWeight = $this->bundle->base_weight_g ?? 0; // Base weight
102102

103103
if ($this->configuration_data) {
104+
$availableOptions = $this->bundle->getAvailableOptions();
105+
104106
// Add espresso module price/weight if selected
105107
if (isset($this->configuration_data['espresso_module']) && $this->configuration_data['espresso_module']) {
106-
$totalPrice += 150.00; // Example price - should come from actual product
107-
$totalWeight += 800; // Example weight in grams
108+
$espressoModule = $availableOptions['espresso_module'] ?? null;
109+
if ($espressoModule) {
110+
$totalPrice += $espressoModule['price'];
111+
$totalWeight += $espressoModule['weight_g'];
112+
}
108113
}
109114

110115
// Add filter attachment price/weight if selected
111116
if (isset($this->configuration_data['filter_attachment']) && $this->configuration_data['filter_attachment']) {
112-
$totalPrice += 75.00;
113-
$totalWeight += 300;
117+
$filterAttachment = $availableOptions['filter_attachment'] ?? null;
118+
if ($filterAttachment) {
119+
$totalPrice += $filterAttachment['price'];
120+
$totalWeight += $filterAttachment['weight_g'];
121+
}
114122
}
115123

116124
// Add fan accessory price/weight if selected
117125
if (isset($this->configuration_data['fan_accessory']) && $this->configuration_data['fan_accessory']) {
118-
$totalPrice += 45.00;
119-
$totalWeight += 200;
126+
$fanAccessory = $availableOptions['fan_accessory'] ?? null;
127+
if ($fanAccessory) {
128+
$totalPrice += $fanAccessory['price'];
129+
$totalWeight += $fanAccessory['weight_g'];
130+
}
120131
}
121132

122133
// Add solar panel price/weight based on size
123134
$solarPanelSize = $this->configuration_data['solar_panel_size'] ?? '10W';
124-
switch ($solarPanelSize) {
125-
case '15W':
126-
$totalPrice += 50.00;
127-
$totalWeight += 400;
128-
break;
129-
case '20W':
130-
$totalPrice += 100.00;
131-
$totalWeight += 600;
132-
break;
133-
case '10W':
134-
default:
135-
$totalPrice += 25.00;
136-
$totalWeight += 250;
137-
break;
135+
$solarPanelSizes = $availableOptions['solar_panel_sizes'] ?? [];
136+
$selectedPanel = $solarPanelSizes[$solarPanelSize] ?? null;
137+
138+
if ($selectedPanel) {
139+
$totalPrice += $selectedPanel['price'];
140+
$totalWeight += $selectedPanel['weight_g'];
138141
}
139142
}
140143

0 commit comments

Comments
 (0)