Skip to content

Commit 328bc51

Browse files
committed
Fix #14958 - apply requested changes
1 parent c83a283 commit 328bc51

File tree

10 files changed

+329
-116
lines changed

10 files changed

+329
-116
lines changed

app/code/Magento/SalesSequence/Model/ResourceModel/Meta.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,6 @@ public function loadByEntityTypeAndStore($entityType, $storeId)
9292
return $meta;
9393
}
9494

95-
/**
96-
* Retrieves Metadata Ids by store id
97-
*
98-
* @param int $storeId
99-
* @return int[]
100-
* @throws \Magento\Framework\Exception\LocalizedException
101-
*/
102-
public function getIdsByStore($storeId)
103-
{
104-
$connection = $this->getConnection();
105-
$bind = ['store_id' => $storeId];
106-
$select = $connection->select()->from(
107-
$this->getMainTable(),
108-
[$this->getIdFieldName()]
109-
)->where(
110-
'store_id = :store_id'
111-
);
112-
113-
return $connection->fetchCol($select, $bind);
114-
}
115-
11695
/**
11796
* Using for load sequence profile and setting it into metadata
11897
*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesSequence\Model\ResourceModel\Meta;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
12+
13+
/**
14+
* Class Ids is used to retrieve metadata ids for sequence
15+
*/
16+
class Ids extends AbstractDb
17+
{
18+
/**
19+
* Model initialization
20+
*
21+
* @return void
22+
*/
23+
protected function _construct()
24+
{
25+
$this->_init('sales_sequence_meta', 'meta_id');
26+
}
27+
28+
/**
29+
* Retrieves Metadata Ids by store id
30+
*
31+
* @param int $storeId
32+
* @return int[]
33+
* @throws LocalizedException
34+
*/
35+
public function getByStoreId($storeId)
36+
{
37+
$connection = $this->getConnection();
38+
$bind = ['store_id' => $storeId];
39+
$select = $connection->select()->from(
40+
$this->getMainTable(),
41+
[$this->getIdFieldName()]
42+
)->where(
43+
'store_id = :store_id'
44+
);
45+
46+
return $connection->fetchCol($select, $bind);
47+
}
48+
}

app/code/Magento/SalesSequence/Model/ResourceModel/Profile.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,4 @@ public function loadActiveProfile($metadataId)
7777
}
7878
return $profile;
7979
}
80-
81-
/**
82-
* Get profile ids by metadata ids
83-
*
84-
* @param int[] $metadataIds
85-
* @return int[]
86-
* @throws \Magento\Framework\Exception\LocalizedException
87-
*/
88-
public function getProfileIdsByMetadataIds(array $metadataIds)
89-
{
90-
$connection = $this->getConnection();
91-
$select = $connection->select()
92-
->from($this->getMainTable(), ['profile_id'])
93-
->where('meta_id IN (?)', $metadataIds);
94-
95-
return $connection->fetchCol($select);
96-
}
9780
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\SalesSequence\Model\ResourceModel\Profile;
8+
9+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
10+
11+
/**
12+
* Class Ids is used to retrieve profile ids for sequence profile
13+
*/
14+
class Ids extends AbstractDb
15+
{
16+
/**
17+
* Model initialization
18+
*
19+
* @return void
20+
*/
21+
protected function _construct()
22+
{
23+
$this->_init('sales_sequence_profile', 'profile_id');
24+
}
25+
26+
/**
27+
* Get profile ids by metadata ids
28+
*
29+
* @param int[] $metadataIds
30+
* @return int[]
31+
* @throws \Magento\Framework\Exception\LocalizedException
32+
*/
33+
public function getByMetadataIds(array $metadataIds)
34+
{
35+
$connection = $this->getConnection();
36+
$select = $connection->select()
37+
->from($this->getMainTable(), ['profile_id'])
38+
->where('meta_id IN (?)', $metadataIds);
39+
40+
return $connection->fetchCol($select);
41+
}
42+
}

app/code/Magento/SalesSequence/Model/Sequence/DeleteByStore.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,29 @@
1010
use Magento\Framework\App\ResourceConnection as AppResource;
1111
use Magento\SalesSequence\Model\MetaFactory;
1212
use Magento\SalesSequence\Model\ResourceModel\Meta as ResourceMetadata;
13-
use Magento\SalesSequence\Model\ResourceModel\Profile as ResourceProfile;
13+
use Magento\SalesSequence\Model\ResourceModel\Meta\Ids as ResourceMetadataIds;
14+
use Magento\SalesSequence\Model\ResourceModel\Profile\Ids as ResourceProfileIds;
1415
use Magento\Store\Api\Data\StoreInterface;
1516

