![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Cnc/Customer/Block/Widget/ |
<?php namespace Cnc\Customer\Block\Widget; use Magento\Customer\Api\CustomerMetadataInterface; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Customer\Api\Data\OptionInterface; /** * Class Select * * Additional widget to display different attributes. * * @method setAttributeCode($attributeCode) * @method getAttributeCode() * @method setCurrentOption($currentOption) * @method getCurrentOption() */ class Select extends \Magento\Customer\Block\Widget\AbstractWidget { /** * @var \Magento\Customer\Model\Session */ protected $_customerSession; /** * @var CustomerRepositoryInterface */ protected $customerRepository; /** * Create an instance of the Gender widget * * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Customer\Helper\Address $addressHelper * @param CustomerMetadataInterface $customerMetadata * @param CustomerRepositoryInterface $customerRepository * @param \Magento\Customer\Model\Session $customerSession * @param array $data */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Helper\Address $addressHelper, CustomerMetadataInterface $customerMetadata, CustomerRepositoryInterface $customerRepository, \Magento\Customer\Model\Session $customerSession, array $data = [] ) { $this->_customerSession = $customerSession; $this->customerRepository = $customerRepository; parent::__construct($context, $addressHelper, $customerMetadata, $data); $this->_isScopePrivate = true; } /** * Initialize block * * @return void */ public function _construct() { parent::_construct(); $this->setTemplate('Cnc_Customer::widget/select.phtml'); } /** * Check if attribute enabled in system * * @return bool */ public function isEnabled() { return $this->_getAttribute($this->getAttributeCode()) ? (bool)$this->_getAttribute($this->getAttributeCode())->isVisible() : false; } /** * Check if attribute marked as required * * @return bool */ public function isRequired() { return $this->_getAttribute($this->getAttributeCode()) ? (bool)$this->_getAttribute($this->getAttributeCode())->isRequired() : false; } /** * Retrieve store attribute label * * @param string $attributeCode * * @return string */ public function getStoreLabel($attributeCode) { $attribute = $this->_getAttribute($attributeCode); return $attribute ? __($attribute->getStoreLabel()) : ''; } /** * Get current customer from session * * @return CustomerInterface */ public function getCustomer() { return $this->customerRepository->getById($this->_customerSession->getCustomerId()); } /** * Returns options from attribute * * @return OptionInterface[] */ public function getOptions() { $options = $this->_getAttribute($this->getAttributeCode())->getOptions(); if ($this->getAttributeCode() == 'cnc_industry_sector' && count($options)) { foreach ($options as $option) { if ($option->getValue() == '') { $option->setLabel(__('Choose a business activity')); break; } } } return $options; } }