Hi,

there is an problem in this module with SQL statement in uc_discounts_product_class_apply function.
Old one:

  $sql = "SELECT * FROM {uc_discounts_conditions} WHERE discount_id=%d ";
  $sql .= "AND property='product_class' AND item_id='%s' ";
  $sql .= "ORDER BY condition_group, weight";

and fixed:

  $sql = "SELECT * FROM {uc_discounts_conditions} WHERE discount_id=%d ";
//  $sql .= "AND property='product_class' AND item_id='%s' ";
  $sql .= "ORDER BY condition_group, weight";

Comments

joachim’s picture

Hi.
Thanks for the code!
Could you explain what the change does please? Why is the old version wrong, and what does the new version fix?

mhrabovcin’s picture

Hi,

I think that lines from 135 to 148 can be deleted, because there is no need to check condition when discount is applied. Conditions are checked in uc_discoutns_apply_discount($node) function. Only if product matches conditions discounts are applied. In uc_discounts_product_class_apply function we need to check only if item is certain node type (by action) - lines from 150.

Its because condition can be checked in other module. Example:
Apply 10% from product type when user has role (authenticated user). - condition (user has role) is checked in uc_discounts_role module.

Node type checking brings me to another bug i've found - discounts aren't applied on cart items, only on nodes. In cart aren't stored whole nodes. So product type isn't available, it has to be loaded. Changes from line 150:

  $product_price = 0;
  foreach ($cart as $index => $product) {
    // we need to apply changes on cart items, they doesn't contain node type
    if (!isset($product->type)) {
      $product_node = node_load(array('nid' => $product->nid));
      $product->type = $product_node->type;
    }

    if ($product->nid == $action->item_id || $product->type == $action->item_id) {
      $product_count += $product->qty;
      $product_price = $product->price;
      $product_found[$index] = $product->qty;
    }
  } // foreach product