Hello Magento Pals,
Last time we learned How to Write translatable strings in Email, PHTML, UiComponents, js, etc. in Magento 2.
Today, we are going to learn how to remove decimals from the quantity product grid in Magento admin. First, If you want to remove quantity decimal, then you can do it via this code.
Create file app\code\VENDOR\EXTENSION\module.xml file
<module name="VENDOR_EXTENSION" setup_version="1.0.0"> <sequence> <module name="Magento_CatalogInventory"/> </sequence> </module>
Create app\code\VENDOR\EXTENSION\view\adminhtml\ui_component\product_listing.xml
<?xml version="1.0" encoding="UTF-8"?> <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <columns name="product_columns" class="Magento\Catalog\Ui\Component\Listing\Columns"> <column name="qty" class="Vendor\Module\Ui\Component\Listing\Columns\QtyFile"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="filter" xsi:type="string">textRange</item> <item name="add_field" xsi:type="boolean">true</item> <item name="label" xsi:type="string" translate="true">Quantity</item> <item name="sortOrder" xsi:type="number">75</item> </item> </argument> </column> </columns> </listing>
Create app\code\VENDOR\EXTENSION\Ui\Component\Listing\Columns\QtyFile.php
<?php namespace VENDOR\EXTENSION\Ui\Component\Listing\Columns; class QtyFile extends \Magento\Ui\Component\Listing\Columns\Column { /** * Prepare Data Source * * @param array $dataSource * @return array */ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { $fieldName = $this->getData('name'); foreach ($dataSource['data']['items'] as & $item) { if (isset($item[$fieldName])) { $item[$fieldName] = (int)$item[$fieldName]; } } } return $dataSource; } }
and that’s it- Now, You can remove decimal from quantity in product grid in Magento admin. The code strings above are just for the reference only you can customize it and implement it for your use as per your needs. If you face any problem while during so then contact our support team.
Lastly, feel free to comment below and let us know what you think about this article. Also, you can share this with your Magento colleagues and partners.
Happy Coding folks ? & If you haven’t checked our #MageheartDays Sale for Magento Lovers, Check all lovely offers from MageComp here?
In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…
In the world of business, understanding financial metrics is crucial for making informed decisions and…
Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…
In this era, businesses are always on the lookout for ways to engage with their…
Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…
E-commerce has transformed the way consumers shop for products and services and interact with businesses.…