Collection.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\ResourceModel\Quote\Address;
  7. /**
  8. * Quote addresses collection
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionControl\Collection
  13. {
  14. /**
  15. * Event prefix
  16. *
  17. * @var string
  18. */
  19. protected $_eventPrefix = 'sales_quote_address_collection';
  20. /**
  21. * Event object name
  22. *
  23. * @var string
  24. */
  25. protected $_eventObject = 'quote_address_collection';
  26. /**
  27. * Resource initialization
  28. *
  29. * @return void
  30. */
  31. protected function _construct()
  32. {
  33. $this->_init(
  34. \Magento\Quote\Model\Quote\Address::class,
  35. \Magento\Quote\Model\ResourceModel\Quote\Address::class
  36. );
  37. }
  38. /**
  39. * Setting filter on quote_id field but if quote_id is 0
  40. * we should exclude loading junk data from DB
  41. *
  42. * @param int $quoteId
  43. * @return $this
  44. */
  45. public function setQuoteFilter($quoteId)
  46. {
  47. $this->addFieldToFilter('quote_id', $quoteId ? $quoteId : ['null' => 1]);
  48. return $this;
  49. }
  50. /**
  51. * Redeclare after load method for dispatch event
  52. *
  53. * @return $this
  54. */
  55. protected function _afterLoad()
  56. {
  57. parent::_afterLoad();
  58. $this->_eventManager->dispatch($this->_eventPrefix . '_load_after', [$this->_eventObject => $this]);
  59. return $this;
  60. }
  61. }