I want to hide or remove Purchase Point column from sales order grid in backend using custom module, how do i do this?
Magento – Hide or remove column from sales order grid
layoutlayout-updatemagento2sales-ordersales-order-grid
Related Solutions
join is happening twice in process of exporting, to avoid it, add checking in registry:
use Magento\Framework\Message\ManagerInterface as MessageManager;
use Magento\Framework\Registry;
use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as SalesOrderGridCollection;
class AddColumnsSalesOrderGridCollection
{
private $messageManager;
private $collection;
private $registry;
public function __construct(MessageManager $messageManager,
SalesOrderGridCollection $collection,
Registry $registry
)
{
$this->messageManager = $messageManager;
$this->collection = $collection;
$this->registry = $registry;
}
public function aroundGetReport(
\Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $subject,
\Closure $proceed,
$requestName
)
{
$result = $proceed($requestName);
if ($requestName == 'sales_order_grid_data_source') {
if ($result instanceof $this->collection
) {
if (is_null($this->registry->registry('shipment_joined'))) {
$select = $this->collection->getSelect();
$select->join(
["sst" => "sales_shipment_track"],
'main_table.entity_id = sst.entity_id',
'sst.track_number'
)
->distinct();
$this->registry->register('shipment_joined', true);
}
}
}
return $this->collection;
}
}
You can Try this its work for me.
Add sales_order_view.xml file in your custom module Packagename/Modulename/view/adminhtml/layout and remove column as per your requirement.
<block class="Magento\Sales\Block\Adminhtml\Order\View\Items" name="order_items" template="Magento_Sales::order/view/items.phtml">
<arguments>
<argument name="columns" xsi:type="array">
<item name="product" xsi:type="string" translate="true">Product</item>
<item name="status" xsi:type="string" translate="true">Item Status</item>
<!-- <item name="price-original" xsi:type="string" translate="true">Original Price</item> -->
<item name="price" xsi:type="string" translate="true">Price</item>
<item name="ordered-qty" xsi:type="string" translate="true">Qty</item>
<item name="subtotal" xsi:type="string" translate="true">Subtotal</item>
<item name="tax-amount" xsi:type="string" translate="true">Tax Amount</item>
<item name="tax-percent" xsi:type="string" translate="true">Tax Percent</item>
<item name="discont" xsi:type="string" translate="true">Discount Amount</item>
<item name="total" xsi:type="string" translate="true">Row Total</item>
</argument>
</arguments>
<block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" name="default_order_items_renderer" template="Magento_Sales::order/view/items/renderer/default.phtml">
<arguments>
<argument name="columns" xsi:type="array">
<item name="product" xsi:type="string" translate="false">col-product</item>
<item name="status" xsi:type="string" translate="false">col-status</item>
<!-- <item name="price-original" xsi:type="string" translate="false">col-price-original</item> -->
<item name="price" xsi:type="string" translate="false">col-price</item>
<item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
<item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
<item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
<item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
<item name="discont" xsi:type="string" translate="false">col-discont</item>
<item name="total" xsi:type="string" translate="false">col-total</item>
</argument>
</arguments>
</block>
<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"/>
</block>
Best Answer
You need to override the layout for sales order grid, in order to do this create the sales order grid layout file inside your custom module
To hide element in this grid you have to set
componentDisabled
item argument to true , you'll also need to disable purchase point filter if you want to hide purchase point column. So the sales_order_grid.xml will look like this: