You are here

function uc_attribute_adjustments_delete in Ubercart 6.2

Same name and namespace in other branches
  1. 8.4 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

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

Return value

The Drupal SAVED_DELETED flag.

3 calls to uc_attribute_adjustments_delete()
UbercartAttributeTestCase::testAttributeAPI in uc_attribute/uc_attribute.test
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 1081

Code

function uc_attribute_adjustments_delete($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.
  $args = $conditions = array();

  // If we have to match aid or oid...
  if ($match) {
    $conditions[] = "combination LIKE '%%%s%%'";
    $args[] = $match;
  }

  // If we've got a node ID to match.
  if (!empty($fields['nid'])) {
    $conditions[] = "nid = %d";
    $args[] = $fields['nid'];
  }
  $conditions = implode(" AND ", $conditions);

  // Delete what's necessary,
  if ($conditions) {
    db_query("DELETE FROM {uc_product_adjustments} WHERE {$conditions}", $args);
  }
  return SAVED_DELETED;
}