Skip to content

Commit 8e256d4

Browse files
committed
Merge pull request #510 from magento-south/BUGS
[South+Firedrakes] Bugfixes
2 parents ab051bf + 523877a commit 8e256d4

File tree

15 files changed

+413
-70
lines changed

15 files changed

+413
-70
lines changed

app/code/Magento/Catalog/view/adminhtml/web/js/options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ define([
137137
}
138138
};
139139

140-
Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption, {}, true));
140+
if ($('add_new_option_button')) {
141+
Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption, {}, true));
142+
}
141143
$('manage-options-panel').on('click', '.delete-option', function (event) {
142144
attributeOption.remove(event);
143145
});

app/code/Magento/Cms/Model/Page/DataProvider.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ public function getData()
6161
if (isset($this->loadedData)) {
6262
return $this->loadedData;
6363
}
64-
foreach ($this->collection->getAllIds() as $pageId) {
65-
/** @var \Magento\Cms\Model\Page $page */
66-
$page = $this->collection->getNewEmptyItem();
67-
/** Load every record separately to make sure the list of associated stores is available */
68-
$this->loadedData[$pageId] = $page->load($pageId)->getData();
64+
$items = $this->collection->getItems();
65+
/** @var $page \Magento\Cms\Model\Page */
66+
foreach ($items as $page) {
67+
$this->loadedData[$page->getId()] = $page->getData();
6968
}
7069

7170
$data = $this->dataPersistor->get('cms_page');

app/code/Magento/Cms/Model/ResourceModel/AbstractCollection.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Cms\Model\ResourceModel;
77

8+
use Magento\Store\Model\Store;
9+
810
/**
911
* Abstract collection of CMS pages and blocks
1012
*/
@@ -61,24 +63,30 @@ protected function performAfterLoad($tableName, $linkField)
6163
$connection = $this->getConnection();
6264
$select = $connection->select()->from(['cms_entity_store' => $this->getTable($tableName)])
6365
->where('cms_entity_store.' . $linkField . ' IN (?)', $linkedIds);
64-
$result = $connection->fetchPairs($select);
66+
$result = $connection->fetchAll($select);
6567
if ($result) {
68+
$storesData = [];
69+
foreach ($result as $storeData) {
70+
$storesData[$storeData[$linkField]][] = $storeData['store_id'];
71+
}
72+
6673
foreach ($this as $item) {
6774
$linkedId = $item->getData($linkField);
68-
if (!isset($result[$linkedId])) {
75+
if (!isset($storesData[$linkedId])) {
6976
continue;
7077
}
71-
if ($result[$linkedId] == 0) {
78+
$storeIdKey = array_search(Store::DEFAULT_STORE_ID, $storesData[$linkedId], true);
79+
if ($storeIdKey !== false) {
7280
$stores = $this->storeManager->getStores(false, true);
7381
$storeId = current($stores)->getId();
7482
$storeCode = key($stores);
7583
} else {
76-
$storeId = $result[$linkedId];
84+
$storeId = current($storesData[$linkedId]);
7785
$storeCode = $this->storeManager->getStore($storeId)->getCode();
7886
}
7987
$item->setData('_first_store_id', $storeId);
8088
$item->setData('store_code', $storeCode);
81-
$item->setData('store_id', [$result[$linkedId]]);
89+
$item->setData('store_id', $storesData[$linkedId]);
8290
}
8391
}
8492
}
@@ -103,7 +111,7 @@ public function addFieldToFilter($field, $condition = null)
103111
/**
104112
* Add filter by store
105113
*
106-
* @param int|array|\Magento\Store\Model\Store $store
114+
* @param int|array|Store $store
107115
* @param bool $withAdmin
108116
* @return $this
109117
*/
@@ -112,13 +120,13 @@ abstract public function addStoreFilter($store, $withAdmin = true);
112120
/**
113121
* Perform adding filter by store
114122
*
115-
* @param int|array|\Magento\Store\Model\Store $store
123+
* @param int|array|Store $store
116124
* @param bool $withAdmin
117125
* @return void
118126
*/
119127
protected function performAddStoreFilter($store, $withAdmin = true)
120128
{
121-
if ($store instanceof \Magento\Store\Model\Store) {
129+
if ($store instanceof Store) {
122130
$store = [$store->getId()];
123131
}
124132

@@ -127,7 +135,7 @@ protected function performAddStoreFilter($store, $withAdmin = true)
127135
}
128136

129137
if ($withAdmin) {
130-
$store[] = \Magento\Store\Model\Store::DEFAULT_STORE_ID;
138+
$store[] = Store::DEFAULT_STORE_ID;
131139
}
132140

133141
$this->addFilter('store', ['in' => $store], 'public');

app/code/Magento/Cms/Model/ResourceModel/Page/Grid/Collection.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
*/
66
namespace Magento\Cms\Model\ResourceModel\Page\Grid;
77

8-
use Magento\Cms\Model\Page;
98
use Magento\Framework\Api\Search\SearchResultInterface;
109
use Magento\Framework\Api\Search\AggregationInterface;
1110
use Magento\Cms\Model\ResourceModel\Page\Collection as PageCollection;
12-
use Magento\Framework\View\Element\UiComponent\DataProvider\Document;
1311

1412
/**
1513
* Class Collection
@@ -22,11 +20,6 @@ class Collection extends PageCollection implements SearchResultInterface
2220
*/
2321
protected $aggregations;
2422

25-
/**
26-
* @var \Magento\Framework\View\Element\UiComponent\DataProvider\Document[]
27-
*/
28-
private $loadedData = [];
29-
3023
/**
3124
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
3225
* @param \Psr\Log\LoggerInterface $logger
@@ -147,23 +140,4 @@ public function setItems(array $items = null)
147140
{
148141
return $this;
149142
}
150-
151-
/**
152-
* {@inheritdoc}
153-
*/
154-
public function getItems()
155-
{
156-
if ($this->loadedData) {
157-
return $this->loadedData;
158-
}
159-
160-
/** @var Document $pageDocument */
161-
foreach (parent::getItems() as $pageDocument) {
162-
$this->loadedData[$pageDocument->getId()] = $pageDocument->setData(
163-
$this->_entityFactory->create(Page::class)->load($pageDocument->getId())->getData()
164-
);
165-
}
166-
167-
return $this->loadedData;
168-
}
169143
}

app/code/Magento/Cms/Test/Unit/Model/ResourceModel/Block/CollectionTest.php

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,34 @@ class CollectionTest extends AbstractCollectionTest
1515
*/
1616
protected $collection;
1717

18+
/**
19+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $storeManagerMock;
22+
23+
/**
24+
* @var \Magento\Framework\Model\Entity\MetadataPool|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $metadataPoolMock;
27+
1828
protected function setUp()
1929
{
2030
parent::setUp();
2131

32+
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
33+
->getMockForAbstractClass();
34+
35+
$this->metadataPoolMock = $this->getMockBuilder('Magento\Framework\Model\Entity\MetadataPool')
36+
->disableOriginalConstructor()
37+
->getMock();
38+
2239
$this->collection = $this->objectManager->getObject(
2340
'Magento\Cms\Model\ResourceModel\Block\Collection',
2441
[
2542
'resource' => $this->resource,
26-
'connection' => $this->connection
43+
'connection' => $this->connection,
44+
'storeManager' => $this->storeManagerMock,
45+
'metadataPool' => $this->metadataPoolMock,
2746
]
2847
);
2948
}
@@ -60,4 +79,60 @@ public function testAddFieldToFilter()
6079

6180
$this->assertSame($this->collection, $this->collection->addFieldToFilter($field, $value));
6281
}
82+
83+
/**
84+
* @param \Magento\Framework\DataObject $item
85+
* @param array $storesData
86+
* @dataProvider getItemsDataProvider
87+
* @throws \Exception
88+
*/
89+
public function testAfterLoad($item, $storesData)
90+
{
91+
$linkField = 'row_id';
92+
93+
$expectedResult = [];
94+
foreach ($storesData as $storeData) {
95+
$expectedResult[$storeData[$linkField]][] = $storeData['store_id'];
96+
}
97+
98+
$entityMetadataMock = $this->getMockBuilder('Magento\Framework\Model\Entity\EntityMetadata')
99+
->disableOriginalConstructor()
100+
->getMock();
101+
$entityMetadataMock->expects($this->any())->method('getLinkField')->willReturn($linkField);
102+
$this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($entityMetadataMock);
103+
104+
$this->select->expects($this->any())->method('from')->willReturnSelf();
105+
$this->connection->expects($this->any())->method('fetchAll')->willReturn($storesData);
106+
107+
$storeDataMock = $this->getMockBuilder('Magento\Store\Api\Data\StoreInterface')->getMockForAbstractClass();
108+
$storeDataMock->expects($this->any())->method('getId')->willReturn(current($expectedResult[$item->getId()]));
109+
$storeDataMock->expects($this->any())->method('getCode')->willReturn('some_code');
110+
$this->storeManagerMock->expects($this->any())->method('getStores')->willReturn([$storeDataMock]);
111+
$this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeDataMock);
112+
113+
$this->collection->addItem($item);
114+
115+
$this->assertEmpty($item->getStoreId());
116+
$this->collection->load();
117+
$this->assertEquals($expectedResult[$item->getId()], $item->getStoreId());
118+
}
119+
120+
public function getItemsDataProvider()
121+
{
122+
return [
123+
[
124+
new \Magento\Framework\DataObject(['id' => 1, 'row_id' => 1]),
125+
[
126+
['row_id' => 1, 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID],
127+
],
128+
],
129+
[
130+
new \Magento\Framework\DataObject(['id' => 2, 'row_id' => 2]),
131+
[
132+
['row_id' => 2, 'store_id' => 1],
133+
['row_id' => 2, 'store_id' => 2],
134+
],
135+
],
136+
];
137+
}
63138
}

app/code/Magento/Cms/Test/Unit/Model/ResourceModel/Page/CollectionTest.php

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,34 @@ class CollectionTest extends AbstractCollectionTest
1515
*/
1616
protected $collection;
1717

18+
/**
19+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $storeManagerMock;
22+
23+
/**
24+
* @var \Magento\Framework\Model\Entity\MetadataPool|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $metadataPoolMock;
27+
1828
protected function setUp()
1929
{
2030
parent::setUp();
2131

32+
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
33+
->getMockForAbstractClass();
34+
35+
$this->metadataPoolMock = $this->getMockBuilder('Magento\Framework\Model\Entity\MetadataPool')
36+
->disableOriginalConstructor()
37+
->getMock();
38+
2239
$this->collection = $this->objectManager->getObject(
2340
'Magento\Cms\Model\ResourceModel\Page\Collection',
2441
[
2542
'resource' => $this->resource,
26-
'connection' => $this->connection
43+
'connection' => $this->connection,
44+
'storeManager' => $this->storeManagerMock,
45+
'metadataPool' => $this->metadataPoolMock,
2746
]
2847
);
2948
}
@@ -60,4 +79,60 @@ public function testAddFieldToFilter()
6079

6180
$this->assertSame($this->collection, $this->collection->addFieldToFilter($field, $value));
6281
}
82+
83+
/**
84+
* @param \Magento\Framework\DataObject $item
85+
* @param array $storesData
86+
* @dataProvider getItemsDataProvider
87+
* @throws \Exception
88+
*/
89+
public function testAfterLoad($item, $storesData)
90+
{
91+
$linkField = 'row_id';
92+
93+
$expectedResult = [];
94+
foreach ($storesData as $storeData) {
95+
$expectedResult[$storeData[$linkField]][] = $storeData['store_id'];
96+
}
97+
98+
$entityMetadataMock = $this->getMockBuilder('Magento\Framework\Model\Entity\EntityMetadata')
99+
->disableOriginalConstructor()
100+
->getMock();
101+
$entityMetadataMock->expects($this->any())->method('getLinkField')->willReturn($linkField);
102+
$this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($entityMetadataMock);
103+
104+
$this->select->expects($this->any())->method('from')->willReturnSelf();
105+
$this->connection->expects($this->any())->method('fetchAll')->willReturn($storesData);
106+
107+
$storeDataMock = $this->getMockBuilder('Magento\Store\Api\Data\StoreInterface')->getMockForAbstractClass();
108+
$storeDataMock->expects($this->any())->method('getId')->willReturn(current($expectedResult[$item->getId()]));
109+
$storeDataMock->expects($this->any())->method('getCode')->willReturn('some_code');
110+
$this->storeManagerMock->expects($this->any())->method('getStores')->willReturn([$storeDataMock]);
111+
$this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeDataMock);
112+
113+
$this->collection->addItem($item);
114+
115+
$this->assertEmpty($item->getStoreId());
116+
$this->collection->load();
117+
$this->assertEquals($expectedResult[$item->getId()], $item->getStoreId());
118+
}
119+
120+
public function getItemsDataProvider()
121+
{
122+
return [
123+
[
124+
new \Magento\Framework\DataObject(['id' => 1, 'row_id' => 1]),
125+
[
126+
['row_id' => 1, 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID],
127+
],
128+
],
129+
[
130+
new \Magento\Framework\DataObject(['id' => 2, 'row_id' => 2]),
131+
[
132+
['row_id' => 2, 'store_id' => 1],
133+
['row_id' => 2, 'store_id' => 2],
134+
],
135+
],
136+
];
137+
}
63138
}

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,21 +673,26 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
673673
}
674674
// Existing password hash will be used from secured customer data registry when saving customer
675675
}
676+
676677
// Make sure we have a storeId to associate this customer with.
677678
if (!$customer->getStoreId()) {
678679
if ($customer->getWebsiteId()) {
679680
$storeId = $this->storeManager->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
680681
} else {
681682
$storeId = $this->storeManager->getStore()->getId();
682683
}
683-
684684
$customer->setStoreId($storeId);
685685
}
686686

687+
// Associate website_id with customer
688+
if (!$customer->getWebsiteId()) {
689+
$websiteId = $this->storeManager->getStore($customer->getStoreId())->getWebsiteId();
690+
$customer->setWebsiteId($websiteId);
691+
}
692+
687693
// Update 'created_in' value with actual store name
688694
if ($customer->getId() === null) {
689-
$storeName = $this->storeManager->getStore($customer->getStoreId())
690-
->getName();
695+
$storeName = $this->storeManager->getStore($customer->getStoreId())->getName();
691696
$customer->setCreatedIn($storeName);
692697
}
693698

app/code/Magento/Customer/Model/Observer/Grid.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Customer\Model\ResourceModel\Customer\Grid as CustomerGrid;
99

10+
/**
11+
* @deprecated
12+
*/
1013
class Grid
1114
{
1215
/**
@@ -25,6 +28,8 @@ public function __construct(
2528

2629
/**
2730
* @return void
31+
*
32+
* @deprecated
2833
*/
2934
public function syncCustomerGrid()
3035
{

0 commit comments

Comments
 (0)