![]() 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/cartforge.co/vendor/magento/module-customer/Model/Customer/Attribute/Source/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Customer\Model\Customer\Attribute\Source; /** * Customer store attribute source * * @author Magento Core Team <[email protected]> */ class Store extends \Magento\Eav\Model\Entity\Attribute\Source\Table { /** * @var \Magento\Store\Model\System\Store */ protected $_store; /** * @var \Magento\Store\Model\ResourceModel\Store\CollectionFactory */ protected $_storesFactory; /** * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory * @param \Magento\Store\Model\System\Store $store * @param \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storesFactory */ public function __construct( \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory, \Magento\Store\Model\System\Store $store, \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storesFactory ) { parent::__construct($attrOptionCollectionFactory, $attrOptionFactory); $this->_store = $store; $this->_storesFactory = $storesFactory; } /** * @inheritdoc */ public function getAllOptions($withEmpty = true, $defaultValues = false) { if (!$this->_options) { $collection = $this->_createStoresCollection(); if ('store_id' == $this->getAttribute()->getAttributeCode()) { $collection->setWithoutDefaultFilter(); } $this->_options = $this->_store->getStoreValuesForForm(); if ('created_in' == $this->getAttribute()->getAttributeCode()) { array_unshift($this->_options, ['value' => '0', 'label' => __('Admin')]); } } return $this->_options; } /** * @param string $value * @return array|string */ public function getOptionText($value) { if (!$value) { $value = '0'; } $isMultiple = false; if (strpos($value, ',') !== false) { $isMultiple = true; $value = explode(',', $value); } if (!$this->_options) { $collection = $this->_createStoresCollection(); if ('store_id' == $this->getAttribute()->getAttributeCode()) { $collection->setWithoutDefaultFilter(); } $this->_options = $collection->load()->toOptionArray(); if ('created_in' == $this->getAttribute()->getAttributeCode()) { array_unshift($this->_options, ['value' => '0', 'label' => __('Admin')]); } } if ($isMultiple) { $values = []; foreach ($value as $val) { $values[] = $this->_options[$val]; } return $values; } else { return $this->_options[$value]; } } /** * @return \Magento\Store\Model\ResourceModel\Store\Collection */ protected function _createStoresCollection() { return $this->_storesFactory->create(); } }