Pregunta

<meta property="og:url" content="<?php echo "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];?>"/>
<meta property="og:description" content=""/> 
<meta property="og:title" content=""/>
<meta property="og:image" content=""/>

He probado con el head.phtml archivo, pero no sé cómo obtener atributos del producto como sku, color y images.

Probé con $this->helper('catalog/image')->init($_product, 'image') encontrado enmedia.phtml en metaetiqueta y obtenga una página en blanco, pero las imágenes en la vista del producto funcionan bien.

Eso me confunde mucho.

¿Fue útil?

Solución

Debe agregar esto a uno de sus archivos de diseño:

<catalog_product_view>
    <reference name="head">
        <block type="core/template" name="open-graph" as="open-graph" template="opengraph/product.phtml" />
    </reference>
</catalog_product_view>

Ahora necesita crear el archivo opengraph/product.phtml Dentro de tu tema (app/design/frontend/{package}/{theme}/template/) con el siguiente contenido:

<?php $_product = Mage::registry('current_product'); ?>
<?php if ($_product) : ?>
    <meta property="og:url" content="<?php echo "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];?>"/>
    <meta property="og:description" content="<?php echo htmlspecialchars($_product->getDescription())?>"/> 
    <meta property="og:title" content="<?php echo htmlspecialchars($_product->getName())?>"/>
    <meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($_product, 'image')?>"/>
<?php endif;?>

Si necesita incluir el sku o color Allí puedes conseguirlos así:

$sku = $_product->getSku();
$color = $_product->getAttributeText('color');

Borre el caché cuando haya terminado.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top