diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index 228f165..b7bf691 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -398,6 +398,10 @@ class ProductController extends SuperController $data['use_last_price_if_zero'] = !empty($data['use_last_price_if_zero']); } + if (!Product::hasDirectPriceColumn()) { + unset($data['direct_price']); + } + return $data; } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 845702c..7107ec8 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -20,6 +20,7 @@ class Product extends Model private static ?bool $orderLimitColumnsExist = null; private static ?bool $showInAssetsColumnExists = null; private static ?bool $useLastPriceIfZeroColumnExists = null; + private static ?bool $directPriceColumnExists = null; protected static function booted(): void { @@ -40,6 +41,9 @@ class Product extends Model if (!static::hasUseLastPriceIfZeroColumn()) { unset($product->attributes['use_last_price_if_zero']); } + if (!static::hasDirectPriceColumn()) { + unset($product->attributes['direct_price']); + } }); } @@ -131,6 +135,24 @@ class Product extends Model return static::$useLastPriceIfZeroColumnExists; } + public static function hasDirectPriceColumn(): bool + { + if (static::$directPriceColumnExists !== null) { + return static::$directPriceColumnExists; + } + + try { + static::$directPriceColumnExists = Schema::hasColumn( + (new static)->getTable(), + 'direct_price' + ); + } catch (\Throwable) { + static::$directPriceColumnExists = false; + } + + return static::$directPriceColumnExists; + } + public function orderLimitsEnabled(): bool { if (!static::hasOrderLimitColumns() || !($this->order_limit_enabled ?? false)) { diff --git a/database/migrations/2026_06_14_000001_add_direct_price_to_products_table.php b/database/migrations/2026_06_14_000001_add_direct_price_to_products_table.php new file mode 100644 index 0000000..afa624e --- /dev/null +++ b/database/migrations/2026_06_14_000001_add_direct_price_to_products_table.php @@ -0,0 +1,40 @@ +unsignedTinyInteger('direct_price')->default(0)->after('inventory'); + } elseif (Schema::hasColumn('products', 'bubble')) { + $table->unsignedTinyInteger('direct_price')->default(0)->after('bubble'); + } else { + $table->unsignedTinyInteger('direct_price')->default(0); + } + }); + } + + public function down(): void + { + if (! Schema::hasTable('products') || ! Schema::hasColumn('products', 'direct_price')) { + return; + } + + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('direct_price'); + }); + } +};