Skip to content

Commit f9559c2

Browse files
committed
MAGETWO-36935: Orders placed in different store views should not have duplicated IDs
1 parent 8cd5cab commit f9559c2

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

app/code/Magento/Sales/Model/Resource/EntityAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
136136
$object->setIncrementId(
137137
$this->sequenceManager->getSequence(
138138
$object->getEntityType(),
139-
$object->getStore()->getId()
139+
$object->getStore()->getGroup()->getDefaultStoreId()
140140
)->getNextValue()
141141
);
142142
}

app/code/Magento/Sales/Test/Unit/Model/Resource/OrderTest.php

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class OrderTest extends \PHPUnit_Framework_TestCase
8989
*/
9090
protected $relationCompositeMock;
9191

92+
/**
93+
* @var \Magento\Framework\Model\Resource\Db\ObjectRelationProcessor|\PHPUnit_Framework_MockObject_MockObject
94+
*/
95+
protected $objectRelationProcessorMock;
9296
/**
9397
* Mock class dependencies
9498
*/
@@ -106,10 +110,16 @@ public function setUp()
106110
'',
107111
false
108112
);
109-
$this->storeMock = $this->getMock('Magento\Store\Model\Store', ['__wakeup'], [], '', false);
110-
$this->storeGroupMock = $this->getMock('Magento\Store\Model\Group', ['__wakeup'], [], '', false);
111-
$this->websiteMock = $this->getMock('Magento\Sales\Model\Website', ['__wakeup'], [], '', false);
112-
$this->customerMock = $this->getMock('Magento\Customer\Model\Customer', ['__wakeup'], [], '', false);
113+
$this->storeMock = $this->getMock(
114+
'Magento\Store\Model\Store',
115+
[],
116+
[],
117+
'',
118+
false
119+
);
120+
$this->storeGroupMock = $this->getMock('Magento\Store\Model\Group', [], [], '', false);
121+
$this->websiteMock = $this->getMock('Magento\Sales\Model\Website', [], [], '', false);
122+
$this->customerMock = $this->getMock('Magento\Customer\Model\Customer', [], [], '', false);
113123
$this->orderItemCollectionMock = $this->getMock(
114124
'Magento\Sales\Model\Resource\Order\Item\Collection',
115125
[],
@@ -154,7 +164,7 @@ public function setUp()
154164
'',
155165
false
156166
);
157-
$this->salesSequenceMock = $this->getMock('Magento\SalesSequence\Sequence', [], [], '', false);
167+
$this->salesSequenceMock = $this->getMock('Magento\SalesSequence\Model\Sequence', [], [], '', false);
158168
$this->entitySnapshotMock = $this->getMock(
159169
'Magento\Sales\Model\Resource\EntitySnapshot',
160170
[],
@@ -169,8 +179,18 @@ public function setUp()
169179
'',
170180
false
171181
);
182+
$this->objectRelationProcessorMock = $this->getMock(
183+
'Magento\Framework\Model\Resource\Db\ObjectRelationProcessor',
184+
[],
185+
[],
186+
'',
187+
false
188+
);
172189
$contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false);
173190
$contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock);
191+
$contextMock->expects($this->once())
192+
->method('getObjectRelationProcessor')
193+
->willReturn($this->objectRelationProcessorMock);
174194

175195
$this->resource = new Order(
176196
$contextMock,
@@ -184,6 +204,51 @@ public function setUp()
184204

185205
public function testSave()
186206
{
207+
208+
$this->orderMock->expects($this->once())
209+
->method('validateBeforeSave')
210+
->willReturnSelf();
211+
$this->orderMock->expects($this->once())
212+
->method('beforeSave')
213+
->willReturnSelf();
214+
$this->orderMock->expects($this->once())
215+
->method('isSaveAllowed')
216+
->willReturn(true);
217+
$this->orderMock->expects($this->once())
218+
->method('getEntityType')
219+
->willReturn('order');
220+
$this->orderMock->expects($this->once())
221+
->method('getStore')
222+
->willReturn($this->storeMock);
223+
$this->storeMock->expects($this->once())
224+
->method('getGroup')
225+
->willReturn($this->storeGroupMock);
226+
$this->storeGroupMock->expects($this->once())
227+
->method('getDefaultStoreId')
228+
->willReturn(1);
229+
$this->salesSequenceManagerMock->expects($this->once())
230+
->method('getSequence')
231+
->with('order', 1)
232+
->willReturn($this->salesSequenceMock);
233+
$this->salesSequenceMock->expects($this->once())
234+
->method('getNextValue')
235+
->willReturn('10000001');
236+
$this->orderMock->expects($this->once())
237+
->method('setIncrementId')
238+
->with('10000001')
239+
->willReturnSelf();
240+
$this->orderMock->expects($this->once())
241+
->method('getIncrementId')
242+
->willReturn(null);
243+
$this->orderMock->expects($this->once())
244+
->method('getData')
245+
->willReturn(['increment_id' => '10000001']);
246+
$this->objectRelationProcessorMock->expects($this->once())
247+
->method('validateDataIntegrity')
248+
->with(null, ['increment_id' => '10000001']);
249+
$this->relationCompositeMock->expects($this->once())
250+
->method('processRelations')
251+
->with($this->orderMock);
187252
$this->resourceMock->expects($this->any())
188253
->method('getConnection')
189254
->willReturn($this->adapterMock);

0 commit comments

Comments
 (0)