Skip to content

Commit 224c658

Browse files
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGETWO-87169
2 parents dcc5e53 + 03bb798 commit 224c658

File tree

12 files changed

+380
-21
lines changed

12 files changed

+380
-21
lines changed

app/code/Magento/Catalog/Plugin/Model/ResourceModel/ReadSnapshotPlugin.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Catalog\Api\Data\CategoryInterface;
99
use Magento\Catalog\Api\Data\ProductInterface;
10-
use Magento\Eav\Model\Config;
10+
use Magento\Eav\Model\Config as EavConfig;
1111
use Magento\Eav\Model\ResourceModel\ReadSnapshot;
1212
use Magento\Framework\EntityManager\MetadataPool;
1313

@@ -24,17 +24,17 @@ class ReadSnapshotPlugin
2424
private $metadataPool;
2525

2626
/**
27-
* @var Config
27+
* @var EavConfig
2828
*/
2929
private $config;
3030

3131
/**
3232
* @param MetadataPool $metadataPool
33-
* @param Config $config
33+
* @param EavConfig $config
3434
*/
3535
public function __construct(
3636
MetadataPool $metadataPool,
37-
Config $config
37+
EavConfig $config
3838
) {
3939
$this->metadataPool = $metadataPool;
4040
$this->config = $config;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Ui\DataProvider\Product;
7+
8+
/**
9+
* Collection which is used for rendering product list in the backend.
10+
*
11+
* Used for product grid and customizes behavior of the default Product collection for grid needs.
12+
*/
13+
class ProductCollection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
14+
{
15+
/**
16+
* Disables using of price index for grid rendering
17+
*
18+
* Admin area shouldn't use price index and should rely on actual product data instead.
19+
*
20+
* @codeCoverageIgnore
21+
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
22+
*/
23+
protected function _productLimitationJoinPrice()
24+
{
25+
$this->_productLimitationFilters->setUsePriceIndex(false);
26+
return $this->_productLimitationPrice(true);
27+
}
28+
}

app/code/Magento/Catalog/etc/adminhtml/di.xml

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@
7878
<type name="Magento\Catalog\Model\ResourceModel\Attribute">
7979
<plugin name="invalidate_pagecache_after_attribute_save" type="Magento\Catalog\Plugin\Model\ResourceModel\Attribute\Save" />
8080
</type>
81+
<virtualType name="\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory" type="\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory">
82+
<arguments>
83+
<argument name="instanceName" xsi:type="string">\Magento\Catalog\Ui\DataProvider\Product\ProductCollection</argument>
84+
</arguments>
85+
</virtualType>
8186
<type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
8287
<arguments>
8388
<argument name="addFieldStrategies" xsi:type="array">
@@ -86,6 +91,7 @@
8691
<argument name="addFilterStrategies" xsi:type="array">
8792
<item name="store_id" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\AddStoreFieldToCollection</item>
8893
</argument>
94+
<argument name="collectionFactory" xsi:type="object">\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory</argument>
8995
</arguments>
9096
</type>
9197
<type name="Magento\Catalog\Model\Product\Action">

app/code/Magento/Customer/Model/Account/Redirect.php

+4
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ protected function processLoggedCustomer()
206206
$referer = $this->request->getParam(CustomerUrl::REFERER_QUERY_PARAM_NAME);
207207
if ($referer) {
208208
$referer = $this->urlDecoder->decode($referer);
209+
preg_match('/logoutSuccess/', $referer, $matches, PREG_OFFSET_CAPTURE);
210+
if (!empty($matches)) {
211+
$referer = str_replace('logoutSuccess', '', $referer);
212+
}
209213
if ($this->hostChecker->isOwnOrigin($referer)) {
210214
$this->applyRedirect($referer);
211215
}

app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens
133133
* @var array
134134
*/
135135
private $emptyStringTypes = [
136+
'int',
137+
'decimal',
136138
'datetime',
137139
'varchar',
138140
'text',

app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,19 @@ public function setAttributeSetsFilter(array $setIds)
210210
*/
211211
public function setInAllAttributeSetsFilter(array $setIds)
212212
{
213-
foreach ($setIds as $setId) {
214-
$setId = (int)$setId;
215-
if (!$setId) {
216-
continue;
217-
}
218-
$alias = sprintf('entity_attribute_%d', $setId);
219-
$joinCondition = $this->getConnection()->quoteInto(
220-
"{$alias}.attribute_id = main_table.attribute_id AND {$alias}.attribute_set_id =?",
221-
$setId
222-
);
223-
$this->join([$alias => 'eav_entity_attribute'], $joinCondition, 'attribute_id');
213+
if (!empty($setIds)) {
214+
$this->getSelect()
215+
->join(
216+
['entity_attribute' => $this->getTable('eav_entity_attribute')],
217+
'entity_attribute.attribute_id = main_table.attribute_id',
218+
['count' => new \Zend_Db_Expr('COUNT(*)')]
219+
)
220+
->where(
221+
'entity_attribute.attribute_set_id IN (?)',
222+
$setIds
223+
)
224+
->group('entity_attribute.attribute_id')
225+
->having('count = ' . count($setIds));
224226
}
225227

226228
//$this->getSelect()->distinct(true);

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/AbstractAttributeTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ public function testIsValueEmpty($isEmpty, $value, $attributeType)
228228
public function attributeValueDataProvider()
229229
{
230230
return [
231-
[false, '', 'int'],
232-
[false, '', 'decimal'],
231+
[true, '', 'int'],
232+
[true, '', 'decimal'],
233233
[true, '', 'datetime'],
234234
[true, '', 'varchar'],
235235
[true, '', 'text'],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Eav\Test\Unit\Model\ResourceModel\Entity\Attribute;
8+
9+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
12+
/**
13+
* Test for \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection class.
14+
*
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
*/
17+
class CollectionTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
21+
*/
22+
private $model;
23+
24+
/**
25+
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $entityFactoryMock;
28+
29+
/**
30+
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
private $loggerMock;
33+
34+
/**
35+
* @var \Magento\Framework\Data\Collection\Db\FetchStrategyInterface|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $fetchStrategyMock;
38+
39+
/**
40+
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $eventManagerMock;
43+
44+
/**
45+
* @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $eavConfigMock;
48+
49+
/**
50+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $storeManagerMock;
53+
54+
/**
55+
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
private $connectionMock;
58+
59+
/**
60+
* @var \Magento\Framework\Model\ResourceModel\Db\AbstractDb|\PHPUnit_Framework_MockObject_MockObject
61+
*/
62+
private $resourceMock;
63+
64+
/**
65+
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
66+
*/
67+
private $selectMock;
68+
69+
/**
70+
* {@inheritdoc}
71+
*/
72+
protected function setUp()
73+
{
74+
$this->entityFactoryMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\EntityFactory::class)
75+
->disableOriginalConstructor()
76+
->getMock();
77+
78+
$this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
79+
->disableOriginalConstructor()
80+
->getMock();
81+
82+
$this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class)
83+
->disableOriginalConstructor()
84+
->getMock();
85+
86+
$this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
87+
->disableOriginalConstructor()
88+
->getMock();
89+
90+
$this->eavConfigMock = $this->getMockBuilder(\Magento\Eav\Model\Config::class)
91+
->disableOriginalConstructor()
92+
->getMock();
93+
94+
$this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
95+
->disableOriginalConstructor()
96+
->getMock();
97+
98+
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
99+
->disableOriginalConstructor()
100+
->getMock();
101+
102+
$this->resourceMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class)
103+
->setMethods(['__wakeup', 'getConnection', 'getMainTable', 'getTable'])
104+
->disableOriginalConstructor()
105+
->getMockForAbstractClass();
106+
107+
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
108+
$this->resourceMock->expects($this->any())->method('getMainTable')->willReturn('eav_entity_attribute');
109+
110+
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
111+
->disableOriginalConstructor()
112+
->getMock();
113+
114+
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock);
115+
116+
$objectManager = new ObjectManager($this);
117+
$this->model = $objectManager->getObject(
118+
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class,
119+
[
120+
'entityFactory' => $this->entityFactoryMock,
121+
'logger' => $this->loggerMock,
122+
'fetchStrategy' => $this->fetchStrategyMock,
123+
'eventManager' => $this->eventManagerMock,
124+
'eavConfig' => $this->eavConfigMock,
125+
'connection' => $this->connectionMock,
126+
'resource' => $this->resourceMock,
127+
]
128+
);
129+
}
130+
131+
/**
132+
* Test method \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::setInAllAttributeSetsFilter
133+
*
134+
* @return void
135+
*/
136+
public function testSetInAllAttributeSetsFilter()
137+
{
138+
$setIds = [1, 2, 3];
139+
140+
$this->selectMock->expects($this->atLeastOnce())
141+
->method('where')
142+
->with('entity_attribute.attribute_set_id IN (?)', $setIds)
143+
->willReturnSelf();
144+
$this->selectMock->expects($this->atLeastOnce())->method('join')->with(
145+
['entity_attribute' => $this->model->getTable('eav_entity_attribute')],
146+
'entity_attribute.attribute_id = main_table.attribute_id',
147+
['count' => new \Zend_Db_Expr('COUNT(*)')]
148+
)->willReturnSelf();
149+
150+
$this->selectMock->expects($this->atLeastOnce())->method('group')->with('entity_attribute.attribute_id')
151+
->willReturnSelf();
152+
153+
$this->selectMock->expects($this->atLeastOnce())->method('having')->with('count = ' . count($setIds))
154+
->willReturnSelf();
155+
156+
$this->model->setInAllAttributeSetsFilter($setIds);
157+
}
158+
}

0 commit comments

Comments
 (0)