cancel
Showing results for 
Search instead for 
Did you mean: 

How to add textbox and dropdown to overridden admin shipment create page?

How to add textbox and dropdown to overridden admin shipment create page?

I have created a custom shipping module for Magento 2.1, which implements 3rd party APIs.

Which is working fine for domestic shipments.

For International shipments its required to send product’s HS codes along with product information.

This API provides a way to obtain HS codes by sending products category or short descriptions.

My shipping module creates shipments using this API at ‘sales_order_shipment_save_after’ Magento event.

As I said earlier Its working fine for domestic shipments.

However, for International shipments since its required to send HS codes, I came up with a solution to select from a HS code dropdown where it pulls codes from API when the user types in product category or product description in category text box under ‘Items to Ship’ table row of ‘New Shipment’ admin page.

enter image description here

To implement this method, I have overridden Magento’s default ‘New Shipment Page’ and was able to modify ‘Items to Ship’ section by listing ‘Product Category’ and ‘HS Code’ columns in that table.

Now I need to know how to add a textbox under ‘Category’ column to type in texts and a dropdown under ‘HS Code’ column which is populated by AJAX call.

I also need to know how to implement validations for those fields when ‘Submit Shipment’ button is clicked.

And finally how to capture those fields values from my model for further processing.

Your suggestions are highly appreciated Smiley Happy

Thank you,

/www_mg1/app/code/[vender]/[modelname]/Block/Adminhtml/Overrite/Create/Items.php

<?phpnamespace [vender]\[modelname]\Block\Adminhtml\Override\Create;
class Items extends \Magento\Shipping\Block\Adminhtml\Create\Items{

}

Path: /mg1/app/code/[vender]/[modulename]/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.xs d">
<preference 
for="Magento\Shipping\Block\Adminhtml\Create\Items" 
type="[vender]\[modulename]\Block\Adminhtml\Override\Create\Items"/>
</config>

/www_mg1/app/code/[vendername] /[modulename] /view/adminhtml/layout/adminhtml_order_shipment_new.xml

                <?xml version="1.0"?>
                <!--
                /**
                * Copyright © 2016 Magento. All rights reserved.
                * See COPYING.txt for license details.
                */
                -->
                <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
                <body>
                <referenceContainer name="admin.scope.col.wrap" htmlClass="admin__old" /> <!-- ToDo UI: remove this wrapper with old styles removal. The class name "admin__old" is for tests only, we shouldn't use it in any way -->
                <referenceContainer name="content">
                <block class="Magento\Shipping\Block\Adminhtml\Create" name="sales_shipment_create">
                    <block class="Magento\Shipping\Block\Adminhtml\Create\Form" name="form" template="create/form.phtml">
                        <block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
                        <block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
                        <block class="Magento\Shipping\Block\Adminhtml\Create\Items" name="order_items" template="create/items.phtml">
                            <block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" as="default" template="Magento_Shipping::create/items/renderer/default.phtml"/>
                            <block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
                            <block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>
                            <block class="Magento\Framework\View\Element\Text\ListText" name="order_item_extra_info"/>
                            <container name="submit_before" label="Submit Before"/>
                            <container name="submit_after" label="Submit After"/>
                        </block>
                        <block class="Magento\Shipping\Block\Adminhtml\Order\Tracking" name="shipment_tracking" template="order/tracking.phtml"/>
                        <block class="Magento\Shipping\Block\Adminhtml\Order\Packaging" name="shipment_packaging" template="Magento_Shipping::order/packaging/popup.phtml"/>
                    </block>
                </block>
                </referenceContainer>
                </body>
                </page>

/www_mg1/app/code/[vender] /[modulename] /view/adminhtml/templates/create/items.phtml

            <section class="admin__page-section">
                <div class="admin__page-section-title">
                    <span class="title"><?php /* @escapeNotVerified */ echo __('Items to Ship') ?></span>
                </div>
                <div class="admin__table-wrapper">
                    <table class="data-table admin__table-primary order-shipment-table">
                        <thead>
                            <tr class="headings">
                                <th class="col-product"><span><?php /* @escapeNotVerified */ echo __('Product') ?></span></th>
                                <th class="col-ordered-qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></th>                                <th class="col-qty<?php if ($block->isShipmentRegular()): ?> last<?php endif; ?>">
                                    <span><?php /* @escapeNotVerified */ echo __('Qty to Ship') ?></span>
                                </th>
                                <?php if (!$block->canShipPartiallyItem()): ?>
                                <th class="col-ship last"><span><?php /* @escapeNotVerified */ echo __('Ship') ?></span></th>
                                <?php endif; ?>
                                <th class="col-ordered-qty"><span><?php /* @escapeNotVerified */ echo __('Category') ?></span></th>
                                <th class="col-ordered-qty"><span><?php /* @escapeNotVerified */ echo __('HS Code') ?></span></th>                                        
                            </tr>
                        </thead>
                        <?php $_items = $block->getShipment()->getAllItems() ?>
                        <?php $_i = 0; foreach ($_items as $_item): if ($_item->getOrderItem()->getIsVirtual() || $_item->getOrderItem()->getParentItem()): continue; endif; $_i++ ?>
...
...