5
5
*/
6
6
namespace Magento \Eav \Model \Entity \Attribute \Source ;
7
7
8
+ use Magento \Framework \App \ObjectManager ;
9
+ use Magento \Store \Model \StoreManagerInterface ;
10
+
8
11
class Table extends \Magento \Eav \Model \Entity \Attribute \Source \AbstractSource
9
12
{
10
13
/**
@@ -24,6 +27,13 @@ class Table extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
24
27
*/
25
28
protected $ _attrOptionFactory ;
26
29
30
+ /**
31
+ * Store manager interface.
32
+ *
33
+ * @var StoreManagerInterface
34
+ */
35
+ private $ storeManager ;
36
+
27
37
/**
28
38
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
29
39
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
@@ -47,31 +57,53 @@ public function __construct(
47
57
public function getAllOptions ($ withEmpty = true , $ defaultValues = false )
48
58
{
49
59
$ storeId = $ this ->getAttribute ()->getStoreId ();
60
+ if ($ storeId === null ) {
61
+ $ storeId = $ this ->getStoreManager ()->getStore ()->getId ();
62
+ }
50
63
if (!is_array ($ this ->_options )) {
51
64
$ this ->_options = [];
52
65
}
53
66
if (!is_array ($ this ->_optionsDefault )) {
54
67
$ this ->_optionsDefault = [];
55
68
}
56
- if (!isset ($ this ->_options [$ storeId ])) {
69
+
70
+ $ attributeId = $ this ->getAttribute ()->getId ();
71
+ if (!isset ($ this ->_options [$ storeId ][$ attributeId ])) {
57
72
$ collection = $ this ->_attrOptionCollectionFactory ->create ()->setPositionOrder (
58
73
'asc '
59
74
)->setAttributeFilter (
60
- $ this -> getAttribute ()-> getId ()
75
+ $ attributeId
61
76
)->setStoreFilter (
62
- $ this -> getAttribute ()-> getStoreId ()
77
+ $ storeId
63
78
)->load ();
64
- $ this ->_options [$ storeId ] = $ collection ->toOptionArray ();
65
- $ this ->_optionsDefault [$ storeId ] = $ collection ->toOptionArray ('default_value ' );
79
+ $ this ->_options [$ storeId ][ $ attributeId ] = $ collection ->toOptionArray ();
80
+ $ this ->_optionsDefault [$ storeId ][ $ attributeId ] = $ collection ->toOptionArray ('default_value ' );
66
81
}
67
- $ options = $ defaultValues ? $ this ->_optionsDefault [$ storeId ] : $ this ->_options [$ storeId ];
82
+ $ options = $ defaultValues
83
+ ? $ this ->_optionsDefault [$ storeId ][$ attributeId ]
84
+ : $ this ->_options [$ storeId ][$ attributeId ];
68
85
if ($ withEmpty ) {
69
86
$ options = $ this ->addEmptyOption ($ options );
70
87
}
71
88
72
89
return $ options ;
73
90
}
74
91
92
+ /**
93
+ * Get StoreManager dependency.
94
+ *
95
+ * @return StoreManagerInterface
96
+ * @deprecated
97
+ */
98
+ private function getStoreManager ()
99
+ {
100
+ if ($ this ->storeManager === null ) {
101
+ $ this ->storeManager = ObjectManager::getInstance ()->get (StoreManagerInterface::class);
102
+ }
103
+
104
+ return $ this ->storeManager ;
105
+ }
106
+
75
107
/**
76
108
* Retrieve Option values array by ids
77
109
*
0 commit comments