Skip to content

Commit

Permalink
wrap product copy around a DB::transaction()
Browse files Browse the repository at this point in the history
  • Loading branch information
Herbert Maschke committed Aug 5, 2020
1 parent ebb6fa0 commit 73a210f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/Webkul/Product/src/Repositories/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,23 @@ public function copy(Product $originalProduct): Product
throw new Exception(trans('admin::app.response.booking-can-not-be-copied'));
}

$copiedProduct = $this->persistCopiedProduct($originalProduct);
DB::beginTransaction();

$this->persistAttributeValues($originalProduct, $copiedProduct);
try {
$copiedProduct = $this->persistCopiedProduct($originalProduct);

$this->persistRelations($originalProduct, $copiedProduct);
$this->persistAttributeValues($originalProduct, $copiedProduct);

$this->persistRelations($originalProduct, $copiedProduct);
} catch (Exception $e) {
DB::rollBack();

report($e);

throw $e;
}

DB::commit();

return $copiedProduct;
}
Expand Down

0 comments on commit 73a210f

Please sign in to comment.