|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Persistent\Model\Checkout; |
| 7 | + |
| 8 | +use Magento\Persistent\Helper\Session as PersistentSession; |
| 9 | +use Magento\Persistent\Helper\Data as PersistentHelper; |
| 10 | +use Magento\Checkout\Model\Session as CheckoutSession; |
| 11 | +use Magento\Quote\Model\QuoteIdMaskFactory; |
| 12 | +use Magento\Customer\Model\Session as CustomerSession; |
| 13 | + |
| 14 | +class ConfigProviderPlugin |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var PersistentSession |
| 18 | + */ |
| 19 | + private $persistentSession; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var PersistentHelper |
| 23 | + */ |
| 24 | + private $persistentHelper; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var CheckoutSession |
| 28 | + */ |
| 29 | + private $checkoutSession; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var QuoteIdMaskFactory |
| 33 | + */ |
| 34 | + private $quoteIdMaskFactory; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var CustomerSession |
| 38 | + */ |
| 39 | + private $customerSession; |
| 40 | + |
| 41 | + /** |
| 42 | + * @param PersistentHelper $persistentHelper |
| 43 | + * @param PersistentSession $persistentSession |
| 44 | + * @param CheckoutSession $checkoutSession |
| 45 | + * @param QuoteIdMaskFactory $quoteIdMaskFactory |
| 46 | + * @param CustomerSession $customerSession |
| 47 | + */ |
| 48 | + public function __construct( |
| 49 | + PersistentHelper $persistentHelper, |
| 50 | + PersistentSession $persistentSession, |
| 51 | + CheckoutSession $checkoutSession, |
| 52 | + QuoteIdMaskFactory $quoteIdMaskFactory, |
| 53 | + CustomerSession $customerSession |
| 54 | + ) { |
| 55 | + $this->persistentHelper = $persistentHelper; |
| 56 | + $this->persistentSession = $persistentSession; |
| 57 | + $this->checkoutSession = $checkoutSession; |
| 58 | + $this->quoteIdMaskFactory = $quoteIdMaskFactory; |
| 59 | + $this->customerSession = $customerSession; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @param \Magento\Checkout\Model\DefaultConfigProvider $subject |
| 64 | + * @param array $result |
| 65 | + * @return array |
| 66 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 67 | + */ |
| 68 | + public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result) |
| 69 | + { |
| 70 | + if ($this->persistentHelper->isEnabled() |
| 71 | + && $this->persistentSession->isPersistent() |
| 72 | + && !$this->customerSession->isLoggedIn() |
| 73 | + ) { |
| 74 | + /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */ |
| 75 | + $quoteIdMask = $this->quoteIdMaskFactory->create(); |
| 76 | + $result['quoteData']['entity_id'] = $quoteIdMask->load( |
| 77 | + $this->checkoutSession->getQuote()->getId(), |
| 78 | + 'quote_id' |
| 79 | + )->getMaskedId(); |
| 80 | + } |
| 81 | + return $result; |
| 82 | + } |
| 83 | +} |
0 commit comments