feat(product): add show_in_list toggle and TV price formula
- New `show_in_list` column to control product visibility in customer list - New `tv_price_formula_enabled` + `tv_price_formula` columns for separate TV pricing - FormulaPriceService: isTvEnabled() and calculateTvForProduct() - listTvProducts applies TV formula overrides before returning - filterProductData handles both new field sets Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('products')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('products', 'show_in_list')) {
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('products', 'show_on_tv')) {
|
||||
$table->boolean('show_in_list')->default(true)->after('show_on_tv');
|
||||
} elseif (Schema::hasColumn('products', 'show_in_assets')) {
|
||||
$table->boolean('show_in_list')->default(true)->after('show_in_assets');
|
||||
} elseif (Schema::hasColumn('products', 'show')) {
|
||||
$table->boolean('show_in_list')->default(true)->after('show');
|
||||
} else {
|
||||
$table->boolean('show_in_list')->default(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
DB::statement(
|
||||
'ALTER TABLE `products` MODIFY COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (!Schema::hasTable('products') || !Schema::hasColumn('products', 'show_in_list')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->dropColumn('show_in_list');
|
||||
});
|
||||
}
|
||||
};
|
||||
+40
@@ -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
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('products', 'tv_price_formula_enabled')) {
|
||||
if (Schema::hasColumn('products', 'price_formula')) {
|
||||
$table->boolean('tv_price_formula_enabled')->default(false)->after('price_formula');
|
||||
} else {
|
||||
$table->boolean('tv_price_formula_enabled')->default(false);
|
||||
}
|
||||
}
|
||||
if (! Schema::hasColumn('products', 'tv_price_formula')) {
|
||||
$table->text('tv_price_formula')->nullable()->after('tv_price_formula_enabled');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$drop = [];
|
||||
if (Schema::hasColumn('products', 'tv_price_formula_enabled')) {
|
||||
$drop[] = 'tv_price_formula_enabled';
|
||||
}
|
||||
if (Schema::hasColumn('products', 'tv_price_formula')) {
|
||||
$drop[] = 'tv_price_formula';
|
||||
}
|
||||
if ($drop) {
|
||||
$table->dropColumn($drop);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
-- products.show_in_list — نمایش در لیست محصولات اپ مشتری
|
||||
SET @db = DATABASE();
|
||||
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products') > 0
|
||||
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_list') = 0,
|
||||
IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_on_tv') > 0,
|
||||
'ALTER TABLE `products` ADD COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'' AFTER `show_on_tv`',
|
||||
IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets') > 0,
|
||||
'ALTER TABLE `products` ADD COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'' AFTER `show_in_assets`',
|
||||
IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show') > 0,
|
||||
'ALTER TABLE `products` ADD COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'' AFTER `show`',
|
||||
'ALTER TABLE `products` ADD COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'''
|
||||
)
|
||||
)
|
||||
),
|
||||
'SELECT ''skip: show_in_list exists'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_list') > 0,
|
||||
'ALTER TABLE `products` MODIFY COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری''',
|
||||
'SELECT ''skip: show_in_list modify'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
@@ -68,6 +68,36 @@ PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- products.show_in_list (لیست محصولات اپ مشتری)
|
||||
-- ---------------------------------------------------------------------------
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products') > 0
|
||||
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_list') = 0,
|
||||
IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_on_tv') > 0,
|
||||
'ALTER TABLE `products` ADD COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'' AFTER `show_on_tv`',
|
||||
IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets') > 0,
|
||||
'ALTER TABLE `products` ADD COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'' AFTER `show_in_assets`',
|
||||
IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show') > 0,
|
||||
'ALTER TABLE `products` ADD COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'' AFTER `show`',
|
||||
'ALTER TABLE `products` ADD COLUMN `show_in_list` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در لیست محصولات مشتری'''
|
||||
)
|
||||
)
|
||||
),
|
||||
'SELECT ''skip products.show_in_list'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- products.use_last_price_if_zero (fallback وقتی provider صفر است)
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -555,6 +585,29 @@ PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- tv_price_formula_enabled / tv_price_formula ---
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'tv_price_formula_enabled') = 0,
|
||||
CONCAT('ALTER TABLE `products` ADD COLUMN `tv_price_formula_enabled` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''فرمول قیمت TV فعال'' AFTER ',
|
||||
IF((SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'price_formula') > 0,
|
||||
'`price_formula`', '`show_on_tv`')),
|
||||
'SELECT ''skip tv_price_formula_enabled'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'tv_price_formula') = 0,
|
||||
'ALTER TABLE `products` ADD COLUMN `tv_price_formula` TEXT NULL COMMENT ''فرمول قیمت مخصوص TV'' AFTER `tv_price_formula_enabled`',
|
||||
'SELECT ''skip tv_price_formula'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- پایان — برای بورسمس (اختیاری، جدا اجرا کنید):
|
||||
-- UPDATE `settings` SET `value` = 'کیلوگرم' WHERE `key` = 'unit';
|
||||
|
||||
Reference in New Issue
Block a user