|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +namespace ActiveCampaign\Customer\Block\Adminhtml\System\Config\Form\Field; |
| 5 | + |
| 6 | +use Magento\Framework\View\Element\Html\Select; |
| 7 | + |
| 8 | +class CustomerOptionColumn extends Select |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @var \Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory |
| 12 | + */ |
| 13 | + private $attrCollection; |
| 14 | + |
| 15 | + public function __construct( |
| 16 | + \Magento\Framework\View\Element\Context $context, |
| 17 | + \Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory $collectionFactory, |
| 18 | + array $data = [] |
| 19 | + ) { |
| 20 | + parent::__construct($context,$data); |
| 21 | + $this->attrCollection = $collectionFactory; |
| 22 | + } |
| 23 | + public function setInputName($value) |
| 24 | + { |
| 25 | + return $this->setName($value); |
| 26 | + } |
| 27 | + |
| 28 | + public function setInputId($value) |
| 29 | + { |
| 30 | + return $this->setId($value); |
| 31 | + |
| 32 | + } |
| 33 | + public function _toHtml(): string |
| 34 | + { |
| 35 | + if (!$this->getOptions()) { |
| 36 | + $this->setOptions($this->getSourceOptions()); |
| 37 | + } |
| 38 | + return parent::_toHtml(); |
| 39 | + } |
| 40 | + |
| 41 | + private function getSourceOptions(): array |
| 42 | + { |
| 43 | + $addressFields = [ |
| 44 | + ['label' => 'Default Shipping ZIP', 'value' => 'shipping__postcode'], |
| 45 | + ['label' => 'Default Shipping City', 'value' => 'shipping__city'], |
| 46 | + ['label' => 'Default Shipping Telephone', 'value' => 'shipping__telephone'], |
| 47 | + ['label' => 'Default Shipping Region', 'value' => 'shipping__region'], |
| 48 | + ['label' => 'Default Shipping Company', 'value' => 'shipping__company'], |
| 49 | + ['label' => 'Default Billing ZIP', 'value' => 'billing__postcode'], |
| 50 | + ['label' => 'Default Billing City', 'value' => 'billing__city'], |
| 51 | + ['label' => 'Default Billing Telephone', 'value' => 'billing__telephone'], |
| 52 | + ['label' => 'Default Billing Region', 'value' => 'billing__region'], |
| 53 | + ['label' => 'Default Billing Company', 'value' => 'billing__company'], |
| 54 | + ]; |
| 55 | + return array_merge($addressFields, $this->getCustomerAtt()); |
| 56 | + |
| 57 | + } |
| 58 | + |
| 59 | + protected function getCustomerAtt() |
| 60 | + { |
| 61 | + $ret = []; |
| 62 | + $collection = $this->attrCollection->create(); |
| 63 | + |
| 64 | + foreach ($collection as $item) { |
| 65 | + $ret[] = ['label' => $item->getFrontendLabel(), 'value' => $item->getAttributeCode() ]; |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + return $ret; |
| 70 | + } |
| 71 | +} |
0 commit comments