On the content page the vote button shows always 0 vote if I reload the page after voted but in the Voting results tab shows an accurate vote.

The strangeness is if I show the node in a view works correctly.

Comments

Heihachi88’s picture

Same here, Drupal 7.22 and Rate 7.x-2.x dev, through views it showing up correctly, but not inside a node.

giupenni’s picture

Same problem

merdekiti’s picture

Same here

merdekiti’s picture

The problem here

  if ($widget->use_source_translation) {
    $criteria['entity_id'] = _rate_get_source_translation($criteria['entity_type'], $criteria['entity_id']);
  }

478 line of rate.module

When you use "Use source translation" option for a widget it will show you 0 votes after page reload. Don't know why.

merdekiti’s picture

Have found the problem
I'm using latest dev version.

I have added a few more lines in rate.module file

Here is my change:

function _rate_get_source_translation($entity_type, $entity_id) {
  if ($entity_type == 'node' && module_exists('translation')) {
    if (arg(0) == 'node' && arg(1) == $entity_id) {
      // We are on the node page. Use node_load since the node is in static cache.
      $entity = node_load($entity_id);
      if ($entity->tnid) {
        $entity_id = $entity->tnid;
      }
    }
    else {
      // We are not on the node page. Do not use node_load to prevent executing many useless queries.
      $tnid = db_select('node', 'n')->fields('n', array('tnid'))->condition('n.nid', $entity_id)->execute()->fetchField();
      if ($tnid) {
        $entity_id = $tnid;
      }
    }
  }
  return $entity_id;
}

Old code:

function _rate_get_source_translation($entity_type, $entity_id) {
  if ($entity_type == 'node' && module_exists('translation')) {
    if (arg(0) == 'node' && arg(1) == $entity_id) {
      // We are on the node page. Use node_load since the node is in static cache.
      $entity_id = node_load($entity_id)->tnid;
    }
    else {
      // We are not on the node page. Do not use node_load to prevent executing many useless queries.
      $tnid = db_select('node', 'n')->fields('n', array('tnid'))->condition('n.nid', $entity_id)->execute()->fetchField();
      if ($tnid) {
        $entity_id = $tnid;
      }
    }
  }
  return $entity_id;
}

This return null if a node not translated
$entity_id = node_load($entity_id)->tnid;

nikita petrov’s picture

it's works for me, thanks, merdekiti!

organicwire’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

I think this is the same issue as #1931868: source translation option on untranslated nodes causes 0 votes display. There's a patch for the problem.