|
7 | 7 |
|
8 | 8 | namespace Magento\Quote\Model;
|
9 | 9 |
|
| 10 | +use Magento\Framework\App\ObjectManager; |
| 11 | +use Magento\Framework\Exception\NoSuchEntityException; |
10 | 12 | use Magento\Quote\Api\CartRepositoryInterface;
|
| 13 | +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; |
11 | 14 | use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource;
|
12 | 15 |
|
13 | 16 | /**
|
|
16 | 19 | class QuoteIdToMaskedQuoteId implements QuoteIdToMaskedQuoteIdInterface
|
17 | 20 | {
|
18 | 21 | /**
|
19 |
| - * @var QuoteIdMaskFactory |
20 |
| - */ |
21 |
| - private $quoteIdMaskFactory; |
22 |
| - /** |
23 |
| - * @var CartRepositoryInterface |
| 22 | + * @var QuoteIdMaskResource |
24 | 23 | */
|
25 |
| - private $cartRepository; |
| 24 | + private $quoteIdMaskResource; |
26 | 25 |
|
27 | 26 | /**
|
28 |
| - * @var QuoteIdMaskResource |
| 27 | + * @var QuoteResource |
29 | 28 | */
|
30 |
| - private $quoteIdMaskResource; |
| 29 | + private $quoteResource; |
31 | 30 |
|
32 | 31 | /**
|
33 | 32 | * @param QuoteIdMaskFactory $quoteIdMaskFactory
|
34 | 33 | * @param CartRepositoryInterface $cartRepository
|
35 | 34 | * @param QuoteIdMaskResource $quoteIdMaskResource
|
| 35 | + * @param QuoteResource|null $quoteResourceModel |
| 36 | + * |
| 37 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
36 | 38 | */
|
37 | 39 | public function __construct(
|
38 | 40 | QuoteIdMaskFactory $quoteIdMaskFactory,
|
39 | 41 | CartRepositoryInterface $cartRepository,
|
40 |
| - QuoteIdMaskResource $quoteIdMaskResource |
| 42 | + QuoteIdMaskResource $quoteIdMaskResource, |
| 43 | + QuoteResource $quoteResourceModel = null |
41 | 44 | ) {
|
42 |
| - $this->quoteIdMaskFactory = $quoteIdMaskFactory; |
43 |
| - $this->cartRepository = $cartRepository; |
44 | 45 | $this->quoteIdMaskResource = $quoteIdMaskResource;
|
| 46 | + $this->quoteResource = $quoteResourceModel ?? ObjectManager::getInstance()->get(QuoteResource::class); |
45 | 47 | }
|
46 | 48 |
|
47 | 49 | /**
|
48 | 50 | * @inheritDoc
|
49 | 51 | */
|
50 | 52 | public function execute(int $quoteId): string
|
51 | 53 | {
|
52 |
| - /* Check the quote exists to avoid database constraint issues */ |
53 |
| - $this->cartRepository->get($quoteId); |
54 |
| - |
55 |
| - $quoteIdMask = $this->quoteIdMaskFactory->create(); |
56 |
| - $this->quoteIdMaskResource->load($quoteIdMask, $quoteId, 'quote_id'); |
57 |
| - $maskedId = $quoteIdMask->getMaskedId() ?? ''; |
| 54 | + // Check the quote exists to avoid database constraint issues |
| 55 | + if (!$this->quoteResource->isExists($quoteId)) { |
| 56 | + throw new NoSuchEntityException( |
| 57 | + __( |
| 58 | + 'No such entity with %fieldName = %fieldValue', |
| 59 | + [ |
| 60 | + 'fieldName' => 'quoteId', |
| 61 | + 'fieldValue' => $quoteId |
| 62 | + ] |
| 63 | + ) |
| 64 | + ); |
| 65 | + } |
58 | 66 |
|
59 |
| - return $maskedId; |
| 67 | + return (string)$this->quoteIdMaskResource->getMaskedQuoteId($quoteId); |
60 | 68 | }
|
61 | 69 | }
|
0 commit comments