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