1

I have created a custom module for show the custom order status in the admin. It's working fine and displaying the static.

Now, I want to save the status value in the custom table with the current order ID. Please see the below image: enter image description here

Below is my module code and files path:

app/code/Vendor/MyModuleName/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_MyModule',
    __DIR__
);

app/code/Vendor/MyModuleName/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\Block\Adminhtml\Order\View\Info" type="Vendor\MyModuleName\Block\Adminhtml\Order\View\Info"/>
</config>

app/code/Vendor/MyModuleName/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_MyModuleName" setup_version="2.0.0">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>

app/code/Vendor/MyModuleName/view/adminhtml/layout/sales_order_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="order_info">
            <action method="setTemplate">
                <argument name="template" translate="true" xsi:type="string">order/view/info.phtml</argument>
            </action>
        </referenceBlock>
        <referenceBlock name="content" after="order_totals">
            <block class="Vendor\MyModuleName\Block\Adminhtml\Order\View\Custom" name="sales_order_view_custom" template="order/view/custom.phtml" />
        </referenceBlock>
    </body>
</page>

app/code/Vendor/MyModuleName/view/adminhtml/templates/order/view/custom.phtml

<section class="admin__page-section">
    <div class="admin__page-section-title">
        <span class="title"><?php /* @escapeNotVerified */ echo __('Custom Dropdown') ?></span>
    </div>
    <div class="admin__field">
        <label for="custom_status" class="admin__field-label"><?php /* @escapeNotVerified */ echo __('Custom Status') ?></label>
        <div class="admin__field-control">
            <select name="custom[status]" id="custom_status" class="admin__control-select">
                <?php $customStatus = array('1' => 'Custom Option 1', '2' => 'Custom Option 2');
                    foreach ($customStatus as $_code => $_label): ?>
                    <option value="<?php /* @escapeNotVerified */ echo $_code ?>"><?php /* @escapeNotVerified */ echo $_label ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div class="order-history-comments-actions">
        <button title="Submit Comment" type="button" class="action-default scalable action-save action-secondary" data-ui-id="widget-button-0">
            <span>Submit Status</span>
        </button>
    </div>
</section>

app/code/Vendor/MyModuleName/Block/Adminhtml/Order/View/Custom.php

<?php
namespace Vendor\MyModuleName\Block\Adminhtml\Order\View;

class Custom extends \Magento\Backend\Block\Template
{

}

How I can save the dropdown value in the below table and get the value in respect of current order id below is custom_table structure:

enter image description here

Please help out how I can achieve this? Thanks

  • Did you find any way to do this? I also have a similar issue. Please provide an answer to this if you have found one. – Abey Josey Dec 6 '17 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.