I want to add next/prev images in product and product kit content type. but don't know how.

CommentFileSizeAuthor
#2 next-prev.jpg28.98 KBmogop
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sahar999’s picture

hi,
I'm not sure about your question but I think you can use the method in the module read me file.

first configure it in Administer › Site configuration >Prev/Next.
for product you can change the code in readme file like this.you can add a code to template.php file of your theme:

function pn_node($node, $mode = 'n') {
  if (!function_exists('prev_next_nid')) {
    return NULL;
  }

  switch($mode) {
    case 'p':
      $n_nid = prev_next_nid($node->nid, 'prev');
      $link_text = 'previous';
      break;

    case 'n':
      $n_nid = prev_next_nid($node->nid, 'next');
      $link_text = 'next';
      break;

    default:
      return NULL;
  }

  if ($n_nid) {
     $n_node = node_load($n_nid);
		switch($n_node->type) {
      // For image nodes only
      case 'product':
	   $html = l($link_text, "node/$n_nid", array('html' => TRUE));
       return $html;
      default:
        // Add other node types here if you want.
    }
  }
}

then copy node.tpl.php and rename it to node-product.tpl.php and add html code like this which is shown in readme file.

  <ul id="node-navigation">
    <li class="next"><?php print pn_node($node, 'n'); ?></li>
    <li class="prev"><?php print pn_node($node, 'p'); ?></li>
  </ul>

hope this helps,

mogop’s picture

FileSize
28.98 KB

It is working with some products but not with all. And they are not in order.
I was looking for something like this:
if I have vocab Catalog:
Term 1
- Term 1.1
--product
- Term 1.2
--product
- Term 1.3
-- Term 1.3.1
---product
-- Term 1.3.2
---product
-- Term 1.3.3
---product
- Term 1.4
Term 2
- Term 2.1
-- Term 2.1.1
-- Term 2.1.2
- Term 2.2
- Term 2.3
... and so on...

Previous / Next should point to another products from the same term that is the present product, but instead of Previous / Next links to show prev and next product with Image and title

:)))))
sounds like a big request

sahar999’s picture

I think you can start by changing the pn_node method. I changed it a little may be that helps. you may need to change the path.

function pn_node($node, $mode = 'n') {
  if (!function_exists('prev_next_nid')) {
    return NULL;
  }

  switch($mode) {
    case 'p':
      $n_nid = prev_next_nid($node->nid, 'prev');
       break;

    case 'n':
      $n_nid = prev_next_nid($node->nid, 'next');
       break;

    default:
      return NULL;
  }

  if ($n_nid) {
     $n_node = node_load($n_nid);
	  $options = array(
      'attributes' => array('class' => 'thumbnail'),
      'html'  => TRUE,
    );
		switch($n_node->type) {
      // For image nodes only
      case 'product':
	   $html  = '<img src="'.base_path().'sites/default/files/imagecache/product/' . $n_node->field_image_cache[0]['filename'];
       $html .= '" class="image image-thumbnail" />';
        $img_html = l($html, "node/$n_nid", $options);
	   $text_html .= l($n_node->title, "node/$n_nid", array('html' => TRUE));
       return $img_html . $text_html;
      default:
        // Add other node types here if you want.
    }
  }
}
mogop’s picture

I'm not sure how to set the image path but was something like this : sites/default/files/imagecache/product/[type]/[termpath-raw]/[nid] - but for termpath I use path auto and i18n module

and still the prev/next products are not from the same term is it possible to choice vocabulary/1/term/tid
I have 2 vocab : one for multiply tags and another for the Product Category.

sahar999’s picture

I've modified the code of module in order to include taxonomy. you can make these changes to see if it solves the problem. I suggest you to make a backup first.this may not solve all of issues. please let me know if it works.
in prev_next.module file replace this function.

