public function process()
 {
     $form = $this->createForm($this->get('product.form.create'));
     $form->handleRequest();
     if ($form->isValid()) {
         $productCreator = $this->get('product.create');
         $unitCreator = $this->get('product.unit.create');
         $stockLocations = $this->get('stock.locations');
         $stockManager = $this->get('stock.manager');
         $product = $form->getData();
         $product->authorship->create(new DateTimeImmutable(), $this->get('user.current'));
         // save overwrite product with saved product to get new id
         $product = $productCreator->create($product);
         // save prices
         $product = $this->get('product.edit')->savePrices($product);
         $stockManager->setReason($this->get('stock.movement.reasons')->get('new_order'));
         foreach ($product->getAllUnits() as $unit) {
             $unit->authorship->create(new DateTimeImmutable(), $this->get('user.current'));
             $unit = $unitCreator->create($unit);
             foreach ($unit->getStockArray() as $location => $stock) {
                 $stockManager->set($unit, $stockLocations->get($location), $stock);
             }
         }
         if (!$stockManager->commit()) {
             $this->addFlash('error', 'Could not update stock');
         } else {
             return $this->render('Message:Mothership:Commerce::product:create-complete-modal', ['productID' => $product->id]);
         }
     }
     $response = new Response();
     $response->setStatusCode(400)->headers->set('Content-Type', 'text/html');
     return $this->render('Message:Mothership:Commerce::product:create', ['form' => $form], $response);
 }
Beispiel #2
0
 /**
  * Render a view using the given templating engine. The templating engine is
  * determined by the file extension passed in the view name $view.
  *
  * @param  string $reference The reference for the view to render
  * @param  array  $params    The parameters to use when rendering the view
  *
  * @return Response          The rendered result as a Response instance
  *
  * @throws NotAcceptableHttpException If view could not be rendered
  *
  * @todo When rendering the view, find out the type of the view rendered and
  *       set the content type as appropriate.
  */
 public function render($reference, array $params = array(), Response $response = null)
 {
     if (!$response) {
         $response = new Response();
     }
     // Convert any shorthand parameters to what they should be
     foreach ($params as $key => $val) {
         if ($val instanceof FormHandler) {
             $params[$key] = $val->getForm()->createView();
         }
         if ($val instanceof SymfonyForm\FormBuilder) {
             $params[$key] = $val->getForm()->createView();
         }
         if ($val instanceof SymfonyForm\Form) {
             $params[$key] = $val->createView();
         }
     }
     try {
         $response->setContent($this->_engine->render($reference, $params));
         return $response;
     } catch (\Exception $e) {
         throw new NotAcceptableHttpException(sprintf('Exception thrown while rendering view `%s`: `%s`', $reference, $e->getMessage()), $e);
     }
 }
Beispiel #3
0
 /**
  * @dataProvider getErrorHttpCodes
  */
 public function testIsError($httpCode)
 {
     $response = new Response('', $httpCode);
     $this->assertTrue($response->isError());
 }