Update source into github
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\OrderItem;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CheckOrderItemAddons extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'check:order-addons {order_item_id : Order Item ID to check}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Check addons for a specific order item';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$orderItemId = $this->argument('order_item_id');
|
||||
|
||||
$this->info("🔍 Checking addons for Order Item ID: {$orderItemId}");
|
||||
|
||||
try {
|
||||
$orderItem = OrderItem::with(['addons.addonItems'])->find($orderItemId);
|
||||
|
||||
if (!$orderItem) {
|
||||
$this->error("❌ Order Item not found with ID: {$orderItemId}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->info("📋 Order Item Details:");
|
||||
$this->info(" - ID: {$orderItem->id}");
|
||||
$this->info(" - Product ID: {$orderItem->product_id}");
|
||||
$this->info(" - Product Type: {$orderItem->product_type}");
|
||||
$this->info(" - Server Name: {$orderItem->server_name}");
|
||||
|
||||
$this->info("\n🔍 Addons Information:");
|
||||
|
||||
if ($orderItem->addons && $orderItem->addons->count() > 0) {
|
||||
$this->info(" - Total Addons: {$orderItem->addons->count()}");
|
||||
|
||||
foreach ($orderItem->addons as $index => $addon) {
|
||||
$this->info("\n 📦 Addon #" . ($index + 1) . ":");
|
||||
$this->info(" - Order Addon ID: {$addon->id}");
|
||||
$this->info(" - Addon ID: {$addon->addon_id}");
|
||||
$this->info(" - Quantity (qty): {$addon->qty}");
|
||||
$this->info(" - Price: {$addon->price}");
|
||||
|
||||
if ($addon->addonItems) {
|
||||
$this->info(" - Addon Name: {$addon->addonItems->name}");
|
||||
$this->info(" - Addon Price: {$addon->addonItems->price}");
|
||||
$this->info(" - Addon Step: {$addon->addonItems->step}");
|
||||
$this->info(" - Addon Prefix: {$addon->addonItems->prefix}");
|
||||
} else {
|
||||
$this->warn(" ⚠️ AddonItems relationship not found!");
|
||||
}
|
||||
}
|
||||
|
||||
// Process addons like in the job
|
||||
$addonData = [
|
||||
'cpu' => 0,
|
||||
'ram' => 0,
|
||||
'disk' => 0
|
||||
];
|
||||
|
||||
foreach ($orderItem->addons as $orderAddon) {
|
||||
$addon = $orderAddon->addonItems;
|
||||
if (!$addon) continue;
|
||||
|
||||
$addonName = strtolower(trim($addon->name));
|
||||
$quantity = (int) $orderAddon->qty;
|
||||
|
||||
switch ($addonName) {
|
||||
case 'cpu':
|
||||
$addonData['cpu'] += $quantity;
|
||||
break;
|
||||
case 'ram':
|
||||
$addonData['ram'] += $quantity;
|
||||
break;
|
||||
case 'disk':
|
||||
case 'ssd':
|
||||
$addonData['disk'] += $quantity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("\n📊 Processed Addon Data:");
|
||||
$this->info(" - CPU: {$addonData['cpu']}");
|
||||
$this->info(" - RAM: {$addonData['ram']}GB");
|
||||
$this->info(" - Disk: {$addonData['disk']}GB");
|
||||
$this->info(" - Has Addons: " . (array_sum($addonData) > 0 ? 'Yes' : 'No'));
|
||||
|
||||
} else {
|
||||
$this->warn("⚠️ No addons found for this order item");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error("❌ Exception: " . $e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user