customerSession = $customerSession; $this->meta = $meta; $this->connection = $resource->getConnection('sales'); $this->pattern = $pattern; parent::__construct($meta, $resource, $pattern); } /** * Calculate current value depends on start value * * @return string */ protected function calculateCurrentValue() { return ($this->lastIncrementId - $this->meta->getActiveProfile()->getStartValue()) * $this->meta->getActiveProfile()->getStep() + $this->meta->getActiveProfile()->getStartValue(); } protected function getCustomerAbbr(){ if ($this->customerSession->isLoggedIn()) { return $this->customerSession->getCustomer()->getData('customer_abbr'); } return ''; } /** * Retrieve next value * * @return string */ public function getNextValue(): ?string { $this->connection->insert($this->meta->getSequenceTable(), []); $this->lastIncrementId = $this->connection->lastInsertId($this->meta->getSequenceTable()); return $this->getCurrentValue(); } /** * Retrieve current value * * @return string */ public function getCurrentValue(): ?string { if (!isset($this->lastIncrementId)) { return null; } return 'STI'. date('Ymd'). $this->getCustomerAbbr(). sprintf("%'.05d", $this->calculateCurrentValue()); } }