Skip to content

Commit 28916b5

Browse files
author
Alexander Akimov
authored
Merge pull request #2235 from magento-tsg/2.3-develop-pr5
[TSG] Forwardports for 2.3 (pr5) (2.3.0)
2 parents dea8b32 + 35c089c commit 28916b5

File tree

14 files changed

+371
-110
lines changed

14 files changed

+371
-110
lines changed

app/code/Magento/Catalog/Cron/DeleteOutdatedPriceValues.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,46 @@ public function __construct(
4848
}
4949

5050
/**
51-
* Delete all price values for non-admin stores if PRICE_SCOPE is global
51+
* Delete all price values for non-admin stores if PRICE_SCOPE is set to global.
5252
*
5353
* @return void
5454
*/
5555
public function execute()
5656
{
57-
$priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE);
58-
if ($priceScope == Store::PRICE_SCOPE_GLOBAL) {
59-
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $priceAttribute */
60-
$priceAttribute = $this->attributeRepository
61-
->get(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE);
62-
$connection = $this->resource->getConnection();
63-
$conditions = [
64-
$connection->quoteInto('attribute_id = ?', $priceAttribute->getId()),
65-
$connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID),
66-
];
57+
if (!$this->isPriceScopeSetToGlobal()) {
58+
return;
59+
}
60+
61+
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $priceAttribute */
62+
$priceAttribute = $this->attributeRepository
63+
->get(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE);
64+
$connection = $this->resource->getConnection();
65+
$conditions = [
66+
$connection->quoteInto('attribute_id = ?', $priceAttribute->getId()),
67+
$connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID),
68+
];
6769

68-
$connection->delete(
69-
$priceAttribute->getBackend()->getTable(),
70-
$conditions
71-
);
70+
$connection->delete(
71+
$priceAttribute->getBackend()->getTable(),
72+
$conditions
73+
);
74+
}
75+
76+
/**
77+
* Checks if price scope config option explicitly equal to global value.
78+
*
79+
* Such strict comparision is required to prevent price deleting when
80+
* price scope config option is null for some reason.
81+
*
82+
* @return bool
83+
*/
84+
private function isPriceScopeSetToGlobal()
85+
{
86+
$priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE);
87+
if ($priceScope === null) {
88+
return false;
7289
}
90+
91+
return (int)$priceScope === Store::PRICE_SCOPE_GLOBAL;
7392
}
7493
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Model\ResourceModel\Provider;
7+
8+
use Magento\Framework\App\ResourceConnection;
9+
use Magento\Framework\DB\Adapter\AdapterInterface;
10+
11+
/**
12+
* Retrieves ID's of not synced by `updated_at` column entities.
13+
* The result should contain list of entities ID's from the main table which have `updated_at` column greater
14+
* than in the grid table.
15+
*/
16+
class UpdatedAtListProvider implements NotSyncedDataProviderInterface
17+
{
18+
/**
19+
* @var ResourceConnection
20+
*/
21+
private $resourceConnection;
22+
23+
/**
24+
* @var AdapterInterface
25+
*/
26+
private $connection;
27+
28+
/**
29+
* @param ResourceConnection $resourceConnection
30+
*/
31+
public function __construct(ResourceConnection $resourceConnection)
32+
{
33+
$this->connection = $resourceConnection->getConnection('sales');
34+
$this->resourceConnection = $resourceConnection;
35+
}
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
public function getIds($mainTableName, $gridTableName)
41+
{
42+
$mainTableName = $this->resourceConnection->getTableName($mainTableName);
43+
$gridTableName = $this->resourceConnection->getTableName($gridTableName);
44+
$select = $this->connection->select()
45+
->from($mainTableName, [$mainTableName . '.entity_id'])
46+
->joinInner(
47+
[$gridTableName => $gridTableName],
48+
sprintf(
49+
'%s.entity_id = %s.entity_id AND %s.updated_at > %s.updated_at',
50+
$mainTableName,
51+
$gridTableName,
52+
$mainTableName,
53+
$gridTableName
54+
),
55+
[]
56+
);
57+
58+
return $this->connection->fetchAll($select, [], \Zend_Db::FETCH_COLUMN);
59+
}
60+
}

