Skip to content

Instantly share code, notes, and snippets.

@GoZOo
Last active August 29, 2015 14:14
Show Gist options
  • Save GoZOo/ba25413cfd9828d2a9e0 to your computer and use it in GitHub Desktop.
Save GoZOo/ba25413cfd9828d2a9e0 to your computer and use it in GitHub Desktop.
Drupal Commerce Get all known product displays
<?php
/**
* Get all known product displays.
*
* We know they are product displays if they are node and have
* commerce_product_reference field type.
*
* @return array
* Array of bundle.
*/
function _commerce_get_product_display_bundles() {
$target_bundles = &drupal_static(__FUNCTION__);
if (!isset($target_bundles)) {
$target_bundles = array();
$fields = field_info_fields();
foreach ($fields as $field) {
if ($field['type'] == 'commerce_product_reference' && isset($field['bundles']) && isset($field['bundles']['node'])) {
$target_bundles = array_merge($target_bundles, drupal_map_assoc($field['bundles']['node']));
}
}
}
return $target_bundles;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment