1 reply [Last post]
JaceRider's picture
Offline
Joined: 03/17/2008
Juice: 98
Was this information Helpful?

Hello,

The following are true on my setup:

Drupal 6
Ubercart Latest (Updated Today)
Add to cart field active in Views
Filter set to allow more than just product in listing

I get the following error:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'uc_product_add_to_cart_form_19' was given in /home/lioncry/public_html/includes/form.inc on line 366.

Which I resolved by editing file uc_product_handler_field_addtocart.inc

class uc_product_handler_field_addtocart extends views_handler_field {
  function query() {
    $this->ensure_my_table();
    $this->add_additional_fields();
  }

  function render($values) {
    $type = node_get_types('type', $values->{$this->aliases['type']});
    $module = $type->module;
    $product = node_load($values->{$this->aliases['nid']});
    if (function_exists('theme_'. $module .'_add_to_cart') && $type->type=='product') {
      return theme($module .'_add_to_cart', $product);
    }
    elseif (function_exists('theme_uc_product_add_to_cart') && $type->type=='product') {
      return theme('uc_product_add_to_cart', $product);
    }
  }
}

All I added was "&& $type->type=='product'" to both the if and elseif function to check and see if node is a product.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Drupal 6: Views Error if field Add to cart form and filter s

Product kits and product classes also need to be able to display their forms, so we really need to do a check with uc_product_is_product(). Since we don't need to do anything else if this check fails, I'll patch it so that it goes first:

<?php
 
function render($values) {
    if (
uc_product_is_product($values->{$this->aliases['type']})) {
     
$type = node_get_types('type', $values->{$this->aliases['type']});
     
$module = $type->module;
     
$product = node_load($values->{$this->aliases['nid']});
      if (
function_exists('theme_'. $module .'_add_to_cart')) {
        return
theme($module .'_add_to_cart', $product);
      }
      elseif (
function_exists('theme_uc_product_add_to_cart')) {
        return
theme('uc_product_add_to_cart', $product);
      }
    }
  }
?>