I have extension installed in my project which converts guest customer to customer,
and i want to display this customer is "Guest to Customer" in my custom column in customer grid,
Something like that in this picture.
Thanks in advance.
-
Which extension you have used for guest to customer?– Rahul BarotJul 15, 2022 at 6:30
-
GuestToCustomer extension of BSS Commerce Co. bsscommerce.com/….– Afzel ArshadJul 15, 2022 at 13:54
1 Answer
1. Register column with custom column class
app/code/Acme/StackExchange/view/adminhtml/ui_component/sales_order_grid.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="sales_order_columns">
<column name="convert_to_customer" class="Acme\StackExchange\Ui\Component\Listing\Column\ConvertToCustomer" sortOrder="90">
<settings>
<label translate="true">Convert to Customer</label>
<bodyTmpl>ui/grid/cells/html</bodyTmpl>
<filter>false</filter>
<sortable>false</sortable>
</settings>
</column>
</columns>
</listing>
2. Create Column processor
app/code/Acme/StackExchange/Ui/Component/Listing/Column/ConvertToCustomer.php
<?php
declare(strict_types=1);
namespace Acme\StackExchange\Ui\Component\Listing\Column;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
class ConvertToCustomer extends Column
{
protected UrlInterface $urlBuilder;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
) {
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* @inheritDoc
*/
public function prepareDataSource(array $dataSource): array
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$content = ' ';
if (empty($item['customer_id'])) {
$url = $this->urlBuilder->getUrl('path/to/url', [
'order_id' => $item['entity_id'],
]);
$title = __('Guest To Customer');
$content = <<<HTML
<a target="_blank" class="product_link" href="{$url}">{$title}</a>
HTML;
}
$item[$this->getName()] = $content;
}
}
return $dataSource;
}
}
-
-
-
Here is my question link, can you take a look? magento.stackexchange.com/questions/357972/… Jul 19, 2022 at 13:30