Stock.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ProductAlert\Model;
  7. use Magento\ProductAlert\Model\ResourceModel\Stock\Customer\Collection;
  8. /**
  9. * ProductAlert for back in stock model
  10. *
  11. * @method int getCustomerId()
  12. * @method \Magento\ProductAlert\Model\Stock setCustomerId(int $value)
  13. * @method int getProductId()
  14. * @method \Magento\ProductAlert\Model\Stock setProductId(int $value)
  15. * @method int getWebsiteId()
  16. * @method \Magento\ProductAlert\Model\Stock setWebsiteId(int $value)
  17. * @method string getAddDate()
  18. * @method \Magento\ProductAlert\Model\Stock setAddDate(string $value)
  19. * @method string getSendDate()
  20. * @method \Magento\ProductAlert\Model\Stock setSendDate(string $value)
  21. * @method int getSendCount()
  22. * @method \Magento\ProductAlert\Model\Stock setSendCount(int $value)
  23. * @method int getStatus()
  24. * @method \Magento\ProductAlert\Model\Stock setStatus(int $value)
  25. * @method int getStoreId()
  26. * @method \Magento\ProductAlert\Model\Stock setStoreId(int $value)
  27. *
  28. * @author Magento Core Team <core@magentocommerce.com>
  29. *
  30. * @api
  31. * @since 100.0.2
  32. */
  33. class Stock extends \Magento\Framework\Model\AbstractModel
  34. {
  35. /**
  36. * @var \Magento\ProductAlert\Model\ResourceModel\Stock\Customer\CollectionFactory
  37. */
  38. protected $_customerColFactory;
  39. /**
  40. * @param \Magento\Framework\Model\Context $context
  41. * @param \Magento\Framework\Registry $registry
  42. * @param \Magento\ProductAlert\Model\ResourceModel\Stock\Customer\CollectionFactory $customerColFactory
  43. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  44. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  45. * @param array $data
  46. */
  47. public function __construct(
  48. \Magento\Framework\Model\Context $context,
  49. \Magento\Framework\Registry $registry,
  50. \Magento\ProductAlert\Model\ResourceModel\Stock\Customer\CollectionFactory $customerColFactory,
  51. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  52. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  53. array $data = []
  54. ) {
  55. $this->_customerColFactory = $customerColFactory;
  56. parent::__construct($context, $registry, $resource, $resourceCollection, $data);
  57. }
  58. /**
  59. * Class constructor.
  60. *
  61. * @return void
  62. */
  63. protected function _construct()
  64. {
  65. $this->_init(\Magento\ProductAlert\Model\ResourceModel\Stock::class);
  66. }
  67. /**
  68. * Create customer collection.
  69. *
  70. * @return Collection
  71. */
  72. public function getCustomerCollection()
  73. {
  74. return $this->_customerColFactory->create();
  75. }
  76. /**
  77. * Load by param.
  78. *
  79. * @return $this
  80. */
  81. public function loadByParam()
  82. {
  83. if ($this->getProductId() !== null && $this->getCustomerId() !== null && $this->getWebsiteId() !== null) {
  84. $this->getResource()->loadByParam($this);
  85. }
  86. return $this;
  87. }
  88. /**
  89. * Method for deleting customer from website.
  90. *
  91. * @param int $customerId
  92. * @param int $websiteId
  93. * @return $this
  94. */
  95. public function deleteCustomer($customerId, $websiteId = 0)
  96. {
  97. $this->getResource()->deleteCustomer($this, $customerId, $websiteId);
  98. return $this;
  99. }
  100. }