Skip to content

Commit a285d53

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

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

app/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,4 +1777,7 @@
17771777
type="Magento\Framework\Mail\MimeMessage" />
17781778
<preference for="Magento\Framework\Mail\MimePartInterface"
17791779
type="Magento\Framework\Mail\MimePart" />
1780+
<type name="Magento\Framework\DB\Adapter\AdapterInterface">
1781+
<plugin name="execute_commit_callbacks" type="Magento\Framework\Model\ExecuteCommitCallbacks" />
1782+
</type>
17801783
</config>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ private function initializeUncompiled($classDefinitions = [])
202202
private function generateIntercepted($classDefinitions)
203203
{
204204
$config = [];
205-
foreach ($this->_scopeList->getAllScopes() as $scope) {
205+
$scopes = $this->_scopeList->getAllScopes();
206+
array_unshift($scopes, 'primary');
207+
foreach (array_unique($scopes) as $scope) {
206208
$config = array_replace_recursive($config, $this->_reader->read($scope));
207209
}
208210
unset($config['preferences']);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\Framework\Model;
9+
10+
use Magento\Framework\DB\Adapter\AdapterInterface;
11+
use Psr\Log\LoggerInterface;
12+
13+
/**
14+
* Execute added callbacks for transaction commit.
15+
*/
16+
class ExecuteCommitCallbacks
17+
{
18+
/**
19+
* @var LoggerInterface
20+
*/
21+
private $logger;
22+
23+
public function __construct(LoggerInterface $logger)
24+
{
25+
$this->logger = $logger;
26+
}
27+
28+
/**
29+
* Execute callbacks after commit.
30+
*
31+
* @param AdapterInterface $subject
32+
* @param AdapterInterface $result
33+
* @return AdapterInterface
34+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
35+
*/
36+
public function afterCommit(AdapterInterface $subject, AdapterInterface $result): AdapterInterface
37+
{
38+
if ($result->getTransactionLevel() === 0) {
39+
$callbacks = CallbackPool::get(spl_object_hash($result));
40+
foreach ($callbacks as $callback) {
41+
try {
42+
call_user_func($callback);
43+
} catch (\Throwable $e) {
44+
$this->logger->critical($e);
45+
}
46+
}
47+
}
48+
49+
return $result;
50+
}
51+
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,7 @@ public function addCommitCallback($callback)
8787
public function commit()
8888
{
8989
$this->getConnection()->commit();
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-
}
90+
10391
return $this;
10492
}
10593

0 commit comments

Comments
 (0)