How to add product stock qty column and render stock info on backend order create grid












1















I need to show stock qty column on order create grid in order to place an order easily when generating an order on admin side.



TO DOs are :



1) Add Stock quantity column (Done)



2) Render the value of stock quantity



Could you help me out how to do this?




app/[Vendor]/[Module-Name]/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="MagentoSalesBlockAdminhtmlOrderCreateSearchGrid" type="[Vendor][Module-Name]BlockAdminhtmlGrid" />
</config>



appcode [Vendor][Module-Name]BlockAdminhtml




<?php
/**
* Created by
* Date: 13/05/2015
* Time: 5:02 PM
*/
namespace [Vendor][Module-Name]BlockAdminhtml;
use MagentoFrameworkViewElementTemplate;
class Grid extends MagentoSalesBlockAdminhtmlOrderCreateSearchGrid
{

protected function _prepareColumns()
{
$this->addColumn(
'entity_id',
[
'header' => __('ID'),
'sortable' => true,
'header_css_class' => 'col-id',
'column_css_class' => 'col-id',
'index' => 'entity_id'
]
);
$this->addColumn(
'name',
[
'header' => __('Product'),
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererProduct',
'index' => 'name'
]
);
$this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']);
$this->addColumn(
'price',
[
'header' => __('Price'),
'column_css_class' => 'price',
'type' => 'currency',
'currency_code' => $this->getStore()->getCurrentCurrencyCode(),
'rate' => $this->getStore()->getBaseCurrency()->getRate($this->getStore()->getCurrentCurrencyCode()),
'index' => 'price',
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererPrice'
]
);

$this->addColumn(
'in_products',
[
'header' => __('Select'),
'type' => 'checkbox',
'name' => 'in_products',
'values' => $this->_getSelectedProducts(),
'index' => 'entity_id',
'sortable' => false,
'header_css_class' => 'col-select',
'column_css_class' => 'col-select'
]
);

/*20171031 add show qty */
$this->addColumn(
'remain_qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Quantity'),
'renderer' => '[Vendor][Module-Name]BlockAdminhtmlGridRendererRemain',
//'values' => 3,
'name' => 'remain_qty',
'inline_css' => 'remain_qty',
'type' => 'text',
'validate_class' => 'validate-number',
'index' => 3
]
);
/*20171031 add show qty */

$this->addColumn(
'qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Qty to Order'),
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererQty',
'name' => 'qty',
'inline_css' => 'qty',
'type' => 'input',
'validate_class' => 'validate-number',
'index' => 'qty'
]
);

return parent::_prepareColumns();
}
}


At this moment, using my above codes, i can see empty custom column at order create grid like this :



enter image description here



To render stock information, i make a block inherited from stock repository. But i don't know how to do.




appcode[Vendor][module-Name]BlockAdminhtmlGridRendererRemian.php




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

/**
* Renderer for Remain Qty field in sales create new order search grid
*
* @author
*/
class Remain extends MagentoFrameworkViewElementTemplate,
// MagentoBackendBlockWidgetGridColumnRendererText
{
/**
* Type config
*
* @var MagentoCatalogModelProductTypesConfigInterface
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
array $data =
)
{
$this->_stockItemRepository = $stockItemRepository;
parent::__construct($context, $data);
}

public function getStockItem($productId)
{
return $this->_stockItemRepository->get($productId);
}
}


/**
* Returns whether this qty field must be inactive
*
* @param MagentoFrameworkDataObject $row
* @return bool
*/
protected function _isInactive($row)
{
return $this->typeConfig->isProductSet($row->getTypeId());
}

/**
* Render product qty field
*
* @param MagentoFrameworkDataObject $row
* @return string
*/
public function render(MagentoFrameworkDataObject $row)
{
// what should i insert that?
}
}









share|improve this question
















bumped to the homepage by Community 7 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • have you find solution for your answer?

    – LucScu
    Jan 22 '18 at 10:08
















1















I need to show stock qty column on order create grid in order to place an order easily when generating an order on admin side.



TO DOs are :



1) Add Stock quantity column (Done)



2) Render the value of stock quantity



Could you help me out how to do this?




app/[Vendor]/[Module-Name]/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="MagentoSalesBlockAdminhtmlOrderCreateSearchGrid" type="[Vendor][Module-Name]BlockAdminhtmlGrid" />
</config>



appcode [Vendor][Module-Name]BlockAdminhtml




