Skip to content

Commit a9fa5a9

Browse files
authored
Merge pull request #6878 from bakaphp/new-cli-command-to-inject-UA-data-locations
make injects indepent but with proper checks
2 parents 490e1b7 + 9f1fad3 commit a9fa5a9

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

app/Console/Commands/Connectors/ESim/InjectInsuranceToOrderCommand.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ public function handle(): int
9191
foreach ($metadata['esims'] as $index => $esimData) {
9292
$this->info("Processing eSIM #{$index}...");
9393

94-
// Check if this eSIM already has insurance
95-
if (isset($esimData['eSimDetails']['insurance']) && ! empty($esimData['eSimDetails']['insurance'])) {
96-
$this->comment("eSIM #{$index} already has insurance. Skipping.");
97-
$skippedCount++;
98-
99-
continue;
100-
}
101-
10294
// Determine variant ID and duration
10395
if ($manualVariantId) {
10496
// Use manual variant ID
@@ -152,22 +144,29 @@ public function handle(): int
152144
$insuranceStructure = $result['structure'];
153145
$variant = $result['variant'];
154146

155-
// Inject insurance into the eSIM eSimDetails
156-
if (! isset($metadata['esims'][$index]['eSimDetails'])) {
157-
$metadata['esims'][$index]['eSimDetails'] = [];
158-
}
147+
// 1. Inject insurance into order metadata (independent check)
148+
$alreadyInOrderMetadata = isset($metadata['esims'][$index]['eSimDetails']['insurance']) && ! empty($metadata['esims'][$index]['eSimDetails']['insurance']);
149+
150+
if (! $alreadyInOrderMetadata) {
151+
if (! isset($metadata['esims'][$index]['eSimDetails'])) {
152+
$metadata['esims'][$index]['eSimDetails'] = [];
153+
}
159154

160-
$metadata['esims'][$index]['eSimDetails']['insurance'] = $insuranceStructure;
155+
$metadata['esims'][$index]['eSimDetails']['insurance'] = $insuranceStructure;
156+
$this->info(" ✓ Insurance injected into order metadata for eSIM #{$index}");
157+
} else {
158+
$this->comment(" Insurance already exists in order metadata for eSIM #{$index}. Skipping order metadata injection.");
159+
}
161160

162-
// Create order item for Flight Plus insurance
161+
// 2. Create order item for Flight Plus insurance (independent check)
163162
$this->createOrderItem($order, $variant, $duration);
164163

165-
// Inject insurance into the message (woocommerce_response)
164+
// 3. Inject insurance into the message (woocommerce_response) (independent check)
166165
$this->injectInsuranceToMessage($order, $insuranceStructure, $index);
167166

168167
$processedCount++;
169168

170-
$this->info("✓ Insurance structure injected successfully for eSIM #{$index}");
169+
$this->info("✓ Insurance processing completed for eSIM #{$index}");
171170
}
172171

173172
if ($processedCount === 0) {

0 commit comments

Comments
 (0)