|
| 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\Quote\Model\Quote\Plugin; |
| 9 | + |
| 10 | +use Magento\Quote\Model\Quote; |
| 11 | +use Magento\Quote\Model\QuoteRepository; |
| 12 | +use Magento\Store\Model\StoreManagerInterface; |
| 13 | + |
| 14 | +/** |
| 15 | + * Updates quote store id. |
| 16 | + */ |
| 17 | +class UpdateQuoteStoreId |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var QuoteRepository |
| 21 | + */ |
| 22 | + private $quoteRepository; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var StoreManagerInterface |
| 26 | + */ |
| 27 | + private $storeManager; |
| 28 | + |
| 29 | + /** |
| 30 | + * @param QuoteRepository $quoteRepository |
| 31 | + * @param StoreManagerInterface $storeManager |
| 32 | + */ |
| 33 | + public function __construct( |
| 34 | + QuoteRepository $quoteRepository, |
| 35 | + StoreManagerInterface $storeManager |
| 36 | + ) { |
| 37 | + $this->quoteRepository = $quoteRepository; |
| 38 | + $this->storeManager = $storeManager; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Update store id in requested quote by store id from request. |
| 43 | + * |
| 44 | + * @param Quote $subject |
| 45 | + * @param null $result |
| 46 | + * @return void |
| 47 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 48 | + */ |
| 49 | + public function afterLoadByIdWithoutStore( |
| 50 | + Quote $subject, |
| 51 | + $result |
| 52 | + ) { |
| 53 | + $quoteStoreId = (int) $subject->getStoreId(); |
| 54 | + $storeId = $this->storeManager->getStore() |
| 55 | + ->getId() ?: $this->storeManager->getDefaultStoreView() |
| 56 | + ->getId(); |
| 57 | + if ($storeId !== $quoteStoreId) { |
| 58 | + $subject->setStoreId($storeId); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments