2 replies [Last post]
baalsgate's picture
Offline
Joined: 09/12/2007
Juice: 46
Was this information Helpful?

ok i searched and found nothing related to this problem
which I thought is odd as I would have thought someone else would have seen this before
ok what happens is that adding the "Manufacturers" module
I find that if i select a Manufacturer that does not have any products assigned to it , in stead of it saying " no products found " which would be ideal, it gives the following error.

warning: Invalid argument supplied for foreach() in /www/http/modules/ubercart/uc_product/uc_product.module on line 728.

Now being the great programmer that I am not ... I will give this a go ..

I would have thought that a simple if statement that evaluated if there was any products to return and if so continues else it gives " No Products Found "
easy... well it would be if i was any good with this syntax or where to put it ...

But in the effort of solving the issue I have posted a hack in this thread even while im not so sure what or how its working ...

The modified subroutine for " case data" from the file uc_product.module if some official developer wants to clean this up and add to the latest version that would be great too, saves me having to hack a future version.

I could not figure out how to remove the table with Image , Name and Price so I just added a message line to say that Nothing was found ,

(( Revised version of the code can be found in a follow up post ))

Hope it helps someone else

baalsgate's picture
Offline
Joined: 09/12/2007
Juice: 46
ok something stuffed up in that

I seems to have made a mess of that last post oh... i see now code tags ...

try again ...

  case 'data':
      $data = array();

if($args['nids']) {

      foreach ($args['nids'] as $nid){
        $node = node_load($nid);
        if ($node->type != 'image'){
          if (module_exists('imagecache') && isset($node->field_image_cache) && file_exists($node->field_image_cache[0]['filepath'])
){
            $data['image'][] = l(theme('imagecache', 'product_list', $node->field_image_cache[0]['filepath']), 'node/'. $node->nid,
array(), null, null, false, true);
          }
          else{
            $data['image'][] = t('n/a');
          }
          $data['name'][] = array('data' => l($node->title, 'node/'. $node->nid), 'width' => '100%');
          $data['price'][] = array('data' => theme('uc_product_sell_price', $node->sell_price, true), 'nowrap' => 'nowrap');
          if (arg(0) != 'admin'){
            $data['add_to_cart'][] = drupal_get_form('uc_catalog_buy_it_now_form_'. $node->nid, $node);
          }
        }
      }
}
else{
        $data['image'][] = t('     ');
        $data['name'][] = t('                 &
nbsp;                 No Products found for this Sea
rch                      &n
bsp;              ');
        $data['price'][] = t('    ');
}

      return $data;
    case 'attributes':
      return $args['attributes'];
  }
}

ok again I hope that helps someone else

baalsgate's picture
Offline
Joined: 09/12/2007
Juice: 46
Bit of a clean up Version 2 :)

Just getting a little bit better at the syntax and after reading
http://api.drupal.org/api/function/theme_table/5
it made more sense so here I have the formating on the " No Products Found " looking a lot cleaner and also works when page size changes Smiling

this is from the file : uc_product.module

    case 'data':
      $data = array();

if($args['nids']) {

      foreach ($args['nids'] as $nid){
        $node = node_load($nid);
        if ($node->type != 'image'){
          if (module_exists('imagecache') && isset($node->field_image_cache) && file_exists($node->field_image_cache[0]['filepath'])
){
            $data['image'][] = l(theme('imagecache', 'product_list', $node->field_image_cache[0]['filepath']), 'node/'. $node->nid,
array(), null, null, false, true);
          }
          else{
            $data['image'][] = t('n/a');
          }
          $data['name'][] = array('data' => l($node->title, 'node/'. $node->nid), 'width' => '100%');
          $data['price'][] = array('data' => theme('uc_product_sell_price', $node->sell_price, true), 'nowrap' => 'nowrap');
          if (arg(0) != 'admin'){
            $data['add_to_cart'][] = drupal_get_form('uc_catalog_buy_it_now_form_'. $node->nid, $node);
          }
        }
      }
}
else{
        $data['image'][] = t('     ');
//      $data['name'][] = t('100%' );
         $data['name'][] = array('data' => t('Sorry No Products Found'), 'width' => '100%');
        $data['price'][] = t('    ');
}

      return $data;
    case 'attributes':
      return $args['attributes'];
  }
}