QuoteIdMask.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model;
  7. /**
  8. * QuoteIdMask model
  9. *
  10. * @method string getMaskedId()
  11. * @method QuoteIdMask setMaskedId()
  12. */
  13. class QuoteIdMask extends \Magento\Framework\Model\AbstractModel
  14. {
  15. /**
  16. * @var \Magento\Framework\Math\Random
  17. */
  18. protected $randomDataGenerator;
  19. /**
  20. * @param \Magento\Framework\Model\Context $context
  21. * @param \Magento\Framework\Registry $registry
  22. * @param \Magento\Framework\Math\Random $randomDataGenerator
  23. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  24. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  25. * @param array $data
  26. */
  27. public function __construct(
  28. \Magento\Framework\Model\Context $context,
  29. \Magento\Framework\Registry $registry,
  30. \Magento\Framework\Math\Random $randomDataGenerator,
  31. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  32. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  33. array $data = []
  34. ) {
  35. $this->randomDataGenerator = $randomDataGenerator;
  36. parent::__construct($context, $registry, $resource, $resourceCollection, $data);
  37. }
  38. /**
  39. * Initialize resource
  40. *
  41. * @return void
  42. */
  43. protected function _construct()
  44. {
  45. $this->_init(\Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask::class);
  46. }
  47. /**
  48. * Initialize quote identifier before save
  49. *
  50. * @return $this
  51. */
  52. public function beforeSave()
  53. {
  54. parent::beforeSave();
  55. $this->setMaskedId($this->randomDataGenerator->getUniqueHash());
  56. return $this;
  57. }
  58. }