I am using the metatag module and there is no problem to retrieve fields of the very node displayed. However, I cannot find how can I use the field_product_image of the product entity to use as token for the Open Graph Protocol image attribute.

As I can use "regular" fields, I have added the issue here, and not in the metatag issue queue. Any help is blessed :)

Comments

rszrama’s picture

Status: Active » Closed (won't fix)

No clue, but I really don't think this is the right place for such a question. We don't handle support requests here (per the issue submission guidelines), and I've never heard of the module in question. : P

Amir Simantov’s picture

Done: here. Also added a link to the metatag module which you've never heard of :P

rvallejo’s picture

I posted an answer at drupalcommerce.org, but copying here for others stumbling on this issue:

How many products do you have on each node?

Field value deltas start at 0, which means if your display only has one product attached to it (or you have a single-value product reference field) then you should be using [node:field-product:0:field_product_image] instead of [node:field-product:1:field_product_image].

Poor UI, IMHO - it doesn't provide the 0th value in the available tokens dialog, but it works if you type it in.

For multiple-value image field metatags, there are a couple issues:

First, the Metatag module/submodules currently list all image urls in a comma-delineated list in a single meta tag. There is a fix for Open Graph tags at https://drupal.org/node/1305402#comment-6420040.

Second, selecting which image you want to use from a multiple-value field doesn't seem to be working currently. Same issue, later comment: https://drupal.org/node/1305402#comment-7890015

I'm also working on a sandbox module to expand the Metatag module to provide integration for Drupal Commerce/product-related tags, available at https://drupal.org/sandbox/rvallejo/2102725. I include the fix for splitting multiple images into multiple tags for Open Graph and Twitter, based on code at the first comment I linked to above.

ANDiTKO’s picture

Issue summary: View changes

Ok i had no luck finding a proper solution for this. "Metatag:OpenGraph", "Metatag:OpenGraph Products" and "Token" modules were not working as expected. So i had to do this on my own.

Here is the code i used inside the "field--field_product_images.tpl.php" file:

// Unset any existing og:image metatags.
unset($variables['page']['content']['metatags']['global:frontpage']['og:image']);

// Set image URL.
$image = file_create_url($items[0]['#item']['uri']);

// Define the metatag element.
$element = array(
  '#tag' => 'meta',
  '#attributes' => array(
    "property" => "og:image",
    "content" => $image,
  ),
);

// Add the og:image metatag to the page.
drupal_add_html_head($element,'opengraph_image');

In my case it worked perfectly. Make sure you wrap this inside an if that checks if $element['#view_mode'] == 'node_full'