0

I am working on a reverse auction for our youth group. I'm using D7 with the commerce_auction module. I ran into the error below when setting up the content type for the auction:

Notice: Undefined offset: 0 in commerce_auction_node_presave() (line 260 of /public_html/catz/sites/all/modules/commerce_auction/commerce_auction.module).
EntityMalformedException: Missing bundle property on entity of type commerce_product. in entity_extract_ids() (line 7697 of /public_html/catz/includes/common.inc).

for the first notice, line 260 contains this: $product_reference = $product_reference[0];

Does anyone know how to fix this error? There's not a lot of commenting as yet on this auction module, so I can't find a solution.

/** * Implements hook_node_presave(). */

function commerce_auction_node_presave($node) {
  $types = variable_get('commerce_auction_display_types', array());
  if (in_array($node->type, $types) !== FALSE) {
    $product_reference = field_get_items('node', $node, 'field_product');
    $product_reference = $product_reference[0];
    $product = commerce_product_load($product_reference['product_id']);
    $price = field_get_items('commerce_product', $product, 'commerce_price');
    $node->auction_starting_price[LANGUAGE_NONE][0]['amount'] = $price[0]['amount'];
    $node->auction_starting_price[LANGUAGE_NONE][0]['currency_code'] = $price[0]['currency_code'];
  }
}

2 Answers 2

0

Change the code below :

 $node->auction_starting_price[LANGUAGE_NONE][0]['amount'] = $price[0]['amount'];
    $node->auction_starting_price[LANGUAGE_NONE][0]['currency_code'] = $price[0]['currency_code'];

with

 $node->auction_starting_price[LANGUAGE_NONE][0]['amount'] = $price['und'][0]['amount'];
        $node->auction_starting_price[LANGUAGE_NONE][0]['currency_code'] = $price['und'][0]['currency_code'];
0

You can fix that error by updating (or moving) to the 7.x-2.x-dev version of the module. commerce_auction_node_presave() has been changed to use the following code.

function commerce_auction_node_presave($node) {
  $types = variable_get('commerce_auction_display_types', array());
  if (in_array($node->type, $types) !== FALSE) {
    $product_reference = field_get_items('node', $node, 'field_product');
    if (!empty($product_reference)) {
      $product_reference = $product_reference[0];
      $product = commerce_product_load($product_reference['product_id']);
      $price = field_get_items('commerce_product', $product, 'commerce_price');
      $node->auction_starting_price[LANGUAGE_NONE][0]['amount'] = $price[0]['amount'];
      $node->auction_starting_price[LANGUAGE_NONE][0]['currency_code'] = $price[0]['currency_code'];
    }
  }
}

Differently from the 7.x-1.x-dev version, the code now verifies $product_reference is not an empty value (for example, an empty array), before trying to use $product_reference[0], which is sufficient to avoid the error you are seeing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.