Ejemplo n.º 1
0
 /**
  * @param SeoPageInterface $seoPage
  * @param ProductInterface $product
  */
 public function alterPage(SeoPageInterface $seoPage, ProductInterface $product)
 {
     $this->registerHeaders($seoPage);
     $seoPage->addMeta('property', 'og:type', 'og:product')->addMeta('property', 'og:title', $product->getName())->addMeta('property', 'og:description', $product->getDescription())->addMeta('property', 'og:url', $this->router->generate('sonata_product_view', array('slug' => $product->getSlug(), 'productId' => $product->getId()), true))->addMeta('property', 'product:price:amount', $this->numberHelper->formatDecimal($product->getPrice()))->addMeta('property', 'product:price:currency', $this->currencyDetector->getCurrency());
     // If a media is available, we add the opengraph image data
     if ($image = $product->getImage()) {
         $this->addImageInfo($image, $seoPage);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param ProductInterface $product
  *
  * @return object|\Sonata\MediaBundle\Model\MediaInterface
  */
 protected function getGalleryForProduct(ProductInterface $product)
 {
     $galleryReference = sprintf("gallery_%s", $product->getSku());
     if ($this->hasReference($galleryReference)) {
         return $this->getReference($galleryReference);
     }
     $gallery = $this->getGalleryManager()->create();
     $gallery->setName($product->getSlug());
     $gallery->setEnabled(true);
     $gallery->setDefaultFormat('product_catalog_preview');
     $gallery->setContext('product_catalog');
     $this->setReference($galleryReference, $gallery);
     $this->getGalleryManager()->update($gallery);
     $product->setGallery($gallery);
     return $gallery;
 }