How to get entity id(order id) in success phtmladd custom attribute in Admin > sales > order > select orderRewrite of block and helper for checkout getCheckoutUrl() not workingHow to use init() method to load order by ID?how to get custom field value to save order table in Checkout page in Magento 2InvalidArgumentException - Magento functional TestingHow to get an order id in success.phtml block?How to get the order id in success.phtml?Get parameters from URL Magento 2How to get last ordered product details in Magento 2.2?How Do I get Order id from module-checkout/Block/Onepage/Success.php in magento 2

can i play a electric guitar through a bass amp?

Do I have a twin with permutated remainders?

Why don't electromagnetic waves interact with each other?

How to write a macro that is braces sensitive?

"which" command doesn't work / path of Safari?

Did Shadowfax go to Valinor?

Do any Labour MPs support no-deal?

What typically incentivizes a professor to change jobs to a lower ranking university?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Show a continuous function with f(x)=y and f(y)=x has a fixed point.

The magic money tree problem

Why don't electron-positron collisions release infinite energy?

Magento 2: Admin panel 3 level menu structure not working

If two metric spaces are topologically equivalent (homeomorphic) imply that they are complete?

Writing rule which states that two causes for the same superpower is bad writing

How does strength of boric acid solution increase in presence of salicylic acid?

Service Entrance Breakers Rain Shield

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

Prevent a directory in /tmp from being deleted

Is it possible to do 50 km distance without any previous training?

Languages that we cannot (dis)prove to be Context-Free

N.B. ligature in Latex

Basic combinations logic doubt in probability

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?



How to get entity id(order id) in success phtml


add custom attribute in Admin > sales > order > select orderRewrite of block and helper for checkout getCheckoutUrl() not workingHow to use init() method to load order by ID?how to get custom field value to save order table in Checkout page in Magento 2InvalidArgumentException - Magento functional TestingHow to get an order id in success.phtml block?How to get the order id in success.phtml?Get parameters from URL Magento 2How to get last ordered product details in Magento 2.2?How Do I get Order id from module-checkout/Block/Onepage/Success.php in magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















In my success.phtml , $block->getViewOrderUrl() gives a order url with order id(entity id) .



dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Success.php




/sales/order/view/order_id/173569/




How to get this order id alone - 173569 in success.phtml.



I don't see any functions in success.php










