Skip to content

Commit 421b3b4

Browse files
committed
ACP2E-778: REST API: Product names in cart always use default store view values
1 parent 3a4ef56 commit 421b3b4

File tree

1 file changed

+30
-8
lines changed
  • app/code/Magento/Quote/Model/ResourceModel

1 file changed

+30
-8
lines changed

app/code/Magento/Quote/Model/ResourceModel/Quote.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
namespace Magento\Quote\Model\ResourceModel;
88

9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Model\ResourceModel\Db\Context;
911
use Magento\Framework\Model\ResourceModel\Db\VersionControl\AbstractDb;
1012
use Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite;
1113
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot;
14+
use Magento\Quote\Api\CartRepositoryInterface;
1215
use Magento\SalesSequence\Model\Manager;
1316

1417
/**
@@ -17,26 +20,39 @@
1720
class Quote extends AbstractDb
1821
{
1922
/**
20-
* @var \Magento\SalesSequence\Model\Manager
23+
* Sales sequence manager
24+
*
25+
* @var Manager
2126
*/
2227
protected $sequenceManager;
2328

2429
/**
25-
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
30+
* Quote repository.
31+
*
32+
* @var CartRepositoryInterface
33+
*/
34+
private $quoteRepository;
35+
36+
/**
37+
* @param Context $context
2638
* @param Snapshot $entitySnapshot
2739
* @param RelationComposite $entityRelationComposite
28-
* @param \Magento\SalesSequence\Model\Manager $sequenceManager
29-
* @param string $connectionName
40+
* @param Manager $sequenceManager
41+
* @param null $connectionName
42+
* @param CartRepositoryInterface|null $quoteRepository
3043
*/
3144
public function __construct(
32-
\Magento\Framework\Model\ResourceModel\Db\Context $context,
45+
Context $context,
3346
Snapshot $entitySnapshot,
3447
RelationComposite $entityRelationComposite,
3548
Manager $sequenceManager,
36-
$connectionName = null
49+
$connectionName = null,
50+
CartRepositoryInterface $quoteRepository = null
3751
) {
3852
parent::__construct($context, $entitySnapshot, $entityRelationComposite, $connectionName);
3953
$this->sequenceManager = $sequenceManager;
54+
$this->quoteRepository = $quoteRepository ?: ObjectManager::getInstance()
55+
->get(CartRepositoryInterface::class);
4056
}
4157

4258
/**
@@ -105,13 +121,19 @@ public function loadByCustomerId($quote, $customerId)
105121

106122
if ($data) {
107123
//Prevent current StoreId of the quote to be overridden
124+
$isStoreSwitched = false;
108125
$currentStoreId = $quote->getStoreId();
109-
if ($currentStoreId !== null && $currentStoreId !== $data['store_id']) {
126+
if ($currentStoreId !== null && $currentStoreId !== (int)$data['store_id']) {
110127
unset($data['store_id']);
128+
$isStoreSwitched = true;
111129
}
112-
113130
$quote->setData($data);
114131
$quote->setOrigData();
132+
133+
//Update StoreId to quote on store switching
134+
if ($isStoreSwitched) {
135+
$this->quoteRepository->save($quote);
136+
}
115137
}
116138

117139
$this->_afterLoad($quote);

0 commit comments

Comments
 (0)