Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Model/Config/Source/CustomerAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © Intelipost. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Intelipost\Push\Model\Config\Source;

use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory;
use Magento\Framework\Data\OptionSourceInterface;

class CustomerAttribute implements OptionSourceInterface
{
/**
* @var CollectionFactory
*/
private $collectionFactory;

/**
* @param CollectionFactory $collectionFactory
*/
public function __construct(CollectionFactory $collectionFactory)
{
$this->collectionFactory = $collectionFactory;
}

/**
* @return array
*/
public function toOptionArray(): array
{
$collection = $this->collectionFactory
->create()
->setEntityTypeFilter(CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER)
->addOrder('frontend_label', 'ASC');

$result = [
[
'value' => '',
'label' => __('Select CPF attribute')
]
];

foreach ($collection as $item) {
$result[] = [
'value' => $item->getAttributeCode(),
'label' => $item->getFrontendLabel()
];
}

return $result;
}
}
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<group id="attributes" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Attributes</label>
<field id="federal_tax_payer_id" translate="label comment" type="select" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">
<source_model>Intelipost\Quote\Model\Config\Source\Attribute</source_model>
<source_model>Intelipost\Push\Model\Config\Source\CustomerAttribute</source_model>
<label>Federal tax payer id</label>
<comment>Select CPF attribute</comment>
</field>
Expand Down