public function SequentialNumberPatternBase::getCurrentSequence in Commerce Core 8.2
Gets the current sequence for the given entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.
Return value
\Drupal\commerce_number_pattern\Sequence|null The current sequence, or NULL if none found.
Overrides SequentialNumberPatternInterface::getCurrentSequence
1 call to SequentialNumberPatternBase::getCurrentSequence()
- SequentialNumberPatternBase::getNextSequence in modules/
number_pattern/ src/ Plugin/ Commerce/ NumberPattern/ SequentialNumberPatternBase.php - Gets the next sequence for the given entity.
File
- modules/
number_pattern/ src/ Plugin/ Commerce/ NumberPattern/ SequentialNumberPatternBase.php, line 210
Class
- SequentialNumberPatternBase
- Provides a base class for number pattern plugins which support sequences.
Namespace
Drupal\commerce_number_pattern\Plugin\Commerce\NumberPatternCode
public function getCurrentSequence(ContentEntityInterface $entity) {
$query = $this->connection
->select('commerce_number_pattern_sequence', 'cnps');
$query
->fields('cnps', [
'store_id',
'number',
'generated',
]);
$query
->condition('entity_id', $this->parentEntity
->id())
->condition('store_id', $this
->getStoreId($entity))
->forUpdate();
$result = $query
->execute()
->fetchAssoc();
if (empty($result)) {
return NULL;
}
return new Sequence([
'number' => $result['number'],
'generated' => $result['generated'],
'store_id' => $result['store_id'],
]);
}