share|improve this question




























    1















    In my success.phtml , $block->getViewOrderUrl() gives a order url with order id(entity id) .



    dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Success.php




    /sales/order/view/order_id/173569/




    How to get this order id alone - 173569 in success.phtml.



    I don't see any functions in success.php










    share|improve this question
























      1












      1








      1








      In my success.phtml , $block->getViewOrderUrl() gives a order url with order id(entity id) .



      dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Success.php




      /sales/order/view/order_id/173569/




      How to get this order id alone - 173569 in success.phtml.



      I don't see any functions in success.php










      share|improve this question














      In my success.phtml , $block->getViewOrderUrl() gives a order url with order id(entity id) .



      dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Success.php




      /sales/order/view/order_id/173569/




      How to get this order id alone - 173569 in success.phtml.



      I don't see any functions in success.php







      magento2 orders onepage-checkout sales-order order-success-page






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      summusummu

      3329




      3329




















          1 Answer
          1






          active

          oldest

          votes


















          1














          You can try this one to get the order Id alone:



          $block->getOrderId()



          UPDATE:



          You can override the Block file of checkout success one page using preference and define your own method to get the order Id.

          Try this:

          In your custom module's di.xml file add this:



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCheckoutBlockOnepageSuccess" type="VendorModuleBlockOnepageSuccess" />
          </config>


          Now create Success.php Block file in Folder VendorModuleBlockOnepage



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleBlockOnepage;

          use MagentoCustomerModelContext;
          use MagentoSalesModelOrder;

          /**
          * One page checkout success page
          *
          * @api
          * @since 100.0.2
          */
          class Success extends MagentoFrameworkViewElementTemplate

          /**
          * @var MagentoCheckoutModelSession
          */
          protected $_checkoutSession;

          /**
          * @var MagentoSalesModelOrderConfig
          */
          protected $_orderConfig;

          /**
          * @var MagentoFrameworkAppHttpContext
          */
          protected $httpContext;

          /**
          * @param MagentoFrameworkViewElementTemplateContext $context
          * @param MagentoCheckoutModelSession $checkoutSession
          * @param MagentoSalesModelOrderConfig $orderConfig
          * @param MagentoFrameworkAppHttpContext $httpContext
          * @param array $data
          */
          public function __construct(
          MagentoFrameworkViewElementTemplateContext $context,
          MagentoCheckoutModelSession $checkoutSession,
          MagentoSalesModelOrderConfig $orderConfig,
          MagentoFrameworkAppHttpContext $httpContext,
          array $data = []
          )
          parent::__construct($context, $data);
          $this->_checkoutSession = $checkoutSession;
          $this->_orderConfig = $orderConfig;
          $this->_isScopePrivate = true;
          $this->httpContext = $httpContext;


          /**
          * Render additional order information lines and return result html
          *
          * @return string
          */
          public function getAdditionalInfoHtml()

          return $this->_layout->renderElement('order.success.additional.info');


          /**
          * Initialize data and prepare it for output
          *
          * @return string
          */
          protected function _beforeToHtml()

          $this->prepareBlockData();
          return parent::_beforeToHtml();


          /**
          * Prepares block data
          *
          * @return void
          */
          protected function prepareBlockData()

          $order = $this->_checkoutSession->getLastRealOrder();

          $this->addData(
          [
          'is_order_visible' => $this->isVisible($order),
          'view_order_url' => $this->getUrl(
          'sales/order/view/',
          ['order_id' => $order->getEntityId()]
          ),
          'print_url' => $this->getUrl(
          'sales/order/print',
          ['order_id' => $order->getEntityId()]
          ),
          'can_print_order' => $this->isVisible($order),
          'can_view_order' => $this->canViewOrder($order),
          'order_id' => $order->getIncrementId()
          ]
          );


          /**
          * Is order visible
          *
          * @param Order $order
          * @return bool
          */
          protected function isVisible(Order $order)

          return !in_array(
          $order->getStatus(),
          $this->_orderConfig->getInvisibleOnFrontStatuses()
          );


          /**
          * Can view order
          *
          * @param Order $order
          * @return bool
          */
          protected function canViewOrder(Order $order)

          return $this->httpContext->getValue(Context::CONTEXT_AUTH)
          && $this->isVisible($order);


          /**
          * @return string
          * @since 100.2.0
          */
          public function getContinueUrl()

          return $this->_storeManager->getStore()->getBaseUrl();



          /**
          * @return string
          * getOrigId
          */
          public function getOrigId()

          return $this->_checkoutSession->getLastRealOrder()->getEntityId();





          Then you can now get the Order Id(Entity Id) in your .phtml template like this:



          $block->getOrigId()





          share|improve this answer

























          • $block->getOrderId() will get me entity id ? whats the difference between $block->getViewOrderUrl()->getId() and $block->getOrderId()

            – summu
            4 hours ago











          • Yeah, the $block->getOrderId() will get the entity id. Actually, I am not sure with the $block->getViewOrderUrl()->getId() but you can check.

            – magefms
            4 hours ago












          • $block->getOrderId() gave me increment id not entitty id, /sales/order/view/order_id/173569/ , this 173569 is entity id which output of $block->getViewOrderUrl() , i just wanted 173569

            – summu
            2 hours ago












          • I think better if you would override the Block file for checkout success.phtml file and create your own method to get order Id

            – magefms
            1 hour ago






          • 1





            @summu updated my answer please check

            – magefms
            1 hour ago












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269043%2fhow-to-get-entity-idorder-id-in-success-phtml%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can try this one to get the order Id alone:



          $block->getOrderId()



          UPDATE:



          You can override the Block file of checkout success one page using preference and define your own method to get the order Id.

          Try this:

          In your custom module's di.xml file add this:



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCheckoutBlockOnepageSuccess" type="VendorModuleBlockOnepageSuccess" />
          </config>


          Now create Success.php Block file in Folder VendorModuleBlockOnepage



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleBlockOnepage;

          use MagentoCustomerModelContext;
          use MagentoSalesModelOrder;

          /**
          * One page checkout success page
          *
          * @api
          * @since 100.0.2
          */
          class Success extends MagentoFrameworkViewElementTemplate

          /**
          * @var MagentoCheckoutModelSession
          */
          protected $_checkoutSession;

          /**
          * @var MagentoSalesModelOrderConfig
          */
          protected $_orderConfig;

          /**
          * @var MagentoFrameworkAppHttpContext
          */
          protected $httpContext;

          /**
          * @param MagentoFrameworkViewElementTemplateContext $context
          * @param MagentoCheckoutModelSession $checkoutSession
          * @param MagentoSalesModelOrderConfig $orderConfig
          * @param MagentoFrameworkAppHttpContext $httpContext
          * @param array $data
          */
          public function __construct(
          MagentoFrameworkViewElementTemplateContext $context,
          MagentoCheckoutModelSession $checkoutSession,
          MagentoSalesModelOrderConfig $orderConfig,
          MagentoFrameworkAppHttpContext $httpContext,
          array $data = []
          )
          parent::__construct($context, $data);
          $this->_checkoutSession = $checkoutSession;
          $this->_orderConfig = $orderConfig;
          $this->_isScopePrivate = true;
          $this->httpContext = $httpContext;


          /**
          * Render additional order information lines and return result html
          *
          * @return string
          */
          public function getAdditionalInfoHtml()

          return $this->_layout->renderElement('order.success.additional.info');


          /**
          * Initialize data and prepare it for output
          *
          * @return string
          */
          protected function _beforeToHtml()

          $this->prepareBlockData();
          return parent::_beforeToHtml();


          /**
          * Prepares block data
          *
          * @return void
          */
          protected function prepareBlockData()

          $order = $this->_checkoutSession->getLastRealOrder();

          $this->addData(
          [
          'is_order_visible' => $this->isVisible($order),
          'view_order_url' => $this->getUrl(
          'sales/order/view/',
          ['order_id' => $order->getEntityId()]
          ),
          'print_url' => $this->getUrl(
          'sales/order/print',
          ['order_id' => $order->getEntityId()]
          ),
          'can_print_order' => $this->isVisible($order),
          'can_view_order' => $this->canViewOrder($order),
          'order_id' => $order->getIncrementId()
          ]
          );


          /**
          * Is order visible
          *
          * @param Order $order
          * @return bool
          */
          protected function isVisible(Order $order)

          return !in_array(
          $order->getStatus(),
          $this->_orderConfig->getInvisibleOnFrontStatuses()
          );


          /**
          * Can view order
          *
          * @param Order $order
          * @return bool
          */
          protected function canViewOrder(Order $order)

          return $this->httpContext->getValue(Context::CONTEXT_AUTH)
          && $this->isVisible($order);


          /**
          * @return string
          * @since 100.2.0
          */
          public function getContinueUrl()

          return $this->_storeManager->getStore()->getBaseUrl();



          /**
          * @return string
          * getOrigId
          */
          public function getOrigId()

          return $this->_checkoutSession->getLastRealOrder()->getEntityId();





          Then you can now get the Order Id(Entity Id) in your .phtml template like this:



          $block->getOrigId()





          share|improve this answer

























          • $block->getOrderId() will get me entity id ? whats the difference between $block->getViewOrderUrl()->getId() and $block->getOrderId()

            – summu
            4 hours ago











          • Yeah, the $block->getOrderId() will get the entity id. Actually, I am not sure with the $block->getViewOrderUrl()->getId() but you can check.

            – magefms
            4 hours ago












          • $block->getOrderId() gave me increment id not entitty id, /sales/order/view/order_id/173569/ , this 173569 is entity id which output of $block->getViewOrderUrl() , i just wanted 173569

            – summu
            2 hours ago












          • I think better if you would override the Block file for checkout success.phtml file and create your own method to get order Id

            – magefms
            1 hour ago






          • 1





            @summu updated my answer please check

            – magefms
            1 hour ago
















          1














          You can try this one to get the order Id alone:



          $block->getOrderId()



          UPDATE:



          You can override the Block file of checkout success one page using preference and define your own method to get the order Id.

          Try this:

          In your custom module's di.xml file add this:



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCheckoutBlockOnepageSuccess" type="VendorModuleBlockOnepageSuccess" />
          </config>


          Now create Success.php Block file in Folder VendorModuleBlockOnepage



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleBlockOnepage;

          use MagentoCustomerModelContext;
          use MagentoSalesModelOrder;

          /**
          * One page checkout success page
          *
          * @api
          * @since 100.0.2
          */
          class Success extends MagentoFrameworkViewElementTemplate

          /**
          * @var MagentoCheckoutModelSession
          */
          protected $_checkoutSession;

          /**
          * @var MagentoSalesModelOrderConfig
          */
          protected $_orderConfig;

          /**
          * @var MagentoFrameworkAppHttpContext
          */
          protected $httpContext;

          /**
          * @param MagentoFrameworkViewElementTemplateContext $context
          * @param MagentoCheckoutModelSession $checkoutSession
          * @param MagentoSalesModelOrderConfig $orderConfig
          * @param MagentoFrameworkAppHttpContext $httpContext
          * @param array $data
          */
          public function __construct(
          MagentoFrameworkViewElementTemplateContext $context,
          MagentoCheckoutModelSession $checkoutSession,
          MagentoSalesModelOrderConfig $orderConfig,
          MagentoFrameworkAppHttpContext $httpContext,
          array $data = []
          )
          parent::__construct($context, $data);
          $this->_checkoutSession = $checkoutSession;
          $this->_orderConfig = $orderConfig;
          $this->_isScopePrivate = true;
          $this->httpContext = $httpContext;


          /**
          * Render additional order information lines and return result html
          *
          * @return string
          */
          public function getAdditionalInfoHtml()

          return $this->_layout->renderElement('order.success.additional.info');


          /**
          * Initialize data and prepare it for output
          *
          * @return string
          */
          protected function _beforeToHtml()

          $this->prepareBlockData();
          return parent::_beforeToHtml();


          /**
          * Prepares block data
          *
          * @return void
          */
          protected function prepareBlockData()

          $order = $this->_checkoutSession->getLastRealOrder();

          $this->addData(
          [
          'is_order_visible' => $this->isVisible($order),
          'view_order_url' => $this->getUrl(
          'sales/order/view/',
          ['order_id' => $order->getEntityId()]
          ),
          'print_url' => $this->getUrl(
          'sales/order/print',
          ['order_id' => $order->getEntityId()]
          ),
          'can_print_order' => $this->isVisible($order),
          'can_view_order' => $this->canViewOrder($order),
          'order_id' => $order->getIncrementId()
          ]
          );


          /**
          * Is order visible
          *
          * @param Order $order
          * @return bool
          */
          protected function isVisible(Order $order)

          return !in_array(
          $order->getStatus(),
          $this->_orderConfig->getInvisibleOnFrontStatuses()
          );


          /**
          * Can view order
          *
          * @param Order $order
          * @return bool
          */
          protected function canViewOrder(Order $order)

          return $this->httpContext->getValue(Context::CONTEXT_AUTH)
          && $this->isVisible($order);


          /**
          * @return string
          * @since 100.2.0
          */
          public function getContinueUrl()

          return $this->_storeManager->getStore()->getBaseUrl();



          /**
          * @return string
          * getOrigId
          */
          public function getOrigId()

          return $this->_checkoutSession->getLastRealOrder()->getEntityId();





          Then you can now get the Order Id(Entity Id) in your .phtml template like this:



          $block->getOrigId()





          share|improve this answer

























          • $block->getOrderId() will get me entity id ? whats the difference between $block->getViewOrderUrl()->getId() and $block->getOrderId()

            – summu
            4 hours ago











          • Yeah, the $block->getOrderId() will get the entity id. Actually, I am not sure with the $block->getViewOrderUrl()->getId() but you can check.

            – magefms
            4 hours ago












          • $block->getOrderId() gave me increment id not entitty id, /sales/order/view/order_id/173569/ , this 173569 is entity id which output of $block->getViewOrderUrl() , i just wanted 173569

            – summu
            2 hours ago












          • I think better if you would override the Block file for checkout success.phtml file and create your own method to get order Id

            – magefms
            1 hour ago






          • 1





            @summu updated my answer please check

            – magefms
            1 hour ago














          1












          1








          1







          You can try this one to get the order Id alone:



          $block->getOrderId()



          UPDATE:



          You can override the Block file of checkout success one page using preference and define your own method to get the order Id.

          Try this:

          In your custom module's di.xml file add this:



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCheckoutBlockOnepageSuccess" type="VendorModuleBlockOnepageSuccess" />
          </config>


          Now create Success.php Block file in Folder VendorModuleBlockOnepage



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleBlockOnepage;

          use MagentoCustomerModelContext;
          use MagentoSalesModelOrder;

          /**
          * One page checkout success page
          *
          * @api
          * @since 100.0.2
          */
          class Success extends MagentoFrameworkViewElementTemplate

          /**
          * @var MagentoCheckoutModelSession
          */
          protected $_checkoutSession;

          /**
          * @var MagentoSalesModelOrderConfig
          */
          protected $_orderConfig;

          /**
          * @var MagentoFrameworkAppHttpContext
          */
          protected $httpContext;

          /**
          * @param MagentoFrameworkViewElementTemplateContext $context
          * @param MagentoCheckoutModelSession $checkoutSession
          * @param MagentoSalesModelOrderConfig $orderConfig
          * @param MagentoFrameworkAppHttpContext $httpContext
          * @param array $data
          */
          public function __construct(
          MagentoFrameworkViewElementTemplateContext $context,
          MagentoCheckoutModelSession $checkoutSession,
          MagentoSalesModelOrderConfig $orderConfig,
          MagentoFrameworkAppHttpContext $httpContext,
          array $data = []
          )
          parent::__construct($context, $data);
          $this->_checkoutSession = $checkoutSession;
          $this->_orderConfig = $orderConfig;
          $this->_isScopePrivate = true;
          $this->httpContext = $httpContext;


          /**
          * Render additional order information lines and return result html
          *
          * @return string
          */
          public function getAdditionalInfoHtml()

          return $this->_layout->renderElement('order.success.additional.info');


          /**
          * Initialize data and prepare it for output
          *
          * @return string
          */
          protected function _beforeToHtml()

          $this->prepareBlockData();
          return parent::_beforeToHtml();


          /**
          * Prepares block data
          *
          * @return void
          */
          protected function prepareBlockData()

          $order = $this->_checkoutSession->getLastRealOrder();

          $this->addData(
          [
          'is_order_visible' => $this->isVisible($order),
          'view_order_url' => $this->getUrl(
          'sales/order/view/',
          ['order_id' => $order->getEntityId()]
          ),
          'print_url' => $this->getUrl(
          'sales/order/print',
          ['order_id' => $order->getEntityId()]
          ),
          'can_print_order' => $this->isVisible($order),
          'can_view_order' => $this->canViewOrder($order),
          'order_id' => $order->getIncrementId()
          ]
          );


          /**
          * Is order visible
          *
          * @param Order $order
          * @return bool
          */
          protected function isVisible(Order $order)

          return !in_array(
          $order->getStatus(),
          $this->_orderConfig->getInvisibleOnFrontStatuses()
          );


          /**
          * Can view order
          *
          * @param Order $order
          * @return bool
          */
          protected function canViewOrder(Order $order)

          return $this->httpContext->getValue(Context::CONTEXT_AUTH)
          && $this->isVisible($order);


          /**
          * @return string
          * @since 100.2.0
          */
          public function getContinueUrl()

          return $this->_storeManager->getStore()->getBaseUrl();



          /**
          * @return string
          * getOrigId
          */
          public function getOrigId()

          return $this->_checkoutSession->getLastRealOrder()->getEntityId();





          Then you can now get the Order Id(Entity Id) in your .phtml template like this:



          $block->getOrigId()





          share|improve this answer















          You can try this one to get the order Id alone:



          $block->getOrderId()



          UPDATE:



          You can override the Block file of checkout success one page using preference and define your own method to get the order Id.

          Try this:

          In your custom module's di.xml file add this:



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCheckoutBlockOnepageSuccess" type="VendorModuleBlockOnepageSuccess" />
          </config>


          Now create Success.php Block file in Folder VendorModuleBlockOnepage



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleBlockOnepage;

          use MagentoCustomerModelContext;
          use MagentoSalesModelOrder;

          /**
          * One page checkout success page
          *
          * @api
          * @since 100.0.2
          */
          class Success extends MagentoFrameworkViewElementTemplate

          /**
          * @var MagentoCheckoutModelSession
          */
          protected $_checkoutSession;

          /**
          * @var MagentoSalesModelOrderConfig
          */
          protected $_orderConfig;

          /**
          * @var MagentoFrameworkAppHttpContext
          */
          protected $httpContext;

          /**
          * @param MagentoFrameworkViewElementTemplateContext $context
          * @param MagentoCheckoutModelSession $checkoutSession
          * @param MagentoSalesModelOrderConfig $orderConfig
          * @param MagentoFrameworkAppHttpContext $httpContext
          * @param array $data
          */
          public function __construct(
          MagentoFrameworkViewElementTemplateContext $context,
          MagentoCheckoutModelSession $checkoutSession,
          MagentoSalesModelOrderConfig $orderConfig,
          MagentoFrameworkAppHttpContext $httpContext,
          array $data = []
          )
          parent::__construct($context, $data);
          $this->_checkoutSession = $checkoutSession;
          $this->_orderConfig = $orderConfig;
          $this->_isScopePrivate = true;
          $this->httpContext = $httpContext;


          /**
          * Render additional order information lines and return result html
          *
          * @return string
          */
          public function getAdditionalInfoHtml()

          return $this->_layout->renderElement('order.success.additional.info');


          /**
          * Initialize data and prepare it for output
          *
          * @return string
          */
          protected function _beforeToHtml()

          $this->prepareBlockData();
          return parent::_beforeToHtml();


          /**
          * Prepares block data
          *
          * @return void
          */
          protected function prepareBlockData()

          $order = $this->_checkoutSession->getLastRealOrder();

          $this->addData(
          [
          'is_order_visible' => $this->isVisible($order),
          'view_order_url' => $this->getUrl(
          'sales/order/view/',
          ['order_id' => $order->getEntityId()]
          ),
          'print_url' => $this->getUrl(
          'sales/order/print',
          ['order_id' => $order->getEntityId()]
          ),
          'can_print_order' => $this->isVisible($order),
          'can_view_order' => $this->canViewOrder($order),
          'order_id' => $order->getIncrementId()
          ]
          );


          /**
          * Is order visible
          *
          * @param Order $order
          * @return bool
          */
          protected function isVisible(Order $order)

          return !in_array(
          $order->getStatus(),
          $this->_orderConfig->getInvisibleOnFrontStatuses()
          );


          /**
          * Can view order
          *
          * @param Order $order
          * @return bool
          */
          protected function canViewOrder(Order $order)

          return $this->httpContext->getValue(Context::CONTEXT_AUTH)
          && $this->isVisible($order);


          /**
          * @return string
          * @since 100.2.0
          */
          public function getContinueUrl()

          return $this->_storeManager->getStore()->getBaseUrl();



          /**
          * @return string
          * getOrigId
          */
          public function getOrigId()

          return $this->_checkoutSession->getLastRealOrder()->getEntityId();





          Then you can now get the Order Id(Entity Id) in your .phtml template like this:



          $block->getOrigId()






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago

























          answered 4 hours ago









          magefmsmagefms

          2,4562426




          2,4562426












          • $block->getOrderId() will get me entity id ? whats the difference between $block->getViewOrderUrl()->getId() and $block->getOrderId()

            – summu
            4 hours ago











          • Yeah, the $block->getOrderId() will get the entity id. Actually, I am not sure with the $block->getViewOrderUrl()->getId() but you can check.

            – magefms
            4 hours ago












          • $block->getOrderId() gave me increment id not entitty id, /sales/order/view/order_id/173569/ , this 173569 is entity id which output of $block->getViewOrderUrl() , i just wanted 173569

            – summu
            2 hours ago












          • I think better if you would override the Block file for checkout success.phtml file and create your own method to get order Id

            – magefms
            1 hour ago






          • 1





            @summu updated my answer please check

            – magefms
            1 hour ago


















          • $block->getOrderId() will get me entity id ? whats the difference between $block->getViewOrderUrl()->getId() and $block->getOrderId()

            – summu
            4 hours ago











          • Yeah, the $block->getOrderId() will get the entity id. Actually, I am not sure with the $block->getViewOrderUrl()->getId() but you can check.

            – magefms
            4 hours ago












          • $block->getOrderId() gave me increment id not entitty id, /sales/order/view/order_id/173569/ , this 173569 is entity id which output of $block->getViewOrderUrl() , i just wanted 173569

            – summu
            2 hours ago












          • I think better if you would override the Block file for checkout success.phtml file and create your own method to get order Id

            – magefms
            1 hour ago






          • 1





            @summu updated my answer please check

            – magefms
            1 hour ago

















          $block->getOrderId() will get me entity id ? whats the difference between $block->getViewOrderUrl()->getId() and $block->getOrderId()

          – summu
          4 hours ago





          $block->getOrderId() will get me entity id ? whats the difference between $block->getViewOrderUrl()->getId() and $block->getOrderId()

          – summu
          4 hours ago













          Yeah, the $block->getOrderId() will get the entity id. Actually, I am not sure with the $block->getViewOrderUrl()->getId() but you can check.

          – magefms
          4 hours ago






          Yeah, the $block->getOrderId() will get the entity id. Actually, I am not sure with the $block->getViewOrderUrl()->getId() but you can check.

          – magefms
          4 hours ago














          $block->getOrderId() gave me increment id not entitty id, /sales/order/view/order_id/173569/ , this 173569 is entity id which output of $block->getViewOrderUrl() , i just wanted 173569

          – summu
          2 hours ago






          $block->getOrderId() gave me increment id not entitty id, /sales/order/view/order_id/173569/ , this 173569 is entity id which output of $block->getViewOrderUrl() , i just wanted 173569

          – summu
          2 hours ago














          I think better if you would override the Block file for checkout success.phtml file and create your own method to get order Id

          – magefms
          1 hour ago





          I think better if you would override the Block file for checkout success.phtml file and create your own method to get order Id

          – magefms
          1 hour ago




          1




          1





          @summu updated my answer please check

          – magefms
          1 hour ago






          @summu updated my answer please check

          – magefms
          1 hour ago


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269043%2fhow-to-get-entity-idorder-id-in-success-phtml%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480