InsideDarkWeb.com

Magento 2.3 adding column to inventory_source

I’ve added a new column to inventory_source successfully and it’s working, here is the tutorial I’ve followed.

The issue is the data saved to the database is not showed in the form, the field appear empty but the data is in the database.

The Steps I’ve done are:

  1. Created extension_attributes

  2. Created event to save the data

  3. Created inventory_source_form.xml to view the field

    <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
        <fieldset name="general" sortOrder="10">
            <field name="branch_erp_id" formElement="input" sortOrder="25">
                <settings>
                    <validation>
                        <rule name="validate-number" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>number</dataType>
                    <label translate="true">Branch ERP Id</label>
                </settings>
            </field>
        </fieldset>
    </form>```
    
    

The di.xml file:

<type name="MagentoInventoryApiApiSourceRepositoryInterface">
    <plugin name="plugin_source_save" type="vendormodulePluginInventorySourceSource"/>
</type>

The plugin file Source.php:

<?php

namespace vendormodulePluginInventorySource;

use MagentoInventoryApiApiSourceRepositoryInterface;
use MagentoInventoryApiApiDataSourceInterface;
use MagentoInventoryApiApiDataSourceSearchResultsInterface;
use MagentoInventoryApiApiDataSourceExtensionFactory;
use MagentoInventoryApiApiDataSourceExtensionInterfaceFactory;


class Source
{
    const FIELD_NAME = 'branch_erp_id';

    protected $extensionFactory;
    protected $sourceFactory;

    public function __construct(SourceExtensionInterfaceFactory $extensionFactory)
    {
        $this->extensionFactory = $extensionFactory;
    }


    public function afterGet(SourceRepositoryInterface $subject, SourceInterface $source)
    {
        $sourceBranchId = $source->getData(self::FIELD_NAME);
        $extensionAttributes = $source->getExtensionAttributes();
        $extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create();
        $extensionAttributes->setBranchErpId($sourceBranchId);
        $source->setExtensionAttributes($extensionAttributes);

        return $source;
    }

    public function afterGetList(SourceRepositoryInterface $subject, SourceSearchResultsInterface $result)
    {
        $products = [];
        $sources = $result->getItems();

        foreach ($sources as $source) {
            $sourceBranchId = $source->getData(self::FIELD_NAME);
            $extensionAttributes = $source->getExtensionAttributes();
            $extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create();
            $extensionAttributes->setBranchErpId($sourceBranchId);
            $source->setExtensionAttributes($extensionAttributes);
            $products[] = $source;
        }
        $result->setItems($products);
        return $result;
    }
}

Magento Asked by Khaled Omara on October 2, 2021

0 Answers

Add your own answers!

Related Questions

Get userid of the admin logged in magento 2 helper

1  Asked on February 12, 2021 by fahad-bashir

   

Product saving problem in admin control panel

1  Asked on February 12, 2021 by venkatesha

 

Print Address / Shipping Label For Magento 2

0  Asked on February 12, 2021 by naveen-sama

     

are the two codes same?

1  Asked on February 11, 2021 by hong-thng

   

Create custom Attributes in Customer Form in magento 1.9

1  Asked on February 6, 2021 by maiitsyuj

 

Magento2 Language Character Problem

0  Asked on February 5, 2021 by stifboy

   

Magento 1.9.2.4 Add Cart To Header

2  Asked on February 5, 2021 by ks6814

         

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.