public getManager ( Sonata\Component\Product\ProductInterface | string $code ) : Sonata\Component\Product\ProductManagerInterface | ||
$code | Sonata\Component\Product\ProductInterface | string | |
return | Sonata\Component\Product\ProductManagerInterface |
/** * Deletes a product * * @ApiDoc( * requirements={ * {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="product identifier"} * }, * statusCodes={ * 200="Returned when post is successfully deleted", * 400="Returned when an error has occurred while product deletion", * 404="Returned when unable to find product" * } * ) * * @param integer $id A Product identifier * * @return \FOS\RestBundle\View\View * * @throws NotFoundHttpException */ public function deleteProductAction($id) { $product = $this->getProduct($id); $manager = $this->productPool->getManager($product); try { $manager->delete($product); } catch (\Exception $e) { return \FOS\RestBundle\View\View::create(array('error' => $e->getMessage()), 400); } return array('deleted' => true); }
/** * Write a product, this method is used by both POST and PUT action methods. * * @param string $provider A product provider name * @param Request $request Symfony request * @param int|null $id A product identifier * * @return \FOS\RestBundle\View\View|FormInterface */ protected function handleWriteProduct($provider, $request, $id = null) { $product = $id ? $this->getProduct($id) : null; try { $manager = $this->productPool->getManager($provider); } catch (\RuntimeException $e) { throw new NotFoundHttpException($e->getMessage(), $e); } $form = $this->formFactory->createNamed(null, 'sonata_product_api_form_product', $product, array('csrf_protection' => false, 'data_class' => $manager->getClass(), 'provider_name' => $provider)); $form->bind($request); if ($form->isValid()) { $product = $form->getData(); $product->setDescription($this->formatterPool->transform($product->getDescriptionFormatter(), $product->getRawDescription())); $product->setShortDescription($this->formatterPool->transform($product->getShortDescriptionFormatter(), $product->getRawShortDescription())); $manager->save($product); $view = \FOS\RestBundle\View\View::create($product); $serializationContext = SerializationContext::create(); $serializationContext->setGroups(array('sonata_api_read')); $serializationContext->enableMaxDepthChecks(); $view->setSerializationContext($serializationContext); return $view; } return $form; }
/** * Get the Manager of the given Product. * * @param string $productType * * @return ManagerInterface */ protected function getProductManager($productType) { return $this->productPool->getManager($productType); }
/** * {@inheritdoc} */ public function delete($object) { $this->pool->getManager($object)->delete($object); }