Skip to content

[Issue] Allow some SalesSequence data to be retrieved by extensions for customisatioons #40252

@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #40237: Allow some SalesSequence data to be retrieved by extensions for customisatioons


Description (*)

Being able to change the sequence generation for a specific entity type is a reasonably common request. The objective of this PR is to allow extensions to more easily modify this: currently, it is impossible without overriding the whole model (read: copy and paste, since everything is private).

This PR will allow extensions or vendors to change the format, for instance with an after plugin:

public function afterGetNextValue(
    \Magento\SalesSequence\Model\Sequence $subject,
    string $result
) {
    //If we're generating for an order, set its sequence to ECOM{STORE_ID}#{4 DIGIT INC. ID}
    if ('order' === $subject->getEntityType()) {
        return \sprintf('ECOM%d#%\'.04d', $subject->getStoreId(), $subject->calculateCurrentValue());
    }
    
    //Otherwise, passthrough
    return $result;
}

NB: this would probably be a good use case for some sort of expansion (having some di-defined array for entity types to calculate their values), but this is a good first step IMO.

Related Pull Requests

N/A

Fixed Issues (if relevant)

N/A

Manual testing scenarios (*)

This is a transparent API change: it should not change anything. Perhaps trying an after plugin like mentioned above.

Questions or comments

Unsure re: unit tests. I've added some, but they seem superfluous.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: P2A defect with this priority could have functionality issues which are not to expectations.

    Type

    No type

    Projects

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions