Skip to content

Commit 419c416

Browse files
committed
MAGETWO-99401: order-related save_after_commit callbacks are not called for guest checkouts
1 parent a285d53 commit 419c416

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

lib/internal/Magento/Framework/Config/Scope.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public function setCurrentScope($scope)
6969
public function getAllScopes()
7070
{
7171
$codes = $this->_areaList->getCodes();
72-
array_unshift($codes, $this->_defaultScope);
72+
array_unshift($codes, 'global');
73+
array_unshift($codes, 'primary');
74+
7375
return $codes;
7476
}
7577
}

lib/internal/Magento/Framework/Config/Test/Unit/ScopeTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@
66

77
namespace Magento\Framework\Config\Test\Unit;
88

9-
use \Magento\Framework\Config\Scope;
9+
use Magento\Framework\App\AreaList;
10+
use Magento\Framework\Config\Scope;
11+
use PHPUnit\Framework\MockObject\MockObject;
1012

1113
class ScopeTest extends \PHPUnit\Framework\TestCase
1214
{
1315
/**
14-
* @var \Magento\Framework\Config\Scope
16+
* @var Scope
1517
*/
16-
protected $model;
18+
private $model;
1719

1820
/**
19-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\AreaList
21+
* @var MockObject|AreaList
2022
*/
21-
protected $areaListMock;
23+
private $areaListMock;
2224

2325
protected function setUp()
2426
{
25-
$this->areaListMock = $this->createPartialMock(\Magento\Framework\App\AreaList::class, ['getCodes']);
27+
$this->areaListMock = $this->createPartialMock(AreaList::class, ['getCodes']);
2628
$this->model = new Scope($this->areaListMock);
2729
}
2830

@@ -35,10 +37,10 @@ public function testScopeSetGet()
3537

3638
public function testGetAllScopes()
3739
{
38-
$expectedBalances = ['primary', 'test_scope'];
40+
$expectedBalances = ['primary', 'global', 'test_scope'];
3941
$this->areaListMock->expects($this->once())
4042
->method('getCodes')
41-
->will($this->returnValue(['test_scope']));
43+
->willReturn(['test_scope']);
4244
$this->assertEquals($expectedBalances, $this->model->getAllScopes());
4345
}
4446
}

lib/internal/Magento/Framework/Interception/Config/Config.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ private function initializeUncompiled($classDefinitions = [])
202202
private function generateIntercepted($classDefinitions)
203203
{
204204
$config = [];
205-
$scopes = $this->_scopeList->getAllScopes();
206-
array_unshift($scopes, 'primary');
207-
foreach (array_unique($scopes) as $scope) {
205+
foreach ($this->_scopeList->getAllScopes() as $scope) {
208206
$config = array_replace_recursive($config, $this->_reader->read($scope));
209207
}
210208
unset($config['preferences']);

lib/internal/Magento/Framework/Model/ExecuteCommitCallbacks.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class ExecuteCommitCallbacks
2020
*/
2121
private $logger;
2222

23+
/**
24+
* @param LoggerInterface $logger
25+
*/
2326
public function __construct(LoggerInterface $logger)
2427
{
2528
$this->logger = $logger;
@@ -31,12 +34,11 @@ public function __construct(LoggerInterface $logger)
3134
* @param AdapterInterface $subject
3235
* @param AdapterInterface $result
3336
* @return AdapterInterface
34-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3537
*/
3638
public function afterCommit(AdapterInterface $subject, AdapterInterface $result): AdapterInterface
3739
{
3840
if ($result->getTransactionLevel() === 0) {
39-
$callbacks = CallbackPool::get(spl_object_hash($result));
41+
$callbacks = CallbackPool::get(spl_object_hash($subject));
4042
foreach ($callbacks as $callback) {
4143
try {
4244
call_user_func($callback);
@@ -48,4 +50,18 @@ public function afterCommit(AdapterInterface $subject, AdapterInterface $result)
4850

4951
return $result;
5052
}
53+
54+
/**
55+
* Drop callbacks after rollBack.
56+
*
57+
* @param AdapterInterface $subject
58+
* @param AdapterInterface $result
59+
* @return AdapterInterface
60+
*/
61+
public function afterRollBack(AdapterInterface $subject, AdapterInterface $result): AdapterInterface
62+
{
63+
CallbackPool::clear(spl_object_hash($subject));
64+
65+
return $result;
66+
}
5167
}

lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,19 @@ public function addCommitCallback($callback)
8787
public function commit()
8888
{
8989
$this->getConnection()->commit();
90-
90+
/**
91+
* Process after commit callbacks
92+
*/
93+
if ($this->getConnection()->getTransactionLevel() === 0) {
94+
$callbacks = CallbackPool::get(spl_object_hash($this->getConnection()));
95+
try {
96+
foreach ($callbacks as $callback) {
97+
call_user_func($callback);
98+
}
99+
} catch (\Exception $e) {
100+
$this->getLogger()->critical($e);
101+
}
102+
}
91103
return $this;
92104
}
93105

0 commit comments

Comments
 (0)