You are here

function uc_dropdown_attributes_dependency_type in Dropdown Attributes 8

Same name and namespace in other branches
  1. 6 uc_dropdown_attributes.module \uc_dropdown_attributes_dependency_type()
  2. 7 uc_dropdown_attributes.module \uc_dropdown_attributes_dependency_type()

Retrieve whether dependencies are defined by node or class.

Parameters

int $nid: Node id.

Return value

string 'node' for dependencies defined on the node level; 'class' for dependencies defined on the product class; otherwise, NULL.

6 calls to uc_dropdown_attributes_dependency_type()
UCDropdownAttributesClassTest::testClassAttributeDependency in src/Tests/UCDropdownAttributesClassTest.php
Test for dropdown attributes in classes.
UCDropdownAttributesProductTest::testProductAttributeDependency in src/Tests/UCDropdownAttributesProductTest.php
Test for dropdown attributes in products.
uc_dropdown_attributes_form_alter in ./uc_dropdown_attributes.module
Implements hook_form_alter().
uc_dropdown_attributes_form_uc_order_edit_form_alter in ./uc_dropdown_attributes.module
Implements hook_form_FORM_ID_alter() for uc_order_edit_form().
_uc_dropdown_attributes_kit_build in ./uc_dropdown_attributes.module
Form build for product kits.

... See full list

File

./uc_dropdown_attributes.module, line 725
A module for uc_dropdown_attributes.

Code

function uc_dropdown_attributes_dependency_type($nid) {
  $count = \Drupal::database()
    ->select('uc_dropdown_products', 'products')
    ->fields('products', array(
    'nid',
  ))
    ->condition('products.nid', $nid)
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($count > 0) {
    return 'node';
  }
  $pcid = uc_dropdown_attributes_get_type($nid);
  $count = \Drupal::database()
    ->select('uc_dropdown_classes', 'classes')
    ->fields('classes', array(
    'pcid',
  ))
    ->condition('classes.pcid', $pcid)
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($count > 0) {
    return 'class';
  }
  return NULL;
}