When using taxonomy as a condition in CA, the actions were never executed, the problem is located at line 120 in uc_discount.ca.inc, I changed to code as follows, because $terms can be a string/number

    // Get the chosen terms that the node actually has.
    if (is_array($terms)) {
      $has_terms = array_intersect($terms, $node_terms);
    }
    else {
      $has_terms = in_array($terms, $node_terms);
    }
CommentFileSizeAuthor
#2 node_category.patch1.17 KBIsland Usurper

Comments

henrrrik’s picture

I've found a couple of problems in uc_discount_condition_node_term() in uc_discount.ca.inc.

  1. taxonomy_node_get_terms() fails on $node because $node isn't a fully populated node object in this context and $node->vid is empty. A node_load() solves this, but I assume real problem is located in ca.module.
    $node = node_load($node->nid);
    $node_terms = array_keys(taxonomy_node_get_terms($node));
    ...
    
  2. as attiks points out, array_intersect() fails if there's only one term. However, is_array() only returns a bool result, not the term id. I replaced it with this:
    if (is_array($terms)) {
      $has_terms = array_intersect($terms, $node_terms);
    }
    else {
      $has_terms = (in_array($terms, $node_terms) ? $terms : FALSE);
    }
    
Island Usurper’s picture

Status: Active » Needs review
StatusFileSize
new1.17 KB

I want to avoid doing node_load() in condition and action code, because they might be used during a View's construction. Doing all those extra node_load()s would be too big a performance hit. That said, I've resorted to using a database call anyway to get the $node->vid if it isn't there. Hopefully that won't be too bad.

It's also a lot easier just to force $terms to be an array than to do different things whether it is or not.

Island Usurper’s picture

Status: Needs review » Fixed

Committed, since I haven't heard anything back.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.