Discussions

How to get Product-ID from Display-Node-ID programmaticly?

How do i get Product-ID from Display-Node-ID programmaticly? Any help much appreciated!

Posted: Jul 25, 2012

Comments

Joel Wallis Jucá on January 31, 2013

You can get the value from the product reference field. Example:

<?php
// let's suppose that $product_display_node contains the node we are handling
$product_id = $product_display_node->field_product[$product_display_node->language][0]['product_id'];

$product = entity_load('commerce_product', $product_id);

// use dpm() to show the entire object in the drupal's message system. requires Devel module
dpm($product);
?>