Magento 2 offers an abandoned carts report that lists all registered customers who have abandoned carts which is yet to be expired. The abandoned carts report grid lists the below details:
- Customer Name
- Email Address
- Number of products in the cart
- Cart Subtotal
- Applied Coupon
- Date created
- Date of the last update
- IP address

Stepwise method to add company column in abandoned carts report in Magento 2:
- Create registration.php file at app\code\Vendor\Module directory
1234<?phpuse \Magento\Framework\Component\ComponentRegistrar;ComponentRegistrar::register(ComponentRegistrar::MODULE, ‘Vendor_Module’, __DIR__);
- Create module.xml file at app\code\Vendor\Module\etc directory
12345<?xml version=“1.0”?><config xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”xsi:noNamespaceSchemaLocation=“urn:magento:framework:Module/etc/module.xsd”><module name=“Vendor_Module” setup_version=“1.0.0”/></config>
- Create di.xml file at app\code\Vendor\Module\etc\adminhtml directory
1234<?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=“Magento\Reports\Block\Adminhtml\Shopcart\Abandoned\Grid” type=“Vendor\Module\Block\Adminhtml\Shopcart\Abandoned\Grid” /></config>
- Create Grid.php at app\code\Vendor\Module\Block\Adminhtml\Shopcart\Abandoned directory
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218<?phpnamespace Vendor\Module\Block\Adminhtml\Shopcart\Abandoned;class Grid extends \Magento\Reports\Block\Adminhtml\Grid\Shopcart{protected $_quotesFactory;public function __construct(\Magento\Backend\Block\Template\Context $context,\Magento\Backend\Helper\Data $backendHelper,\Magento\Reports\Model\ResourceModel\Quote\CollectionFactory $quotesFactory,array $data = []) {$this->_quotesFactory = $quotesFactory;parent::__construct($context, $backendHelper, $data);}protected function _construct(){parent::_construct();$this->setId(‘gridAbandoned’);}protected function _prepareCollection(){$collection = $this->_quotesFactory->create();$filter = $this->getParam($this->getVarNameFilter(), []);if ($filter) {$filter = base64_decode($filter);parse_str(urldecode($filter), $data);}if (!empty($data)) {$collection->prepareForAbandonedReport($this->_storeIds, $data);} else {$collection->prepareForAbandonedReport($this->_storeIds);}$this->setCollection($collection);parent::_prepareCollection();if ($this->_isExport) {$collection->setPageSize(null);}$this->getCollection()->resolveCustomerNames();return $this;}protected function _addColumnFilterToCollection($column){$field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();$skip = [‘subtotal’, ‘customer_name’, ’email’];if (in_array($field, $skip)) {return $this;}parent::_addColumnFilterToCollection($column);return $this;}protected function _prepareColumns(){$this->addColumn(‘customer_name’,[‘header’ => __(‘Customer’),‘index’ => ‘customer_name’,‘sortable’ => false,‘header_css_class’ => ‘col-name’,‘column_css_class’ => ‘col-name’]);$this->addColumn(’email’,[‘header’ => __(‘Email’),‘index’ => ’email’,‘sortable’ => false,‘header_css_class’ => ‘col-email’,‘column_css_class’ => ‘col-email’]);//add Company field$this->addColumn(‘company’,[‘header’ => __(‘Company’),‘index’ => ‘company’,‘sortable’ => false,‘renderer’ => \Cozmot\Register\Block\Adminhtml\Grid\Column\Renderer\Company::class,‘header_css_class’ => ‘col-company’,‘column_css_class’ => ‘col-company’]);$this->addColumn(‘items_count’,[‘header’ => __(‘Products’),‘index’ => ‘items_count’,‘sortable’ => false,‘type’ => ‘number’,‘header_css_class’ => ‘col-number’,‘column_css_class’ => ‘col-number’]);$this->addColumn(‘items_qty’,[‘header’ => __(‘Quantity’),‘index’ => ‘items_qty’,‘sortable’ => false,‘type’ => ‘number’,‘header_css_class’ => ‘col-qty’,‘column_css_class’ => ‘col-qty’]);if ($this->getRequest()->getParam(‘website’)) {$storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam(‘website’))->getStoreIds();} elseif ($this->getRequest()->getParam(‘group’)) {$storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam(‘group’))->getStoreIds();} elseif ($this->getRequest()->getParam(‘store’)) {$storeIds = [(int)$this->getRequest()->getParam(‘store’)];} else {$storeIds = [];}$this->setStoreIds($storeIds);$currencyCode = $this->getCurrentCurrencyCode();$this->addColumn(‘subtotal’,[‘header’ => __(‘Subtotal’),‘type’ => ‘currency’,‘currency_code’ => $currencyCode,‘index’ => ‘subtotal’,‘sortable’ => false,‘renderer’ => \Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency::class,‘rate’ => $this->getRate($currencyCode),‘header_css_class’ => ‘col-subtotal’,‘column_css_class’ => ‘col-subtotal’]);$this->addColumn(‘coupon_code’,[‘header’ => __(‘Applied Coupon’),‘index’ => ‘coupon_code’,‘sortable’ => false,‘header_css_class’ => ‘col-coupon’,‘column_css_class’ => ‘col-coupon’]);$this->addColumn(‘created_at’,[‘header’ => __(‘Created’),‘type’ => ‘datetime’,‘index’ => ‘created_at’,‘filter_index’ => ‘main_table.created_at’,‘sortable’ => false,‘header_css_class’ => ‘col-created’,‘column_css_class’ => ‘col-created’]);$this->addColumn(‘updated_at’,[‘header’ => __(‘Updated’),‘type’ => ‘datetime’,‘index’ => ‘updated_at’,‘filter_index’ => ‘main_table.updated_at’,‘sortable’ => false,‘header_css_class’ => ‘col-updated’,‘column_css_class’ => ‘col-updated’]);$this->addColumn(‘remote_ip’,[‘header’ => __(‘IP Address’),‘index’ => ‘remote_ip’,‘sortable’ => false,‘header_css_class’ => ‘col-ip’,‘column_css_class’ => ‘col-ip’]);$this->addExportType(‘*/*/exportAbandonedCsv’, __(‘CSV’));$this->addExportType(‘*/*/exportAbandonedExcel’, __(‘Excel XML’));return parent::_prepareColumns();}/*** Get rows url** @param \Magento\Framework\DataObject $row** @return string*/public function getRowUrl($row){return $this->getUrl(‘customer/index/edit’, [‘id’ => $row->getCustomerId(), ‘active_tab’ => ‘cart’]);}}
- Create Company.php at app\code\Vendor\Module\Block\Adminhtml\Grid\Column\Renderer and add below code
123456789101112131415161718192021222324252627282930313233<?phpnamespace Vendor\Module\Block\Adminhtml\Grid\Column\Renderer;use Magento\Backend\Block\Context;use Magento\Customer\Model\CustomerFactory;use Magento\Framework\DataObject;class Company extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer{protected $customerFactory;public function __construct(Context $context, array $data = array(),CustomerFactory $customerFactory) {$this->customerFactory = $customerFactory;parent::__construct($context, $data);}public function render(DataObject $row){$customerFactory = $this->customerFactory->create();$customerId = $row->getcustomer_id();$customer = $customerFactory->load($customerId);$Addresses = $customer->getAddresses();foreach ($Addresses as $address){return $address->getData(‘company’);}}}
