Have set up a product with a minimum of 10, maximum 0 (unlimited). Every time I view a page logged in as the administrator, I see an error reading:

"Notice: Undefined variable: output in uc_product_minmax_form_alter() (line 435 of [...]/uc_product_minmax/uc_product_minmax.module)."

Comments

BrandonJSchwartz’s picture

Seemed to have resolved it...or at least made the error disappear. Please advise if I have created a problem elsewhere:

Code was:

  if (variable_get('uc_product_minmax_position', 0) == 1) {
    if ((strpos($form_id, 'add_to_cart_form') > 0 || strpos($form_id, 'uc_catalog_buy_it_now_form_') === 0)) {
      $minmax = uc_product_minmax_feature_load($form['nid']['#value']);

      if ($minmax->pmin_multiple > 1 && $minmax->display_multiple) {
        $output = '<div class="uc_product_multiple">' . t('This product must be ordered in sets of !qty.', array('!qty' => $minmax->pmin_multiple)) . '</div>';
      }
      if ($minmax->product_min > 1 && $minmax->display_min) {
        $output .= '<div class="uc_product_min">' . t('A minimum order of at least !qty is required.', array('!qty' => $minmax->product_min)) . '</div>';
      }
      if ($minmax->product_max >= 1 && $minmax->display_max) {
        $output .= '<div class="uc_product_max">' . t('A maximum order of !qty is allowed.', array('!qty' => $minmax->product_max)) . '</div>';
      }

      $form['qty']['#description'] = $output;
    }
  }
}

Code is...

function uc_product_minmax_form_alter(&$form, &$form_state, $form_id) {
  // Add text for "Add to cart" and "Buy it now" forms
  if (variable_get('uc_product_minmax_position', 0) == 1) {
    if ((strpos($form_id, 'add_to_cart_form') > 0 || strpos($form_id, 'uc_catalog_buy_it_now_form_') === 0)) {
      $minmax = uc_product_minmax_feature_load($form['nid']['#value']);

      if ($minmax->pmin_multiple > 1 && $minmax->display_multiple) {
        $output = '<div class="uc_product_multiple">' . t('This product must be ordered in sets of !qty.', array('!qty' => $minmax->pmin_multiple)) . '</div>';
      }
      if ($minmax->product_min > 1 && $minmax->display_min) {
        $output = '<div class="uc_product_min">' . t('A minimum order of at least !qty is required.', array('!qty' => $minmax->product_min)) . '</div>';
      }
      if ($minmax->product_max >= 1 && $minmax->display_max) {
        $output = '<div class="uc_product_max">' . t('A maximum order of !qty is allowed.', array('!qty' => $minmax->product_max)) . '</div>';
      }

      $form['qty']['#description'] = $output;
    }
  }
}

(Removed the periods before output of min and max messages.)

fred0’s picture

The periods before the equals sign id php for "add this to the previous value. The use in this case is to concatenate the strings so that a buyer sees the various restrictions the module is applying to the product. Removing the periods means that the variable $output will be over-witten by each if statement and only display the last one that matched so, that's not really a solution.
IF you have chosen not to display these restrictions, then all if statements would be false and there would be no $output value. My guess is the correct fix is to set $output to a null value prior to the if statements. Try this and let me know if it works:

function uc_product_minmax_form_alter(&$form, &$form_state, $form_id) {
  // Add text for "Add to cart" and "Buy it now" forms
  if (variable_get('uc_product_minmax_position', 0) == 1) {
    if ((strpos($form_id, 'add_to_cart_form') > 0 || strpos($form_id, 'uc_catalog_buy_it_now_form_') === 0)) {
      $minmax = uc_product_minmax_feature_load($form['nid']['#value']);
      $output = '';
      if ($minmax->pmin_multiple > 1 && $minmax->display_multiple) {
        $output = '<div class="uc_product_multiple">' . t('This product must be ordered in sets of !qty.', array('!qty' => $minmax->pmin_multiple)) . '</div>';
      }
      if ($minmax->product_min > 1 && $minmax->display_min) {
        $output .= '<div class="uc_product_min">' . t('A minimum order of at least !qty is required.', array('!qty' => $minmax->product_min)) . '</div>';
      }
      if ($minmax->product_max >= 1 && $minmax->display_max) {
        $output .= '<div class="uc_product_max">' . t('A maximum order of !qty is allowed.', array('!qty' => $minmax->product_max)) . '</div>';
      }

      $form['qty']['#description'] = $output;
    }
  }
}
Eduardo_Martinez’s picture

Runs for me: Undefined variable outpost solved, but not: Notice: Trying to get property of non-object a uc_product_minmax_form_alter(), see: http://drupal.org/node/1403634

LTech’s picture

Adding the line $output = ''; solved it for me. Thanks

lokolo’s picture

Adding the line $output = ''; solved it for me. Thanks

Did this solve the "Trying to get property of non-object..." notice? Where did u add this?

sibro’s picture

Where can I add the line. My log is seeing mostly these errors.

LTech’s picture

I added the line in the file: sites/all/modules/uc_product_minmax/uc_product_minmax.module
line 430:
function uc_product_minmax_form_alter(&$form, &$form_state, $form_id) {
// Add text for "Add to cart" and "Buy it now" forms
if (variable_get('uc_product_minmax_position', 0) == 1) {
if ((strpos($form_id, 'add_to_cart_form') > 0 || strpos($form_id, 'uc_catalog_buy_it_now_form_') === 0)) {
$minmax = uc_product_minmax_feature_load($form['nid']['#value']);
$output = '';
if ($minmax->pmin_multiple > 1 && $minmax->display_multiple) {
$output = '

' . t('This product must be ordered in sets of !qty.', array('!qty' => $minmax->pmin_multiple)) . '

';
It took away the error.

sibro’s picture

LTech, thanks for your response. I had the line in correctly. It was shown in #2. I am down to this error in my log.

Notice: Trying to get property of non-object in uc_product_minmax_form_alter() (line 438 of /home/fjmcprod/public_html/sites/all/modules/uc_product_minmax/uc_product_minmax.module).

I have many of these every time I have a Drupal transaction.