app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedIdListProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ public function __construct(
3838
*/
3939
public function getIds($mainTableName, $gridTableName)
4040
{
41+
$mainTableName = $this->resourceConnection->getTableName($mainTableName);
42+
$gridTableName = $this->resourceConnection->getTableName($gridTableName);
4143
$select = $this->getConnection()->select()
42-
->from($this->getConnection()->getTableName($mainTableName), [$mainTableName . '.entity_id'])
44+
->from($mainTableName, [$mainTableName . '.entity_id'])
4345
->joinLeft(
44-
[$gridTableName => $this->getConnection()->getTableName($gridTableName)],
46+
[$gridTableName => $gridTableName],
4547
sprintf(
4648
'%s.%s = %s.%s',
4749
$mainTableName,

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Provider/NotSyncedDataProviderTest.php

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
*/
66
namespace Magento\Sales\Test\Unit\Model\ResourceModel\Provider;
77

8-
use Magento\Framework\ObjectManager\TMap;
98
use Magento\Framework\ObjectManager\TMapFactory;
109
use Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProvider;
1110
use Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProviderInterface;
1211
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1312

1413
/**
15-
* Class NotSyncedDataProviderTest
14+
* Class for testing not synchronized DataProvider.
1615
*/
1716
class NotSyncedDataProviderTest extends \PHPUnit\Framework\TestCase
1817
{
@@ -23,77 +22,46 @@ public function testGetIdsEmpty()
2322
->disableOriginalConstructor()
2423
->setMethods(['create'])
2524
->getMock();
26-
$tMap = $this->getMockBuilder(TMap::class)
27-
->disableOriginalConstructor()
28-
->getMock();
2925

30-
$tMapFactory->expects(static::once())
31-
->method('create')
32-
->with(
33-
[
34-
'array' => [],
35-
'type' => NotSyncedDataProviderInterface::class
36-
]
37-
)
38-
->willReturn($tMap);
39-
$tMap->expects(static::once())
40-
->method('getIterator')
41-
->willReturn(new \ArrayIterator([]));
26+
$tMapFactory->method('create')
27+
->willReturn([]);
4228

43-
$provider = new NotSyncedDataProvider($tMapFactory, []);
44-
static::assertEquals([], $provider->getIds('main_table', 'grid_table'));
29+
$provider = new NotSyncedDataProvider($tMapFactory);
30+
self::assertEquals([], $provider->getIds('main_table', 'grid_table'));
4531
}
4632

47-
/**
48-
* @covers \Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProvider::getIds
49-
*/
5033
public function testGetIds()
5134
{
5235
/** @var TMapFactory|MockObject $tMapFactory */
5336
$tMapFactory = $this->getMockBuilder(TMapFactory::class)
5437
->disableOriginalConstructor()
5538
->setMethods(['create'])
5639
->getMock();
57-
$tMap = $this->getMockBuilder(TMap::class)
58-
->disableOriginalConstructor()
59-
->getMock();
6040

6141
$provider1 = $this->getMockBuilder(NotSyncedDataProviderInterface::class)
6242
->getMockForAbstractClass();
63-
$provider1->expects(static::once())
64-
->method('getIds')
43+
$provider1->method('getIds')
6544
->willReturn([1, 2]);
6645

6746
$provider2 = $this->getMockBuilder(NotSyncedDataProviderInterface::class)
6847
->getMockForAbstractClass();
69-
$provider2->expects(static::once())
70-
->method('getIds')
48+
$provider2->method('getIds')
7149
->willReturn([2, 3, 4]);
7250

73-
$tMapFactory->expects(static::once())
74-
->method('create')
75-
->with(
51+
$tMapFactory->method('create')
52+
->with(self::equalTo(
7653
[
77-
'array' => [
78-
'provider1' => NotSyncedDataProviderInterface::class,
79-
'provider2' => NotSyncedDataProviderInterface::class
80-
],
54+
'array' => [$provider1, $provider2],
8155
'type' => NotSyncedDataProviderInterface::class
8256
]
83-
)
84-
->willReturn($tMap);
85-
$tMap->expects(static::once())
86-
->method('getIterator')
87-
->willReturn(new \ArrayIterator([$provider1, $provider2]));
57+
))
58+
->willReturn([$provider1, $provider2]);
8859

89-
$provider = new NotSyncedDataProvider(
90-
$tMapFactory,
91-
[
92-
'provider1' => NotSyncedDataProviderInterface::class,
93-
'provider2' => NotSyncedDataProviderInterface::class,
94-
]
95-
);
60+
$provider = new NotSyncedDataProvider($tMapFactory, [$provider1, $provider2]);
9661

97-
static::assertEquals([1, 2, 3, 4], array_values($provider->getIds('main_table', 'grid_table')));
62+
self::assertEquals(
63+
[1, 2, 3, 4],
64+
array_values($provider->getIds('main_table', 'grid_table'))
65+
);
9866
}
9967
}

app/code/Magento/Sales/etc/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,14 @@
470470
<argument name="entityRelationComposite" xsi:type="object">CreditmemoRelationsComposite</argument>
471471
</arguments>
472472
</type>
473+
<virtualType name="Magento\Sales\Model\ResourceModel\Provider\NotSyncedOrderDataProvider" type="Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProvider">
474+
<arguments>
475+
<argument name="providers" xsi:type="array">
476+
<item name="default" xsi:type="string">Magento\Sales\Model\ResourceModel\Provider\UpdatedIdListProvider</item>
477+
<item name="updated_at" xsi:type="string">Magento\Sales\Model\ResourceModel\Provider\UpdatedAtListProvider</item>
478+
</argument>
479+
</arguments>
480+
</virtualType>
473481
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
474482
<arguments>
475483
<argument name="mainTableName" xsi:type="string">sales_order</argument>
@@ -520,6 +528,7 @@
520528
<item name="payment_method" xsi:type="string">sales_order_payment.method</item>
521529
<item name="total_refunded" xsi:type="string">sales_order.total_refunded</item>
522530
</argument>
531+
<argument name="notSyncedDataProvider" xsi:type="object">Magento\Sales\Model\ResourceModel\Provider\NotSyncedOrderDataProvider</argument>
523532
</arguments>
524533
</virtualType>
525534
<virtualType name="ShipmentGridAggregator" type="Magento\Sales\Model\ResourceModel\Grid">

0 commit comments

Comments
 (0)