You are here

function uc_attribute_save in Ubercart 8.4

Same name and namespace in other branches
  1. 6.2 uc_attribute/uc_attribute.module \uc_attribute_save()
  2. 7.3 uc_attribute/uc_attribute.module \uc_attribute_save()

Saves an attribute object to the database.

Parameters

object $attribute: The attribute object to save.

Return value

\Drupal\Core\Database\StatementInterface|null A prepared statement, or NULL if the query is not valid.

3 calls to uc_attribute_save()
AttributeTestTrait::createAttribute in uc_attribute/tests/src/Traits/AttributeTestTrait.php
Creates an attribute.
InclusiveTaxTest::testProductKitAttributes in uc_tax/tests/src/Functional/InclusiveTaxTest.php
Test inclusive taxes with product kit attributes.
UbercartTestBase::createAttribute in uc_store/src/Tests/UbercartTestBase.php
Creates an attribute.

File

uc_attribute/uc_attribute.module, line 601
Ubercart Attribute module.

Code

function uc_attribute_save(&$attribute) {
  $fields = [
    'name' => $attribute->name,
    'label' => $attribute->label,
    'ordering' => $attribute->ordering,
    'required' => (int) $attribute->required,
    'display' => $attribute->display,
    'description' => $attribute->description,
  ];
  $connection = \Drupal::database();
  if (empty($attribute->aid)) {
    $attribute->aid = $connection
      ->insert('uc_attributes')
      ->fields($fields)
      ->execute();
    return Merge::STATUS_INSERT;
  }
  else {
    return $connection
      ->merge('uc_attributes')
      ->key('aid', $attribute->aid)
      ->fields($fields)
      ->execute();
  }
}