0

How to override

Magento\Sales\Controller\Adminhtml\Order\Create\Save.php

the file can you please help me out?

1 Answer 1

2

app/code/StackExchange/ControllerOverride/composer.json

{
    "name": "stackexchange/controlleroverride",
    "description": "StackExchange ControllerOverride",
    "require": {
      "php": "~5.6.0|7.0.2|~7.0.6",
      "magento/module-store": "0.74.0-beta4",
      "magento/module-theme": "0.74.0-beta4",
      "magento/module-widget": "0.74.0-beta4",
      "magento/module-backend": "0.74.0-beta4",
      "magento/module-catalog": "0.74.0-beta4",
      "magento/module-email": "0.74.0-beta4",
      "magento/module-ui": "0.74.0-beta4",
      "magento/module-variable": "0.74.0-beta4",
      "magento/module-media-storage": "0.74.0-beta4",
      "magento/framework": "0.74.0-beta4",
      "magento/magento-composer-installer": "*"
    },
    "type": "magento2-module",
    "version": "0.74.0-beta4",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "extra": {
        "map": [
            [
                "*",
                "StackExchange/ControllerOverride"
            ]
        ]
    }
}

app/code/StackExchange/ControllerOverride/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'StackExchange_ControllerOverride',
    __DIR__
);

app/code/StackExchange/ControllerOverride/etc/di.xml

<?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="Magento\Sales\Controller\Adminhtml\Order\Create\Save" type="StackExchange\ControllerOverride\Controller\Magento\Sales\Adminhtml\Order\Create\Save" />

</config>

app/code/StackExchange/ControllerOverride/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="StackExchange_ControllerOverride" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Backend"/>
             <module name="Magento_Sales"/>
            <module name="Magento_Quote"/>
            <module name="Magento_Checkout"/>
            <module name="Magento_Cms"/>
        </sequence>
    </module>
</config>

app/code/StackExchange/ControllerOverride/Controller/Magento/Sales/Adminhtml/Order/Create/Save.php

<?php

namespace StackExchange\ControllerOverride\Controller\Magento\Sales\Adminhtml\Order\Create;


class Save extends \Magento\Sales\Controller\Adminhtml\Order\Create\Save
{


}

EDIT

If you want order ID after place order, you can use observer as per below tutorial.

https://meetanshi.com/blog/get-order-data-from-magento-2-sales_order_place_after-event/

12
  • thanks for quick replay and i will check now , let u know. Commented Nov 6, 2018 at 9:48
  • i am checking and after that i will surely accept it give me 10 mins time to check. Commented Nov 6, 2018 at 9:51
  • Hi @kishan i have overrided but giving below error when i am trying to place an order from admin Order saving error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '187185177-1' for key 'SALES_ORDER_INCREMENT_ID_STORE_ID', query was: INSERT INTO sales_order (state, status Commented Nov 6, 2018 at 10:03
  • I have overrided but giving below error when i am trying to place an order from admin throwing saving error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '187185177-1' for key 'SALES_ORDER_INCREMENT_ID_STORE_ID', query was: INSERT INTO sales_order (state, status Commented Nov 6, 2018 at 10:12
  • Your answer is not working kindly check your side please Commented Nov 6, 2018 at 10:27

Your Answer

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

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