|
6 | 6 |
|
7 | 7 | namespace Magento\Quote\Model\ResourceModel;
|
8 | 8 |
|
| 9 | +use Magento\Framework\App\ObjectManager; |
| 10 | +use Magento\Framework\Model\ResourceModel\Db\Context; |
9 | 11 | use Magento\Framework\Model\ResourceModel\Db\VersionControl\AbstractDb;
|
10 | 12 | use Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite;
|
11 | 13 | use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot;
|
| 14 | +use Magento\Quote\Api\CartRepositoryInterface; |
12 | 15 | use Magento\SalesSequence\Model\Manager;
|
13 | 16 |
|
14 | 17 | /**
|
|
17 | 20 | class Quote extends AbstractDb
|
18 | 21 | {
|
19 | 22 | /**
|
20 |
| - * @var \Magento\SalesSequence\Model\Manager |
| 23 | + * Sales sequence manager |
| 24 | + * |
| 25 | + * @var Manager |
21 | 26 | */
|
22 | 27 | protected $sequenceManager;
|
23 | 28 |
|
24 | 29 | /**
|
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 |
26 | 38 | * @param Snapshot $entitySnapshot
|
27 | 39 | * @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 |
30 | 43 | */
|
31 | 44 | public function __construct(
|
32 |
| - \Magento\Framework\Model\ResourceModel\Db\Context $context, |
| 45 | + Context $context, |
33 | 46 | Snapshot $entitySnapshot,
|
34 | 47 | RelationComposite $entityRelationComposite,
|
35 | 48 | Manager $sequenceManager,
|
36 |
| - $connectionName = null |
| 49 | + $connectionName = null, |
| 50 | + CartRepositoryInterface $quoteRepository = null |
37 | 51 | ) {
|
38 | 52 | parent::__construct($context, $entitySnapshot, $entityRelationComposite, $connectionName);
|
39 | 53 | $this->sequenceManager = $sequenceManager;
|
| 54 | + $this->quoteRepository = $quoteRepository ?: ObjectManager::getInstance() |
| 55 | + ->get(CartRepositoryInterface::class); |
40 | 56 | }
|
41 | 57 |
|
42 | 58 | /**
|
@@ -105,13 +121,19 @@ public function loadByCustomerId($quote, $customerId)
|
105 | 121 |
|
106 | 122 | if ($data) {
|
107 | 123 | //Prevent current StoreId of the quote to be overridden
|
| 124 | + $isStoreSwitched = false; |
108 | 125 | $currentStoreId = $quote->getStoreId();
|
109 |
| - if ($currentStoreId !== null && $currentStoreId !== $data['store_id']) { |
| 126 | + if ($currentStoreId !== null && $currentStoreId !== (int)$data['store_id']) { |
110 | 127 | unset($data['store_id']);
|
| 128 | + $isStoreSwitched = true; |
111 | 129 | }
|
112 |
| - |
113 | 130 | $quote->setData($data);
|
114 | 131 | $quote->setOrigData();
|
| 132 | + |
| 133 | + //Update StoreId to quote on store switching |
| 134 | + if ($isStoreSwitched) { |
| 135 | + $this->quoteRepository->save($quote); |
| 136 | + } |
115 | 137 | }
|
116 | 138 |
|
117 | 139 | $this->_afterLoad($quote);
|
|
0 commit comments