src/Flowcode/ShopBundle/Controller/ProductController.php
/**
     * Finds and displays a Product entity.
     *
     * @Route("/{slug}", name="product_show")
     * @Method("GET")
     * @Template()
     */
Finds and displays a Product entity.
Finds and displays a Product entity .
public function showAction($slug, Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $productService = $this->get("amulen.shop.product");
        $productOrderService = $this->get("amulen.shop.order");
        $productOrderItemService = $this->get("amulen.shop.order.item");
        $entity = $em->getRepository('AmulenShopBundle:Product')->findOneBy(array("slug" => $slug));
        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Product entity.');
        } else {
            $seoPage = $this->container->get('sonata.seo.page');
            $baseTitle = $seoPage->getTitle();
            $title = ucfirst($entity->getName()) . " - Productos - " . $baseTitle;
            $seoPage->setTitle($title);
            $seoPage->addMeta('property', "og:type", "product");
            $seoPage->addMeta('property', "og:title", $title);
            $seoPage->addMeta('property', "og:description", $entity->getDescription());
            $seoPage->addMeta('property', "og:url", $this->generateUrl('product_show', [
                'slug' => $entity->getSlug()
            ], UrlGeneratorInterface::ABSOLUTE_URL));
            $seoPage->addMeta('property', "product:price:amount", $entity->getPrice());
            $seoPage->addMeta('property', "product:price:currency", 'ARS');
            if ($entity->getImage()) {
                $absoluteImageUrl = $this->generateUrl('base_path', [], UrlGeneratorInterface::ABSOLUTE_URL);
                $absoluteImageUrl .= $entity->getImage()->getPath();
                $seoPage->addMeta('property', "og:image", $absoluteImageUrl);
            }
        }
        $prodQty = 1;
        $session = $request->getSession();
        $productOrderId = $session->get('productOrderId');
        $productOrder = $productOrderService->getProductOrder($productOrderId);
        if (!$productOrderId) {
            $session->set('productOrderId', $productOrder->getId());
        }
        return array(
            'entity' => $entity,
            'productQtyOrder' => $prodQty,
            'current_products' => $productOrder->getProductsAdded(),
        );
    }
public function showAction ( $ slug , Request $ request ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ productService = $ this -> get ( " amulen.shop.product " ) ; $ productOrderService = $ this -> get ( " amulen.shop.order " ) ; $ productOrderItemService = $ this -> get ( " amulen.shop.order.item " ) ; $ entity = $ em -> getRepository ( 'AmulenShopBundle:Product' ) -> findOneBy ( array ( " slug " => $ slug ) ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find Product entity.' ) ; } else { $ seoPage = $ this -> container -> get ( 'sonata.seo.page' ) ; $ baseTitle = $ seoPage -> getTitle ( ) ; $ title = ucfirst ( $ entity -> getName ( ) ) . "  - Productos -  " . $ baseTitle ; $ seoPage -> setTitle ( $ title ) ; $ seoPage -> addMeta ( 'property' , " og:type " , " product " ) ; $ seoPage -> addMeta ( 'property' , " og:title " , $ title ) ; $ seoPage -> addMeta ( 'property' , " og:description " , $ entity -> getDescription ( ) ) ; $ seoPage -> addMeta ( 'property' , " og:url " , $ this -> generateUrl ( 'product_show' , [ 'slug' => $ entity -> getSlug ( ) ] , UrlGeneratorInterface :: ABSOLUTE_URL ) ) ; $ seoPage -> addMeta ( 'property' , " product:price:amount " , $ entity -> getPrice ( ) ) ; $ seoPage -> addMeta ( 'property' , " product:price:currency " , 'ARS' ) ; if ( $ entity -> getImage ( ) ) { $ absoluteImageUrl = $ this -> generateUrl ( 'base_path' , [ ] , UrlGeneratorInterface :: ABSOLUTE_URL ) ; $ absoluteImageUrl .= $ entity -> getImage ( ) -> getPath ( ) ; $ seoPage -> addMeta ( 'property' , " og:image " , $ absoluteImageUrl ) ; } } $ prodQty = 1 ; $ session = $ request -> getSession ( ) ; $ productOrderId = $ session -> get ( 'productOrderId' ) ; $ productOrder = $ productOrderService -> getProductOrder ( $ productOrderId ) ; if ( ! $ productOrderId ) { $ session -> set ( 'productOrderId' , $ productOrder -> getId ( ) ) ; } return array ( 'entity' => $ entity , 'productQtyOrder' => $ prodQty , 'current_products' => $ productOrder -> getProductsAdded ( ) , ) ; }
Finds and displays a Product entity.
Finds and displays a Product entity .
/* ProductOrder */