CodeExplorer getProductFromDetail example
protected $entityManager;
public function __construct(ModelManager
$entityManager) { $this->entityManager =
$entityManager;
} public function addProductDetail(OrderDetail
$detail): void
{ $product =
$this->
getProductFromDetail($detail);
if ($product) { $product->
setInStock($product->
getInStock() -
$detail->
getQuantity());
$this->entityManager->
persist($product);
$this->entityManager->
flush($product);
} } public function updateProductDetail(OrderDetail
$detail, ?string
$oldProductNumber = null, ?int
$oldQuantity = null, ?string
$newProductNumber = null, ?int
$newQuantity = null
): void
{ $oldQuantity =
$oldQuantity === 0 ||
$oldQuantity > 0 ?
$oldQuantity :
$detail->
getQuantity();
$newQuantity =
$newQuantity === 0 ||
$newQuantity > 0 ?
$newQuantity :
$detail->
getQuantity();