You are here

public static function CartStorage::update in Basic cart 8.6

Same name and namespace in other branches
  1. 8 src/CartStorage.php \Drupal\basic_cart\CartStorage::update()
  2. 8.0 src/CartStorage.php \Drupal\basic_cart\CartStorage::update()
  3. 8.2 src/CartStorage.php \Drupal\basic_cart\CartStorage::update()
  4. 8.3 src/CartStorage.php \Drupal\basic_cart\CartStorage::update()
  5. 8.4 src/CartStorage.php \Drupal\basic_cart\CartStorage::update()
  6. 8.5 src/CartStorage.php \Drupal\basic_cart\CartStorage::update()

Update a cart entry in the database.

Parameters

array $entry: An array containing all the fields of the item to be updated.

Return value

int The number of updated rows.

See also

db_update()

File

src/CartStorage.php, line 56

Class

CartStorage
Class CartStorage.

Namespace

Drupal\basic_cart

Code

public static function update(array $entry) {
  try {

    // db_update()...->execute() returns the number of rows updated.
    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
    // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
    $count = \Drupal::database()
      ->update(self::TABLE)
      ->fields($entry)
      ->condition('uid', $entry['uid'])
      ->condition('id', $entry['id'])
      ->condition('entitytype', $entry['entitytype'])
      ->execute();
  } catch (\Exception $e) {
    \Drupal::messenger()
      ->addError(t('db_update failed. Message = %message, query= %query', array(
      '%message' => $e
        ->getMessage(),
      '%query' => $e->query_string,
    )));
  }
  return $count;
}