40 lines
1022 B
PHP
40 lines
1022 B
PHP
<?php
|
|
|
|
namespace Stemcell\Customer\Ui\Component\DataProvider;
|
|
|
|
use Magento\Framework\Data\OptionSourceInterface;
|
|
use Magento\Customer\Model\ResourceModel\Customer\Collection;
|
|
|
|
class VendorOption implements OptionSourceInterface
|
|
{
|
|
private Collection $collection;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected array $customerTree;
|
|
|
|
public function __construct(
|
|
Collection $collection
|
|
) {
|
|
$this->collection = $collection;
|
|
}
|
|
|
|
public function toOptionArray()
|
|
{
|
|
|
|
$collection = $this->collection->addFieldToSelect('firstname');
|
|
foreach ($collection as $customer) {
|
|
$customerId = $customer->getEntityId();
|
|
if (!isset($customerById[$customerId])) {
|
|
$customerById[$customerId] = [
|
|
'value' => $customerId
|
|
];
|
|
}
|
|
$customerById[$customerId]['label'] = $customer->getFirstname();
|
|
}
|
|
$this->customerTree = $customerById;
|
|
return $this->customerTree;
|
|
}
|
|
}
|