/** * @param \Generated\Shared\Transfer\TypeTransfer $stockTypeTransfer * * @throws \Spryker\Zed\Stock\Business\Exception\StockTypeNotFoundException * * @return int */ public function updateStockType(TypeTransfer $stockTypeTransfer) { Propel::getConnection()->beginTransaction(); $stockTypeEntity = $this->queryContainer->queryStockByName($stockTypeTransfer->getName())->findOne(); if ($stockTypeEntity === null) { throw new StockTypeNotFoundException(); } $stockTypeEntity->setName($stockTypeTransfer->getName()); $stockTypeEntity->save(); Propel::getConnection()->commit(); return $stockTypeEntity->getIdStock(); }
/** * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function stockAction(Request $request) { $form = $this->getFactory()->getStockForm($request); if ($form->isValid()) { $stockTypeTransfer = new TypeTransfer(); $stockTypeTransfer->fromArray($form->getRequestData()); if ($stockTypeTransfer->getIdStock() === null) { $this->getFacade()->createStockType($stockTypeTransfer); } else { $this->getFacade()->updateStockType($stockTypeTransfer); } $form->setActiveValuesToDefault(); } return $this->jsonResponse($form->renderData()); }