Created
May 22, 2017 05:24
-
-
Save druman/90da2b1bcd9036145aa4e4f68ca1b698 to your computer and use it in GitHub Desktop.
Get display node id for a commerce product
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get display node id for a commerce product. | |
* @param $product_id | |
* An integer value of the product id. | |
* @param string $product_field_name | |
* Name of the commerce_product_reference field used to reference products from display node. | |
* @return FALSE|node_id | |
* Returns FALSE if no results or display node id on success. | |
*/ | |
function MY_CUSTOM_MODULE_get_display_node_by_product_id($product_id, $product_field_name = 'product_reference') { | |
$query = new EntityFieldQuery; | |
$result = $query->entityCondition('entity_type', 'node', '=') | |
->propertyCondition('type', 'tire') | |
->fieldCondition($product_field_name, 'product_id', $product_id, '=') | |
->range(0, 1)->execute(); | |
if (empty($result['node'])) { | |
return FALSE; | |
} | |
return reset($result['node'])->nid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment