Skip to content

Commit d7ebdef

Browse files
committed
MAGETWO-61628: [Backport] - Match products by rule in admin not working - for 2.0
1 parent 4ac2029 commit d7ebdef

File tree

2 files changed

+47
-6
lines changed
  • app/code/Magento
    • Catalog/Controller/Adminhtml/Category
    • Eav/Model/Entity/Attribute/Source

2 files changed

+47
-6
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Catalog\Controller\Adminhtml\Category;
7+
use Magento\Store\Model\StoreManagerInterface;
78

89
/**
910
* Class Save
@@ -25,6 +26,11 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
2526
*/
2627
protected $layoutFactory;
2728

29+
/**
30+
* @var StoreManagerInterface
31+
*/
32+
private $storeManager;
33+
2834
/**
2935
* Constructor
3036
*
@@ -43,6 +49,10 @@ public function __construct(
4349
$this->resultRawFactory = $resultRawFactory;
4450
$this->resultJsonFactory = $resultJsonFactory;
4551
$this->layoutFactory = $layoutFactory;
52+
53+
if ($this->storeManager == null){
54+
$this->storeManager = $this->_objectManager->get(StoreManagerInterface::class);
55+
}
4656
}
4757

4858
/**
@@ -82,6 +92,8 @@ public function execute()
8292
}
8393

8494
$storeId = $this->getRequest()->getParam('store');
95+
$store = $this->storeManager->getStore($storeId);
96+
$this->storeManager->setCurrentStore($store->getCode());
8597
$refreshTree = false;
8698
$data = $this->getRequest()->getPostValue();
8799
if ($data) {

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

Lines changed: 35 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,11 @@ class Table extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
2427
*/
2528
protected $_attrOptionFactory;
2629

30+
/**
31+
* @var StoreManagerInterface
32+
*/
33+
private $storeManager;
34+
2735
/**
2836
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
2937
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
@@ -47,31 +55,52 @@ public function __construct(
4755
public function getAllOptions($withEmpty = true, $defaultValues = false)
4856
{
4957
$storeId = $this->getAttribute()->getStoreId();
58+
if ($storeId === null) {
59+
$storeId = $this->getStoreManager()->getStore()->getId();
60+
}
5061
if (!is_array($this->_options)) {
5162
$this->_options = [];
5263
}
5364
if (!is_array($this->_optionsDefault)) {
5465
$this->_optionsDefault = [];
5566
}
56-
if (!isset($this->_options[$storeId])) {
67+
$attributeId = $this->getAttribute()->getId();
68+
if (!isset($this->_options[$storeId][$attributeId])) {
5769
$collection = $this->_attrOptionCollectionFactory->create()->setPositionOrder(
5870
'asc'
5971
)->setAttributeFilter(
60-
$this->getAttribute()->getId()
72+
$attributeId
6173
)->setStoreFilter(
62-
$this->getAttribute()->getStoreId()
74+
$storeId
6375
)->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');
6678
}
67-
$options = $defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId];
79+
$options = $defaultValues
80+
? $this->_optionsDefault[$storeId][$attributeId]
81+
: $this->_options[$storeId][$attributeId];
6882
if ($withEmpty) {
6983
$options = $this->addEmptyOption($options);
7084
}
7185

7286
return $options;
7387
}
7488

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+
75104
/**
76105
* Retrieve Option values array by ids
77106
*

0 commit comments

Comments
 (0)