I'm converting from an old UPS module to the newer Commerce UPS. The old module used integer fields for height, length, width. The Commerce UPS module demands a multi-dimensional field 'Product_Dimensions'. So I want to update the Product_Dimensions field with the old data.

I created a View with a VBO column and I selected Execute Arbitrary PHP Script as my operation. Here is my code:

$product = commerce_product_load($entity->product_id); $product->field_package_dimensions = array( "und" => array(0 => array( length=>"91", width=>"22", height=>"11", unit=>"in") ) ); commerce_product_save($product); // dpm($product->field_package_dimensions);

...the product_dimensions field is being updated BUT each dimension of the array is being assigned a single character '9'. ie. the length, width and height are all '9'. So clearly there is something wrong with my array assignment?

Can someone tell me what I'm doing wrong? I'm sure it's an obvious mistake... or there is a 'proper' procedure for programmatically updating commerce product fields that I'm missing.


1 Answer 1


For any future travelers.

This may be my ignorance but it seems like you -must- use commerce_product_load(), even thought it kinda looks like the $entity object is the same as the $product object.

$product = commerce_product_load($entity->product_id); $product->field_package_dimensions = array( LANGUAGE_NONE => array( 0 => array('length'=> $entity->field_length['und'][0]['value'], 'width'=> $entity->field_width['und'][0]['value'], 'height' => $entity->field_height['und'][0]['value'], 'unit'=>"in") ) ); commerce_product_save($product);

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.