introduce ability to make original and copy be linked to each other

This commit is contained in:
Herbert Maschke 2020-08-10 09:31:56 +02:00
parent 96e6c56375
commit 3670a6210b
3 changed files with 15 additions and 0 deletions

View File

@ -8,4 +8,7 @@ return [
'skipAttributesOnCopy' => [ 'skipAttributesOnCopy' => [
], ],
// Make the original and source product 'related' via the 'product_relations' table
'linkProductsOnCopy' => true,
]; ];

View File

@ -703,5 +703,12 @@ class ProductRepository extends Repository
$variant->save(); $variant->save();
} }
} }
if (config('products.linkProductsOnCopy')) {
DB::table('product_relations')->insert([
'parent_id' => $originalProduct->id,
'child_id' => $copiedProduct->id,
]);
}
} }
} }

View File

@ -74,6 +74,11 @@ class ProductCopyCest
'qty' => 10, 'qty' => 10,
]); ]);
$I->seeRecord('product_relations', [
'parent_id' => $original->id,
'child_id' => $copiedProduct->id,
]);
$flat = $I->grabRecord(ProductFlat::class, [ $flat = $I->grabRecord(ProductFlat::class, [
'product_id' => $copiedProduct->id, 'product_id' => $copiedProduct->id,
]); ]);