<?php
/**
* Created by
* Date: 13/05/2015
* Time: 5:02 PM
*/
namespace [Vendor][Module-Name]BlockAdminhtml;
use MagentoFrameworkViewElementTemplate;
class Grid extends MagentoSalesBlockAdminhtmlOrderCreateSearchGrid
{

protected function _prepareColumns()
{
$this->addColumn(
'entity_id',
[
'header' => __('ID'),
'sortable' => true,
'header_css_class' => 'col-id',
'column_css_class' => 'col-id',
'index' => 'entity_id'
]
);
$this->addColumn(
'name',
[
'header' => __('Product'),
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererProduct',
'index' => 'name'
]
);
$this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']);
$this->addColumn(
'price',
[
'header' => __('Price'),
'column_css_class' => 'price',
'type' => 'currency',
'currency_code' => $this->getStore()->getCurrentCurrencyCode(),
'rate' => $this->getStore()->getBaseCurrency()->getRate($this->getStore()->getCurrentCurrencyCode()),
'index' => 'price',
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererPrice'
]
);

$this->addColumn(
'in_products',
[
'header' => __('Select'),
'type' => 'checkbox',
'name' => 'in_products',
'values' => $this->_getSelectedProducts(),
'index' => 'entity_id',
'sortable' => false,
'header_css_class' => 'col-select',
'column_css_class' => 'col-select'
]
);

/*20171031 add show qty */
$this->addColumn(
'remain_qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Quantity'),
'renderer' => '[Vendor][Module-Name]BlockAdminhtmlGridRendererRemain',
//'values' => 3,
'name' => 'remain_qty',
'inline_css' => 'remain_qty',
'type' => 'text',
'validate_class' => 'validate-number',
'index' => 3
]
);
/*20171031 add show qty */

$this->addColumn(
'qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Qty to Order'),
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererQty',
'name' => 'qty',
'inline_css' => 'qty',
'type' => 'input',
'validate_class' => 'validate-number',
'index' => 'qty'
]
);

return parent::_prepareColumns();
}
}


At this moment, using my above codes, i can see empty custom column at order create grid like this :



enter image description here



To render stock information, i make a block inherited from stock repository. But i don't know how to do.




appcode[Vendor][module-Name]BlockAdminhtmlGridRendererRemian.php




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

/**
* Renderer for Remain Qty field in sales create new order search grid
*
* @author
*/
class Remain extends MagentoFrameworkViewElementTemplate,
// MagentoBackendBlockWidgetGridColumnRendererText
{
/**
* Type config
*
* @var MagentoCatalogModelProductTypesConfigInterface
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
array $data =
)
{
$this->_stockItemRepository = $stockItemRepository;
parent::__construct($context, $data);
}

public function getStockItem($productId)
{
return $this->_stockItemRepository->get($productId);
}
}


/**
* Returns whether this qty field must be inactive
*
* @param MagentoFrameworkDataObject $row
* @return bool
*/
protected function _isInactive($row)
{
return $this->typeConfig->isProductSet($row->getTypeId());
}

/**
* Render product qty field
*
* @param MagentoFrameworkDataObject $row
* @return string
*/
public function render(MagentoFrameworkDataObject $row)
{
// what should i insert that?
}
}









share|improve this question
















bumped to the homepage by Community 7 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • have you find solution for your answer?

    – LucScu
    Jan 22 '18 at 10:08














1












1








1








I need to show stock qty column on order create grid in order to place an order easily when generating an order on admin side.



TO DOs are :



1) Add Stock quantity column (Done)



2) Render the value of stock quantity



Could you help me out how to do this?




app/[Vendor]/[Module-Name]/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="MagentoSalesBlockAdminhtmlOrderCreateSearchGrid" type="[Vendor][Module-Name]BlockAdminhtmlGrid" />
</config>



appcode [Vendor][Module-Name]BlockAdminhtml