function _prev_next_add($nid) {
  $node_type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d LIMIT 1", $nid));
  $search_criteria = variable_get(PREV_NEXT_NODE_TYPE . $node_type . '_indexing_criteria', PREV_NEXT_INDEXING_CRITERIA_DEFAULT);

  $criteria_value = db_result(db_query("SELECT %s FROM {node} WHERE nid = %d LIMIT 1", $search_criteria, $nid));

  $cond = _prev_next_node_types_sql($node_type);
   $node = node_load($nid, NULL, TRUE);
	$mytid= end($node->taxonomy)->tid;
  $next_nid = db_result(db_query("SELECT n.nid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid WHERE %s > '%s' AND r.tid = ".$mytid." AND status = 1 $cond ORDER BY %s ASC LIMIT 1",
    $search_criteria, $criteria_value, $search_criteria));


  $prev_nid = db_result(db_query("SELECT n.nid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid WHERE %s < '%s' AND r.tid = ".$mytid." AND status = 1 $cond ORDER BY %s DESC LIMIT 1",
    $search_criteria, $criteria_value, $search_criteria));

  // Update the node-level data
  $exists = db_result(db_query('SELECT COUNT(*) FROM {prev_next_node} WHERE nid = %d', $nid));
  if ($exists) {
    db_query('UPDATE {prev_next_node} SET prev_nid = %d, next_nid = %d, changed = %d WHERE nid = %d',
      $prev_nid, $next_nid, time(), $nid);
  }
  else {
    db_query('INSERT INTO {prev_next_node} (prev_nid, next_nid, changed, nid) VALUES (%d, %d, %d, %d)',
      $prev_nid, $next_nid, time(), $nid);
  }

  // Update the other nodes pointing to this node
  foreach (node_get_types() as $type => $name) {
    if (variable_get(PREV_NEXT_NODE_TYPE . $type, 0)) {
      $search_criteria = variable_get(PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria', PREV_NEXT_INDEXING_CRITERIA_DEFAULT);
      $criteria_value = db_result(db_query("SELECT %s FROM {node} WHERE nid = %d LIMIT 1", $search_criteria, $nid));
	  
      $cond = _prev_next_node_types_sql($node_type);
	$node = node_load($nid, NULL, TRUE);
	$mytid= end($node->taxonomy)->tid;
      $next_nid = db_result(db_query("SELECT n.nid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid WHERE %s < '%s' AND r.tid = ".$mytid." AND status = 1 $cond ORDER BY %s DESC LIMIT 1",
        $search_criteria, $criteria_value, $search_criteria));
      if ($next_nid) {
        db_query("UPDATE {prev_next_node} SET next_nid = %d WHERE nid = %d", $nid, $next_nid);
      }
      $prev_nid = db_result(db_query("SELECT n.nid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid WHERE %s > '%s' AND r.tid = ".$mytid." AND status = 1 $cond ORDER BY %s ASC LIMIT 1",
        $search_criteria, $criteria_value, $search_criteria));
      if ($prev_nid) {
        db_query("UPDATE {prev_next_node} SET prev_nid = %d WHERE nid = %d", $nid, $prev_nid);
      }
    }
  }

}
mogop’s picture

I have no idea of what is going wrong but now the block for prev/next is not showing...

sahar999’s picture

may be you need to re index the site in Administer › Site configuration >Prev/Next

mogop’s picture

My indexing status was 0% before I run Cron, now it's 100% and the block is showing but in the links there is no space between the category name and the title of the product, look like this : "product category nametitle of a product"

In order to get the image of the product I change your code
from:
$html = '<img src="'.base_path().'sites/default/files/imagecache/product/' . $n_node->field_image_cache[0]['filename'];
to:
$html = '<img src="'.base_path().'/' . $n_node->field_image_cache[0]['filepath'];

which gives me the original image but it's not very good solution because the size of the file is very big instead I want to use image cache profile for that image but I don't know how to get the path.Is there any way to use File path tokens like these bellow? :

<img src="'.base_path().'sites/default/files/imagecache/imagecache_profile'  . [type]/[termpath-raw]/[nid] . $n_node->field_image_cache[0]['filename'];

and still prev/next links sometimes are based on tags used for that product. they are not showing items of the same category as the current product. I use vocab/1/terms/category for product categories and vocab/3/terms/tags for tagging products

bhosmer’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

Is this still an issue for you? If so, feel free to reopen.

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)