1

We use separate order prefixes for our production and lower environments. For each environment we run a sequel statement to update so each environment is unique.

update `sales_sequence_profile` set prefix = "PREFIX";

How would I return the prefix value programmatically?

I am currently working on Magento 2.2.10

1 Answer 1

0

A peer figured this out so I am answering in hopes to benefit others.

Include the following classes and handle dependency injection in _constructor.

use Magento\SalesSequence\Model\ResourceModel\Profile;
use Magento\SalesSequence\Model\ResourceModel\Meta;

Here is function to get prefix:

 /**
     * get Order prefix
     */
    protected function getOrderPrefix()
    {
        try {
            $metaId = $this->_meta->loadByEntityTypeAndStore('order', $this->_storeManager->getStore()->getId());
        } catch (\Exception $e) {
            $this->_logger->critical(
                sprintf("[%s]: Meta not found for Order prefix.",
                    strtoupper($this->queueType)
                )
            );
            return;
        }

        try {
            $collection = $this->_profile->loadActiveProfile($metaId->getId());
        } catch (\Exception $e) {
            $this->_logger->critical(
                sprintf("[%s]: profile not found for Order prefix.",
                    strtoupper($this->queueType)
                )
            );
            return;
        }
        return $collection->getPrefix();
    }

cheers!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.