forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountry.php
78 lines (69 loc) · 2.31 KB
/
Country.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Model\StoreManagerInterface;
/**
* Customer country attribute source
*/
class Country extends \Magento\Eav\Model\Entity\Attribute\Source\Table
{
/**
* @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory
*/
protected $_countriesFactory;
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
* @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countriesFactory
*/
public function __construct(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory,
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countriesFactory
) {
$this->_countriesFactory = $countriesFactory;
parent::__construct($attrOptionCollectionFactory, $attrOptionFactory);
}
/**
* @inheritdoc
*/
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
if (!$this->_options) {
$this->_options = $this->_createCountriesCollection()->loadByStore(
$this->getStoreManager()->getStore()->getId()
)->toOptionArray();
}
return $this->_options;
}
/**
* Return new countries object
*
* @return \Magento\Directory\Model\ResourceModel\Country\Collection
*/
protected function _createCountriesCollection()
{
return $this->_countriesFactory->create();
}
/**
* Retrieve Store Manager
*
* @deprecated 101.0.0
* @return StoreManagerInterface
*/
private function getStoreManager()
{
if (!$this->storeManager) {
$this->storeManager = ObjectManager::getInstance()->get(StoreManagerInterface::class);
}
return $this->storeManager;
}
}