<?php
/**
* Created by
* Date: 13/05/2015
* Time: 5:02 PM
*/
namespace [Vendor][Module-Name]BlockAdminhtml;
use MagentoFrameworkViewElementTemplate;
class Grid extends MagentoSalesBlockAdminhtmlOrderCreateSearchGrid
{

protected function _prepareColumns()
{
$this->addColumn(
'entity_id',
[
'header' => __('ID'),
'sortable' => true,
'header_css_class' => 'col-id',
'column_css_class' => 'col-id',
'index' => 'entity_id'
]
);
$this->addColumn(
'name',
[
'header' => __('Product'),
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererProduct',
'index' => 'name'
]
);
$this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']);
$this->addColumn(
'price',
[
'header' => __('Price'),
'column_css_class' => 'price',
'type' => 'currency',
'currency_code' => $this->getStore()->getCurrentCurrencyCode(),
'rate' => $this->getStore()->getBaseCurrency()->getRate($this->getStore()->getCurrentCurrencyCode()),
'index' => 'price',
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererPrice'
]
);

$this->addColumn(
'in_products',
[
'header' => __('Select'),
'type' => 'checkbox',
'name' => 'in_products',
'values' => $this->_getSelectedProducts(),
'index' => 'entity_id',
'sortable' => false,
'header_css_class' => 'col-select',
'column_css_class' => 'col-select'
]
);

/*20171031 add show qty */
$this->addColumn(
'remain_qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Quantity'),
'renderer' => '[Vendor][Module-Name]BlockAdminhtmlGridRendererRemain',
//'values' => 3,
'name' => 'remain_qty',
'inline_css' => 'remain_qty',
'type' => 'text',
'validate_class' => 'validate-number',
'index' => 3
]
);
/*20171031 add show qty */

$this->addColumn(
'qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Qty to Order'),
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererQty',
'name' => 'qty',
'inline_css' => 'qty',
'type' => 'input',
'validate_class' => 'validate-number',
'index' => 'qty'
]
);

return parent::_prepareColumns();
}
}


At this moment, using my above codes, i can see empty custom column at order create grid like this :



enter image description here



To render stock information, i make a block inherited from stock repository. But i don't know how to do.




appcode[Vendor][module-Name]BlockAdminhtmlGridRendererRemian.php




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

/**
* Renderer for Remain Qty field in sales create new order search grid
*
* @author
*/
class Remain extends MagentoFrameworkViewElementTemplate,
// MagentoBackendBlockWidgetGridColumnRendererText
{
/**
* Type config
*
* @var MagentoCatalogModelProductTypesConfigInterface
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
array $data =
)
{
$this->_stockItemRepository = $stockItemRepository;
parent::__construct($context, $data);
}

public function getStockItem($productId)
{
return $this->_stockItemRepository->get($productId);
}
}


/**
* Returns whether this qty field must be inactive
*
* @param MagentoFrameworkDataObject $row
* @return bool
*/
protected function _isInactive($row)
{
return $this->typeConfig->isProductSet($row->getTypeId());
}

/**
* Render product qty field
*
* @param MagentoFrameworkDataObject $row
* @return string
*/
public function render(MagentoFrameworkDataObject $row)
{
// what should i insert that?
}
}









share|improve this question
















I need to show stock qty column on order create grid in order to place an order easily when generating an order on admin side.



TO DOs are :



1) Add Stock quantity column (Done)



2) Render the value of stock quantity



Could you help me out how to do this?




app/[Vendor]/[Module-Name]/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="MagentoSalesBlockAdminhtmlOrderCreateSearchGrid" type="[Vendor][Module-Name]BlockAdminhtmlGrid" />
</config>



appcode [Vendor][Module-Name]BlockAdminhtml




<?php
/**
* Created by
* Date: 13/05/2015
* Time: 5:02 PM
*/
namespace [Vendor][Module-Name]BlockAdminhtml;
use MagentoFrameworkViewElementTemplate;
class Grid extends MagentoSalesBlockAdminhtmlOrderCreateSearchGrid
{

protected function _prepareColumns()
{
$this->addColumn(
'entity_id',
[
'header' => __('ID'),
'sortable' => true,
'header_css_class' => 'col-id',
'column_css_class' => 'col-id',
'index' => 'entity_id'
]
);
$this->addColumn(
'name',
[
'header' => __('Product'),
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererProduct',
'index' => 'name'
]
);
$this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']);
$this->addColumn(
'price',
[
'header' => __('Price'),
'column_css_class' => 'price',
'type' => 'currency',
'currency_code' => $this->getStore()->getCurrentCurrencyCode(),
'rate' => $this->getStore()->getBaseCurrency()->getRate($this->getStore()->getCurrentCurrencyCode()),
'index' => 'price',
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererPrice'
]
);

$this->addColumn(
'in_products',
[
'header' => __('Select'),
'type' => 'checkbox',
'name' => 'in_products',
'values' => $this->_getSelectedProducts(),
'index' => 'entity_id',
'sortable' => false,
'header_css_class' => 'col-select',
'column_css_class' => 'col-select'
]
);

/*20171031 add show qty */
$this->addColumn(
'remain_qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Quantity'),
'renderer' => '[Vendor][Module-Name]BlockAdminhtmlGridRendererRemain',
//'values' => 3,
'name' => 'remain_qty',
'inline_css' => 'remain_qty',
'type' => 'text',
'validate_class' => 'validate-number',
'index' => 3
]
);
/*20171031 add show qty */

