Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.7
Component:
Product
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
23 May 2013 at 10:20 UTC
Updated:
24 May 2013 at 13:55 UTC
I`m trying to alter product price with hook_node_presave.
So I`m loading products attached to my product display.
And it seems that both commerce_product_load and commerce_product_load_multiple cause this error:
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\AppServ\www\trailhead\includes\entity.inc).
Here an example how I`m trying to do it:
$pids = array();
foreach ($node->field_product['und'] as $key => $product_id) {
if ( !empty($product_id) ) {
$pids[] = $product_id;
}
}
if ( !empty($pids) ) {
$products = commerce_product_load_multiple($pids);
}
or like this:
foreach ($node->field_product['und'] as $key => $product_id) {
if ( !empty($product_id) ) {
$product = commerce_product_load($product_id);
}
}
Both variants work properly but return set of errors. Can`t find out how to fix this errors.
Comments
Comment #1
vasikeyour issue is real, But:
1. there's no bug.
2. the code is wrong - $node->field_product['und'] array items are arrays not product ids : array('product_id' => xxx), where is xxx is the product id number
here is the corrected code:
Comment #2
lanzs commentedOh, such a stupid error, I was looking everythere but not in that place (because I was sure of using product_id).
Thaks a lot for help!