1617
/**
1718
* Class DeleteByStore
18-
* @api
1919
*/
2020
class DeleteByStore
2121
{
2222
/**
23-
* @var resourceMetadata
23+
* @var ResourceMetadata
2424
*/
2525
private $resourceMetadata;
2626

2727
/**
28-
* @var ResourceProfile
28+
* @var ResourceMetadataIds
2929
*/
30-
private $resourceProfile;
30+
private $resourceMetadataIds;
31+
32+
/**
33+
* @var ResourceProfileIds
34+
*/
35+
private $resourceProfileIds;
3136

3237
/**
3338
* @var MetaFactory
@@ -41,18 +46,21 @@ class DeleteByStore
4146

4247
/**
4348
* @param ResourceMetadata $resourceMetadata
44-
* @param ResourceProfile $resourceProfile
49+
* @param ResourceMetadataIds $resourceMetadataIds
50+
* @param ResourceProfileIds $resourceProfileIds
4551
* @param MetaFactory $metaFactory
4652
* @param AppResource $appResource
4753
*/
4854
public function __construct(
4955
ResourceMetadata $resourceMetadata,
50-
ResourceProfile $resourceProfile,
56+
ResourceMetadataIds $resourceMetadataIds,
57+
ResourceProfileIds $resourceProfileIds,
5158
MetaFactory $metaFactory,
5259
AppResource $appResource
5360
) {
5461
$this->resourceMetadata = $resourceMetadata;
55-
$this->resourceProfile = $resourceProfile;
62+
$this->resourceMetadataIds = $resourceMetadataIds;
63+
$this->resourceProfileIds = $resourceProfileIds;
5664
$this->metaFactory = $metaFactory;
5765
$this->appResource = $appResource;
5866
}
@@ -66,8 +74,8 @@ public function __construct(
6674
*/
6775
public function execute(StoreInterface $store): void
6876
{
69-
$metadataIds = $this->resourceMetadata->getIdsByStore($store->getId());
70-
$profileIds = $this->resourceProfile->getProfileIdsByMetadataIds($metadataIds);
77+
$metadataIds = $this->resourceMetadataIds->getByStoreId($store->getId());
78+
$profileIds = $this->resourceProfileIds->getByMetadataIds($metadataIds);
7179

7280
$this->appResource->getConnection()->delete(
7381
$this->appResource->getTableName('sales_sequence_profile'),
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\SalesSequence\Test\Unit\Model\ResourceModel\Meta;
7+
8+
use Magento\Framework\App\ResourceConnection;
9+
use Magento\Framework\DB\Adapter\AdapterInterface;
10+
use Magento\Framework\DB\Select;
11+
use Magento\Framework\Model\ResourceModel\Db\Context;
12+
use Magento\SalesSequence\Model\ResourceModel\Meta\Ids;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Class IdsTest
18+
*/
19+
class IdsTest extends TestCase
20+
{
21+
/**
22+
* @var AdapterInterface | MockObject
23+
*/
24+
private $connectionMock;
25+
26+
/**
27+
* @var Context | MockObject
28+
*/
29+
private $dbContext;
30+
31+
/**
32+
* @var Ids
33+
*/
34+
private $resource;
35+
36+
/**
37+
* @var Resource | MockObject
38+
*/
39+
protected $resourceMock;
40+
41+
/**
42+
* @var Select | MockObject
43+
*/
44+
private $select;
45+
46+
/**
47+
* Initialization
48+
*/
49+
protected function setUp()
50+
{
51+
$this->connectionMock = $this->getMockForAbstractClass(
52+
AdapterInterface::class,
53+
[],
54+
'',
55+
false,
56+
false,
57+
true,
58+
['query']
59+
);
60+
$this->dbContext = $this->createMock(Context::class);
61+
$this->resourceMock = $this->createPartialMock(
62+
ResourceConnection::class,
63+
['getConnection', 'getTableName']
64+
);
65+
$this->dbContext->expects($this->once())->method('getResources')->willReturn($this->resourceMock);
66+
$this->select = $this->createMock(Select::class);
67+
$this->resource = new Ids(
68+
$this->dbContext
69+
);
70+
}
71+
72+
public function testGetByStoreId()
73+
{
74+
$metaTableName = 'sequence_meta';
75+
$metaIdFieldName = 'meta_id';
76+
$storeId = 1;
77+
$metaIds = [1, 2];
78+
$this->resourceMock->expects($this->any())
79+
->method('getConnection')
80+
->willReturn($this->connectionMock);
81+
$this->resourceMock->expects($this->once())
82+
->method('getTableName')
83+
->willReturn($metaTableName);
84+
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->select);
85+
$this->select->expects($this->at(0))
86+
->method('from')
87+
->with($metaTableName, [$metaIdFieldName])
88+
->willReturn($this->select);
89+
$this->select->expects($this->at(1))
90+
->method('where')
91+
->with('store_id = :store_id')
92+
->willReturn($this->select);
93+
$this->connectionMock->expects($this->once())
94+
->method('fetchCol')
95+
->with($this->select, ['store_id' => $storeId])
96+
->willReturn($metaIds);
97+
$this->assertEquals($metaIds, $this->resource->getByStoreId($storeId));
98+
}
99+
}

app/code/Magento/SalesSequence/Test/Unit/Model/ResourceModel/MetaTest.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -128,34 +128,6 @@ public function testLoadBy()
128128
$this->assertEquals($this->meta, $this->resource->loadByEntityTypeAndStore($entityType, $storeId));
129129
}
130130

131-
public function testGetIdsByStore()
132-
{
133-
$metaTableName = 'sequence_meta';
134-
$metaIdFieldName = 'meta_id';
135-
$storeId = 1;
136-
$metaIds = [1, 2];
137-
$this->resourceMock->expects($this->any())
138-
->method('getConnection')
139-
->willReturn($this->connectionMock);
140-
$this->resourceMock->expects($this->once())
141-
->method('getTableName')
142-
->willReturn($metaTableName);
143-
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->select);
144-
$this->select->expects($this->at(0))
145-
->method('from')
146-
->with($metaTableName, [$metaIdFieldName])
147-
->willReturn($this->select);
148-
$this->select->expects($this->at(1))
149-
->method('where')
150-
->with('store_id = :store_id')
151-
->willReturn($this->select);
152-
$this->connectionMock->expects($this->once())
153-
->method('fetchCol')
154-
->with($this->select, ['store_id' => $storeId])
155-
->willReturn($metaIds);
156-
$this->assertEquals($metaIds, $this->resource->getIdsByStore($storeId));
157-
}
158-
159131
/**
160132
* @param $metaData
161133
*/

0 commit comments

Comments
 (0)