Получить NID по Product_id (Drupal Commerce)

    Опубликовано Andres - пт, 05/03/2019 - 14:59

    http://xandeadx.ru/blog/drupal/749

     

    $id = 4430;

    $product = commerce_product_load($id);
    $product_type = $product->type;

    $product_id = $id;
    $bundle = 'split_sistemy_kondicionery';
    $field_name = 'field_cart';

      $product_display_nid = db_select('field_data_' . $field_name, 'f')
        ->fields('f', array('entity_id'))
        ->condition('f.' . $field_name . '_product_id', $product_id)
        ->condition('f.bundle', $bundle)
        ->range(0, 1)
        ->execute()
        ->fetchField();
      $product_display_nid = $product_display_nid;

    pr($product_display_nid);

     

    https://drupalcommerce.org/questions/3176/how-get-node-id-product-display-using-product-id#comment-8708

     

    $id = 4430;
    $commerce_product = commerce_product_load($id);

    $product = $commerce_product;
      global $language;

      // Itterate thhrough fields which refer to products.
      foreach (commerce_info_fields('commerce_product_reference') as $field['field_name']) {
        // Build query.
        $query = new EntityFieldQuery;
        $query->entityCondition('entity_type', 'node', '=')
          ->fieldCondition($field['field_name'], 'product_id', $product->product_id, '=')
          ->propertyCondition('language', $language->language, '=')
          ->range(0, 1);

        if ($result = $query->execute()) {
          // Return node id.
          $product_display_nid = array_shift(array_keys($result['node']));
        }
      }

    print $product_display_nid;