コード例 #1
0
 /**
  * Find line item with the same product and unit
  *
  * @param LineItem $lineItem
  *
  * @return LineItem
  */
 public function findDuplicate(LineItem $lineItem)
 {
     $qb = $this->createQueryBuilder('li')->where('li.product = :product')->andWhere('li.unit = :unit')->andWhere('li.shoppingList = :shoppingList')->setParameter('product', $lineItem->getProduct())->setParameter('unit', $lineItem->getUnit())->setParameter('shoppingList', $lineItem->getShoppingList());
     if ($lineItem->getId()) {
         $qb->andWhere('li.id != :currentId')->setParameter('currentId', $lineItem->getId());
     }
     return $qb->getQuery()->getOneOrNullResult();
 }
コード例 #2
0
 /**
  * @param LineItem $lineItem
  * @param LineItem $existingLineItem
  */
 protected function updateExistingLineItem(LineItem $lineItem, LineItem $existingLineItem)
 {
     $existingLineItem->setQuantity($lineItem->getQuantity() + $existingLineItem->getQuantity());
     $existingLineItemNote = $existingLineItem->getNotes();
     $newNotes = $lineItem->getNotes();
     $notes = trim(implode(' ', [$existingLineItemNote, $newNotes]));
     if ($notes) {
         $existingLineItem->setNotes($notes);
     }
     $this->savedId = $existingLineItem->getId();
 }