/** * @param Order $order * @param Request $request * * @return array|RedirectResponse */ protected function update(Order $order, Request $request) { if (!$order->getAccountUser()) { $accountUser = $this->get('oro_security.security_facade')->getLoggedUser(); if (!$accountUser instanceof AccountUser) { throw new \InvalidArgumentException('Only AccountUser can create an Order.'); } $order->setAccountUser($accountUser); } if ($order->getAccount()) { $paymentTerm = $this->get('orob2b_payment.provider.payment_term')->getPaymentTerm($order->getAccount()); if ($paymentTerm) { $order->setPaymentTerm($paymentTerm); } } //TODO: set correct owner in task BB-929 if (!$order->getOwner()) { $user = $this->getDoctrine()->getManagerForClass('OroUserBundle:User')->getRepository('OroUserBundle:User')->findOneBy([]); $order->setOwner($user); } $form = $this->createForm(FrontendOrderType::NAME, $order); $handler = new OrderHandler($form, $request, $this->getDoctrine()->getManagerForClass(ClassUtils::getClass($order)), $this->get('orob2b_order.provider.subtotals')); return $this->get('oro_form.model.update_handler')->handleUpdate($order, $form, function (Order $order) { return ['route' => 'orob2b_order_frontend_update', 'parameters' => ['id' => $order->getId()]]; }, function (Order $order) { return ['route' => 'orob2b_order_frontend_view', 'parameters' => ['id' => $order->getId()]]; }, $this->get('translator')->trans('orob2b.order.controller.order.saved.message'), $handler, function (Order $order, FormInterface $form, Request $request) { return ['form' => $form->createView(), 'entity' => $order, 'isWidgetContext' => (bool) $request->get('_wid', false), 'isShippingAddressGranted' => $this->getOrderAddressSecurityProvider()->isAddressGranted($order, AddressType::TYPE_SHIPPING), 'isBillingAddressGranted' => $this->getOrderAddressSecurityProvider()->isAddressGranted($order, AddressType::TYPE_BILLING), 'tierPrices' => $this->getTierPrices($order), 'matchedPrices' => $this->getMatchedPrices($order)]; }); }