ConfigProviderPlugin.php 2.4 KB

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