Question

I recently added rich snippets to the product detail page for simple and configurable.
But now I'm asking myself if it was right to add the meta datas at the end of the templates.

How do you solved this in your projects?

I first tried to set the meta tags outside my template or with other words at the top of my layout.
But then I had to struggle with all product details.

  • How do I know if the product is a simple or configurable?
  • How do I know if the product has related products?

To solve this I need a new template and a new block to make all the queries I have to do when I enter the product detail page.
But at that point I guess it is much easier to create a module.

Was it helpful?

Solution

You can get the current product object by the following code.

 Mage::registry('current_product');

Use this code in any of your file inside the product view page.

To check product type

$currentProduct = Mage::registry('current_product');
$currentProduct->getTypeId(); //return simple, configurable,..

To check related product

$currentProduct->getRelatedProductIds()

This will return related product ids of currency product.

OTHER TIPS

I used to add all itemprop attributes in my templates, but in the end, you'll have to edit a whole bunch of templates.

I'm currently looking into developing an extension, which adds the rich snippets via JSON-LD. The idea is that you can install the extension in your webshop and it will just add a JSON block in the footer (or header) of your page.

It will be publicly available on GitHub asap.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top