$this->addColumn(
'qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Qty to Order'),
'renderer' => 'MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererQty',
'name' => 'qty',
'inline_css' => 'qty',
'type' => 'input',
'validate_class' => 'validate-number',
'index' => 'qty'
]
);

return parent::_prepareColumns();
}
}


At this moment, using my above codes, i can see empty custom column at order create grid like this :



enter image description here



To render stock information, i make a block inherited from stock repository. But i don't know how to do.




appcode[Vendor][module-Name]BlockAdminhtmlGridRendererRemian.php




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

/**
* Renderer for Remain Qty field in sales create new order search grid
*
* @author
*/
class Remain extends MagentoFrameworkViewElementTemplate,
// MagentoBackendBlockWidgetGridColumnRendererText
{
/**
* Type config
*
* @var MagentoCatalogModelProductTypesConfigInterface
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
array $data =
)
{
$this->_stockItemRepository = $stockItemRepository;
parent::__construct($context, $data);
}

public function getStockItem($productId)
{
return $this->_stockItemRepository->get($productId);
}
}


/**
* Returns whether this qty field must be inactive
*
* @param MagentoFrameworkDataObject $row
* @return bool
*/
protected function _isInactive($row)
{
return $this->typeConfig->isProductSet($row->getTypeId());
}

/**
* Render product qty field
*
* @param MagentoFrameworkDataObject $row
* @return string
*/
public function render(MagentoFrameworkDataObject $row)
{
// what should i insert that?
}
}






magento2 adminhtml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 1 '17 at 6:25









Teja Bhagavan Kollepara

2,94841847




2,94841847










asked Oct 31 '17 at 21:59









3CE3CE

364214




364214





bumped to the homepage by Community 7 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 7 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • have you find solution for your answer?

    – LucScu
    Jan 22 '18 at 10:08



















  • have you find solution for your answer?

    – LucScu
    Jan 22 '18 at 10:08

















have you find solution for your answer?

– LucScu
Jan 22 '18 at 10:08





have you find solution for your answer?

– LucScu
Jan 22 '18 at 10:08










1 Answer
1






active

oldest

votes


















0














<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

/**
* Renderer for Remain Qty field in sales create new order search grid
*
* @author
*/
class Remain extends MagentoBackendBlockWidgetGridColumnRendererText
{
/**
* Type config
*
* @var MagentoCatalogModelProductTypesConfigInterface
*/
public function __construct(
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
)
{
$this->_stockItemRepository = $stockItemRepository;

}
public function getStockItem($productId)
{
return $this->_stockItemRepository->get($productId)->getQty();
}


/**
* Returns whether this qty field must be inactive
*
* @param MagentoFrameworkDataObject $row
* @return bool
*/
protected function _isInactive($row)
{
return $this->typeConfig->isProductSet($row->getTypeId());
}

/**
* Render product qty field
*
* @param MagentoFrameworkDataObject $row
* @return string
*/
public function render(MagentoFrameworkDataObject $row)
{
$id = $row->getData('entity_id');
$availQty = $this->getStockItem($id);
return $availQty;
}
}


You should try this






