You are here

protected function TestController::createAttributeOption in Dropdown Attributes 8

Creates an attribute option.

Parameters

array $data: Attribute data.

bool $save: TRUE if attribute should be saved.

3 calls to TestController::createAttributeOption()
TestController::product in uc_dropdown_test/src/Controller/TestController.php
TestController::productClass in uc_dropdown_test/src/Controller/TestController.php
TestController::productKit in uc_dropdown_test/src/Controller/TestController.php

File

uc_dropdown_test/src/Controller/TestController.php, line 663

Class

TestController
Additional test of Dropdown Attributes UI.

Namespace

Drupal\uc_dropdown_test\Controller

Code

protected function createAttributeOption(array $data = array(), $save = TRUE) {
  $max_aid = \Drupal::database()
    ->select('uc_attributes', 'a')
    ->fields('a', array(
    'aid',
  ))
    ->orderBy('aid', 'DESC')
    ->range(0, 1)
    ->execute()
    ->fetchField();
  $option = $data + array(
    'aid' => $max_aid,
    'name' => $this
      ->randGen(8),
    'cost' => mt_rand(0, 500),
    'price' => mt_rand(0, 500),
    'weight' => mt_rand(0, 500),
    'ordering' => mt_rand(-10, 10),
  );
  $option = (object) $option;
  if ($save) {
    uc_attribute_option_save($option);
  }
  return $option;
}