fix: clean up duplicate categories, assign White Label Canna to Bulk
- Merge duplicate parent categories (Accessories, Concentrates, etc.) - Deactivate duplicate category records - Move products/children to the kept category - Assign White Label Canna products to Bulk category (147) - Mark White Label Canna products as is_raw_material=true
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Merge duplicate parent categories - keep the one with more products,
|
||||
* reassign products and children from the duplicate.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// Pairs: [keep, delete] - keep the one with more products
|
||||
$merges = [
|
||||
// Accessories: both have 0 products, keep lower ID
|
||||
[41, 86],
|
||||
// Concentrates: 16 has 15, 61 has 1
|
||||
[16, 61],
|
||||
// Tinctures: 37 has 7, 82 has 0
|
||||
[37, 82],
|
||||
// Vapes: 56 has 157, 11 has 0
|
||||
[56, 11],
|
||||
// Pre-Rolls: 52 has 3, 7 has 0
|
||||
[52, 7],
|
||||
// Edibles: 70 has 6, 25 has 3
|
||||
[70, 25],
|
||||
// Flower: both have 0, keep lower ID
|
||||
[1, 46],
|
||||
// Topicals: 32 has 34, 77 has 4
|
||||
[32, 77],
|
||||
];
|
||||
|
||||
foreach ($merges as [$keepId, $deleteId]) {
|
||||
// Move products from duplicate to keeper
|
||||
DB::table('products')
|
||||
->where('category_id', $deleteId)
|
||||
->update(['category_id' => $keepId]);
|
||||
|
||||
// Move child categories from duplicate to keeper
|
||||
DB::table('product_categories')
|
||||
->where('parent_id', $deleteId)
|
||||
->update(['parent_id' => $keepId]);
|
||||
|
||||
// Soft delete the duplicate (or hard delete if no soft deletes)
|
||||
DB::table('product_categories')
|
||||
->where('id', $deleteId)
|
||||
->update(['is_active' => false]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Re-activate the deactivated categories
|
||||
$reactivate = [86, 61, 82, 11, 7, 25, 46, 77];
|
||||
|
||||
DB::table('product_categories')
|
||||
->whereIn('id', $reactivate)
|
||||
->update(['is_active' => true]);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Assign White Label Canna products to Bulk category and mark as raw materials.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// White Label Canna brand ID = 18, Bulk category ID = 147
|
||||
$brandId = 18;
|
||||
$bulkCategoryId = 147;
|
||||
|
||||
// Update all products from this brand
|
||||
DB::table('products')
|
||||
->where('brand_id', $brandId)
|
||||
->update([
|
||||
'category_id' => $bulkCategoryId,
|
||||
'is_raw_material' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Revert - set back to no category and not raw material
|
||||
$brandId = 18;
|
||||
|
||||
DB::table('products')
|
||||
->where('brand_id', $brandId)
|
||||
->update([
|
||||
'category_id' => null,
|
||||
'is_raw_material' => false,
|
||||
]);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user