share|improve this answer























    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%2f199513%2fhow-to-add-product-stock-qty-column-and-render-stock-info-on-backend-order-creat%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









    0














    <?php
    /**
    * Copyright © 2013-2017 Magento, Inc. All rights reserved.
    * See COPYING.txt for license details.
    */
    namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

    /**
    * Renderer for Remain Qty field in sales create new order search grid
    *
    * @author
    */
    class Remain extends MagentoBackendBlockWidgetGridColumnRendererText
    {
    /**
    * Type config
    *
    * @var MagentoCatalogModelProductTypesConfigInterface
    */
    public function __construct(
    MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
    )
    {
    $this->_stockItemRepository = $stockItemRepository;

    }
    public function getStockItem($productId)
    {
    return $this->_stockItemRepository->get($productId)->getQty();
    }


    /**
    * Returns whether this qty field must be inactive
    *
    * @param MagentoFrameworkDataObject $row
    * @return bool
    */
    protected function _isInactive($row)
    {
    return $this->typeConfig->isProductSet($row->getTypeId());
    }

    /**
    * Render product qty field
    *
    * @param MagentoFrameworkDataObject $row
    * @return string
    */
    public function render(MagentoFrameworkDataObject $row)
    {
    $id = $row->getData('entity_id');
    $availQty = $this->getStockItem($id);
    return $availQty;
    }
    }


    You should try this






    share|improve this answer




























      0














      <?php
      /**
      * Copyright © 2013-2017 Magento, Inc. All rights reserved.
      * See COPYING.txt for license details.
      */
      namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

      /**
      * Renderer for Remain Qty field in sales create new order search grid
      *
      * @author
      */
      class Remain extends MagentoBackendBlockWidgetGridColumnRendererText
      {
      /**
      * Type config
      *
      * @var MagentoCatalogModelProductTypesConfigInterface
      */
      public function __construct(
      MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
      )
      {
      $this->_stockItemRepository = $stockItemRepository;

      }
      public function getStockItem($productId)
      {
      return $this->_stockItemRepository->get($productId)->getQty();
      }


      /**
      * Returns whether this qty field must be inactive
      *
      * @param MagentoFrameworkDataObject $row
      * @return bool
      */
      protected function _isInactive($row)
      {
      return $this->typeConfig->isProductSet($row->getTypeId());
      }

      /**
      * Render product qty field
      *
      * @param MagentoFrameworkDataObject $row
      * @return string
      */
      public function render(MagentoFrameworkDataObject $row)
      {
      $id = $row->getData('entity_id');
      $availQty = $this->getStockItem($id);
      return $availQty;
      }
      }


      You should try this






      share|improve this answer


























        0












        0








        0







        <?php
        /**
        * Copyright © 2013-2017 Magento, Inc. All rights reserved.
        * See COPYING.txt for license details.
        */
        namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

        /**
        * Renderer for Remain Qty field in sales create new order search grid
        *
        * @author
        */
        class Remain extends MagentoBackendBlockWidgetGridColumnRendererText
        {
        /**
        * Type config
        *
        * @var MagentoCatalogModelProductTypesConfigInterface
        */
        public function __construct(
        MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
        )
        {
        $this->_stockItemRepository = $stockItemRepository;

        }
        public function getStockItem($productId)
        {
        return $this->_stockItemRepository->get($productId)->getQty();
        }


        /**
        * Returns whether this qty field must be inactive
        *
        * @param MagentoFrameworkDataObject $row
        * @return bool
        */
        protected function _isInactive($row)
        {
        return $this->typeConfig->isProductSet($row->getTypeId());
        }

        /**
        * Render product qty field
        *
        * @param MagentoFrameworkDataObject $row
        * @return string
        */
        public function render(MagentoFrameworkDataObject $row)
        {
        $id = $row->getData('entity_id');
        $availQty = $this->getStockItem($id);
        return $availQty;
        }
        }


        You should try this






        share|improve this answer













        <?php
        /**
        * Copyright © 2013-2017 Magento, Inc. All rights reserved.
        * See COPYING.txt for license details.
        */
        namespace [Vendor][module-Name]BlockAdminhtmlGridRenderer;

        /**
        * Renderer for Remain Qty field in sales create new order search grid
        *
        * @author
        */
        class Remain extends MagentoBackendBlockWidgetGridColumnRendererText
        {
        /**
        * Type config
        *
        * @var MagentoCatalogModelProductTypesConfigInterface
        */
        public function __construct(
        MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
        )
        {
        $this->_stockItemRepository = $stockItemRepository;

        }
        public function getStockItem($productId)
        {
        return $this->_stockItemRepository->get($productId)->getQty();
        }


        /**
        * Returns whether this qty field must be inactive
        *
        * @param MagentoFrameworkDataObject $row
        * @return bool
        */
        protected function _isInactive($row)
        {
        return $this->typeConfig->isProductSet($row->getTypeId());
        }

        /**
        * Render product qty field
        *
        * @param MagentoFrameworkDataObject $row
        * @return string
        */
        public function render(MagentoFrameworkDataObject $row)
        {
        $id = $row->getData('entity_id');
        $availQty = $this->getStockItem($id);
        return $availQty;
        }
        }


        You should try this







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 28 '18 at 13:15









        Jagriti JoshiJagriti Joshi

        474




        474






























            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%2f199513%2fhow-to-add-product-stock-qty-column-and-render-stock-info-on-backend-order-creat%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

            Magento 2 controller redirect on button click in phtml file

            Polycentropodidae