fix price 2
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('products')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('products', 'direct_price')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('products', 'inventory')) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user