|
|
@@ -163,6 +163,81 @@ class RepairMigratedVariantSkusCommandTest extends BagistoApiTestCase
|
|
|
$this->assertArrayNotHasKey('variant_sku', $migratedAdditional);
|
|
|
}
|
|
|
|
|
|
+ public function test_it_can_reuse_a_sku_held_by_a_variant_renamed_in_a_later_batch(): void
|
|
|
+ {
|
|
|
+ $now = now();
|
|
|
+ $product = new Product;
|
|
|
+ $product->sku = 'SWAP';
|
|
|
+ $product->type = 'flexible_variant';
|
|
|
+ $product->migrated_from_asteria_id = 991900201;
|
|
|
+ $product->save();
|
|
|
+
|
|
|
+ $option = ProductOption::query()->create([
|
|
|
+ 'label' => 'Length',
|
|
|
+ 'type' => 'select',
|
|
|
+ 'code' => 'swap_length',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ DB::table('product_product_options')->insert([
|
|
|
+ 'product_id' => $product->id,
|
|
|
+ 'product_option_id' => $option->id,
|
|
|
+ 'position' => 0,
|
|
|
+ 'is_required' => 1,
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $count = 201;
|
|
|
+ $valueIds = [];
|
|
|
+
|
|
|
+ for ($i = 0; $i < $count; $i++) {
|
|
|
+ $valueIds[] = DB::table('product_option_values')->insertGetId([
|
|
|
+ 'product_option_id' => $option->id,
|
|
|
+ 'label' => 'L'.$i,
|
|
|
+ 'code' => 'N'.$i,
|
|
|
+ 'position' => $i,
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $variantIds = [];
|
|
|
+
|
|
|
+ for ($i = 0; $i < $count; $i++) {
|
|
|
+ $current = $i === $count - 1 ? 'SWAP-N0' : 'OLD-'.$i;
|
|
|
+ $variantIds[] = DB::table('product_variants')->insertGetId([
|
|
|
+ 'product_id' => $product->id,
|
|
|
+ 'sku' => $current,
|
|
|
+ 'price' => 10,
|
|
|
+ 'quantity' => 1,
|
|
|
+ 'status' => 1,
|
|
|
+ 'sort_order' => $i,
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $pivots = [];
|
|
|
+
|
|
|
+ foreach ($variantIds as $i => $variantId) {
|
|
|
+ $pivots[] = [
|
|
|
+ 'product_variant_id' => $variantId,
|
|
|
+ 'product_option_value_id' => $valueIds[$i],
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::table('product_variant_option_values')->insert($pivots);
|
|
|
+
|
|
|
+ $this->artisan('products:repair-variant-skus', [
|
|
|
+ '--sku' => 'SWAP',
|
|
|
+ ])->assertSuccessful();
|
|
|
+
|
|
|
+ $this->assertSame('SWAP-N0', DB::table('product_variants')->where('id', $variantIds[0])->value('sku'));
|
|
|
+ $this->assertSame('SWAP-N200', DB::table('product_variants')->where('id', $variantIds[$count - 1])->value('sku'));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return array{0: Product, 1: ProductVariant}
|
|
|
*/
|