/** * @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); } }
/** * {@inheritdoc} */ public function setProduct($productCode, ProductInterface $product) { $this->product = $product; $this->productId = $product->getId(); $this->productCode = $productCode; $this->name = $product->getName(); $this->price = $product->getPrice(); $this->options = $product->getOptions(); }
/** * {@inheritdoc} */ public function hasProduct(ProductInterface $product) { if (!array_key_exists($product->getId(), $this->positions)) { return false; } $pos = $this->positions[$product->getId()]; foreach ($this->getBasketElements() as $basketElement) { if ($pos == $basketElement->getPosition()) { return true; } } return false; }
/** * Set the related product * * @param ProductInterface $product */ public function setProduct(ProductInterface $product) { $this->productId = $product->getId(); $this->product = $product; }
/** * return a fresh product instance (so information are reloaded: enabled and stock ...) * * @param \Sonata\Component\Product\ProductInterface $product * @return \Sonata\Component\Product\ProductInterface */ public function reloadProduct(ProductInterface $product) { return $this->findOneById($product->getId()); }