You are here

function uc_attribute_adjustments_delete in Ubercart 8.4

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

Deletes an attribute adjustment.

Parameters

array $fields: Fields used to build a condition to delete adjustments against. Fields currently handled are 'aid', 'oid', and 'nid'.

Return value

int The Drupal SAVED_DELETED flag.

3 calls to uc_attribute_adjustments_delete()
AttributeTest::testAttributeApi in uc_attribute/tests/src/Functional/AttributeTest.php
Tests the basic attribute API.
uc_attribute_subject_delete in uc_attribute/uc_attribute.module
Deletes an attribute and all options associated with it.
uc_attribute_subject_option_delete in uc_attribute/uc_attribute.module
Deletes a product/class attribute option.

File

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

Code

function uc_attribute_adjustments_delete(array $fields) {

  // Build the serialized string to match against adjustments.
  $match = '';
  if (!empty($fields['aid'])) {
    $match .= serialize((int) $fields['aid']);
  }
  if (!empty($fields['oid'])) {
    $match .= serialize((string) $fields['oid']);
  }

  // Assemble the conditions and args for the SQL.
  $connection = \Drupal::database();
  $query = $connection
    ->delete('uc_product_adjustments');

  // If we have to match aid or oid...
  if ($match) {
    $query
      ->condition('combination', '%' . $connection
      ->escapeLike($match) . '%', 'LIKE');
  }

  // If we've got a node ID to match.
  if (!empty($fields['nid'])) {
    $query
      ->condition('nid', $fields['nid']);
  }

  // Delete what's necessary.
  if ($query
    ->conditions()) {
    $query
      ->execute();
  }
  return SAVED_DELETED;
}