Warning: in_array(): Wrong datatype for second argument in

..../modules/contribs/ecommerce/product/product.module on line 703

I'm receiving the above error on the home page. I've updated to 4.7.2 and eccomerce 4.7 . I've searched through the forum and on the web for a solution but am stumped. I have checked content type to make sure at least 1 option was checked. I have also deleted the product module and product table in the DB and reinstalled but keep receiving this error. I have also created a product.

Thanks for any assistance.

Comments

mbacas’s picture

I'm getting the same thing after an initial installation of 4.7 ecommerce running on 4.7.2 drupal.

I installed the cvs ecommerce and now I get the same message just on a different line number (712 I believe).

- Mark

dgtlmoon’s picture

i think its doing a callback or invoking a member of a productAPI and expecting an array but its not getting it for some reason (maybe becuase its not checking to see if it got an array back? not sure here)

701: function product_get_specials($node, $total_only = false, $txn = null) {
702: $specials = array();
703: if (!(in_array('no_discounts', product_invoke_productapi($node, 'attributes')))) {

im guessing that product_invoke_productapi($node, 'attributes') is returning nothing/null,
and in_array is doing an array operation on it which is causing the error.

is casting that call as an array with (array) a valid fix? seems to fix the notice here.

703: if (!(in_array('no_discounts', (array)product_invoke_productapi($node,
'attributes')))) {

mbacas’s picture

Or is it just me and ajsloan?

- Mark

dgtlmoon’s picture

Also i think you'll find you're running a module that isnt totally compatible with your product.module

check that the _productapi switch case of your enabled product modules atleast has

    case 'attributes':
      return array();

or

    case 'attributes':
      return array('in_stock');

except for the apparel module as gorden says..

The apparel module has a dependency of the tangible module which is
where are gets all it's attributes, and some other functions from.

lambert-1’s picture

I've been getting the same error, and I don't know why it cropped up. And I still get it after reinstallling Drupal and ecommerce. And I get it even while disabling all the modules except the core ecommerce modules. So ...

I added line 2 and the bracket at line 10

1.  $specials = array();
2.  if (strlen($node->attributes)> 0) {
3.    if (!(in_array('no_discounts', product_invoke_productapi($node, 'attributes')))) {
4.       foreach (module_implements('product_specials') as $name) {
5.         if ($extra = module_invoke($name, 'product_specials', $node, $specials, $txn)) {
6.         $specials = array_merge($specials, $extra);
7.         }
8.       }
9.    }
10. }

It would seem to be an elementary precaution to check for the precondition that the node has the "attributes" field, though maybe there's a better way to make the check?

Also, am I the only one who's confused that sometimes this code returns a number, and sometimes it returns an integer?

ajsloan’s picture

This eliminated the error for me. I'm using Drupal 4.7.3 and the latest 4.7 ecommerce as of 9/5/06 and I still got the error until I tried the fix. Thanks !!!

somebodysysop’s picture

I'm getting this error, and I'm guessing it's because "attributes" needs something. What are the possible attributes that can go here? I just want to make sure that the product is not shippable.
In tangible_productapi of tangible (example) module:

    case 'attributes':
//      $attributes = array('is_shippable');
		$attributes = array(); // from http://drupal.org/node/68472
      if (($node->manage_stock && $node->stock > 0) || !$node->manage_stock) {
        $attributes[] = 'in_stock';
      }
      return $attributes;
      break;
mwu’s picture

I'm getting this same error after installing today's (July 17) ecommerce 4.7.

Carillon’s picture

I resolved this issue by adding the following lines above the: if (!(in_array(:

+ $nodeattributes = product_invoke_productapi($node, 'attributes');
+ if (sizeof($noteattributes)!=0)

Perhaps someone could submit this as a bug for future releases?

Carillon’s picture

I resolved this issue by adding the following lines above the: if (!(in_array(:

+ $nodeattributes = product_invoke_productapi($node, 'attributes');
+ if (sizeof($noteattributes)!=0)

Perhaps someone could submit this as a bug for future releases?

dgtlmoon’s picture

I dont think its a bug, i think its a loose end designed to pull you up if something that is happening isnt exactly what is expected

ie: another module is calling the API without giving it exactly what it is after

kocev’s picture

This is working... Thank you Carillon

Chris Gillis’s picture

Make sure all of your dependencies are turned on. For example, if you are using apparel module, you need tangible.