This commit is contained in:
@@ -30,6 +30,44 @@ class StockRepository extends ServiceEntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Stock $entity
|
||||
* @param int $id
|
||||
* @return void
|
||||
*/
|
||||
public function update(Stock $entity, string $id): void
|
||||
{
|
||||
|
||||
$stock = $this->getEntityManager()->getRepository(Stock::class)->find($id);
|
||||
|
||||
if (!$stock) {
|
||||
throw $this->createNotFoundException(
|
||||
'No product found for id '.$id
|
||||
);
|
||||
}
|
||||
|
||||
$stock->setStock($entity->getStock());
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Stock $entity
|
||||
* @return void
|
||||
*/
|
||||
public function upsert(Stock $entity): void
|
||||
{
|
||||
$stock = $this->findByGtin($entity->getGtin());
|
||||
|
||||
if ($stock) {
|
||||
// $stock->setStock($entity->getStock());
|
||||
// $this->getEntityManager()->flush();
|
||||
$this->update($entity,$stock[0]->getId());
|
||||
}else{
|
||||
$this->add($entity,true);
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(Stock $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
@@ -39,20 +77,23 @@ class StockRepository extends ServiceEntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Stock[] Returns an array of Stock objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('s')
|
||||
// ->andWhere('s.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('s.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
/**
|
||||
* @return Stock[] Returns an array of Stock objects
|
||||
*/
|
||||
public function findByGtin($value): array
|
||||
{
|
||||
return $this->createQueryBuilder('s')
|
||||
->andWhere('s.gtin = :val')
|
||||
->setParameter('val', $value)
|
||||
->orderBy('s.id', 'ASC')
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// public function findOneBySomeField($value): ?Stock
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user