Skip to content

Commit c8fe101

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-57615' into 2.1.8-develop-pr19
2 parents edb8cd4 + 896dbf8 commit c8fe101

File tree

7 files changed

+565
-74
lines changed

7 files changed

+565
-74
lines changed

app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Eav\Model\Entity\Attribute\Source;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Store\Model\StoreManagerInterface;
10+
811
class Table extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
912
{
1013
/**
@@ -24,6 +27,13 @@ class Table extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
2427
*/
2528
protected $_attrOptionFactory;
2629

30+
/**
31+
* Store manager interface.
32+
*
33+
* @var StoreManagerInterface
34+
*/
35+
private $storeManager;
36+
2737
/**
2838
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
2939
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
@@ -47,31 +57,53 @@ public function __construct(
4757
public function getAllOptions($withEmpty = true, $defaultValues = false)
4858
{
4959
$storeId = $this->getAttribute()->getStoreId();
60+
if ($storeId === null) {
61+
$storeId = $this->getStoreManager()->getStore()->getId();
62+
}
5063
if (!is_array($this->_options)) {
5164
$this->_options = [];
5265
}
5366
if (!is_array($this->_optionsDefault)) {
5467
$this->_optionsDefault = [];
5568
}
56-
if (!isset($this->_options[$storeId])) {
69+
70+
$attributeId = $this->getAttribute()->getId();
71+
if (!isset($this->_options[$storeId][$attributeId])) {
5772
$collection = $this->_attrOptionCollectionFactory->create()->setPositionOrder(
5873
'asc'
5974
)->setAttributeFilter(
60-
$this->getAttribute()->getId()
75+
$attributeId
6176
)->setStoreFilter(
62-
$this->getAttribute()->getStoreId()
77+
$storeId
6378
)->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');
6681
}
67-
$options = $defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId];
82+
$options = $defaultValues
83+
? $this->_optionsDefault[$storeId][$attributeId]
84+
: $this->_options[$storeId][$attributeId];
6885
if ($withEmpty) {
6986
$options = $this->addEmptyOption($options);
7087
}
7188

7289
return $options;
7390
}
7491

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+
75107
/**
76108
* Retrieve Option values array by ids
77109
*

0 commit comments

Comments
 (0)