Collection.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ProductAlert\Model\ResourceModel\Stock;
  7. /**
  8. * Product alert for back in stock collection
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  16. {
  17. /**
  18. * Define stock collection
  19. *
  20. * @return void
  21. */
  22. protected function _construct()
  23. {
  24. $this->_init(\Magento\ProductAlert\Model\Stock::class, \Magento\ProductAlert\Model\ResourceModel\Stock::class);
  25. }
  26. /**
  27. * Add website filter
  28. *
  29. * @param mixed $website
  30. * @return $this
  31. */
  32. public function addWebsiteFilter($website)
  33. {
  34. $connection = $this->getConnection();
  35. if ($website === null || $website == 0) {
  36. return $this;
  37. }
  38. if (is_array($website)) {
  39. $condition = $connection->quoteInto('website_id IN(?)', $website);
  40. } elseif ($website instanceof \Magento\Store\Model\Website) {
  41. $condition = $connection->quoteInto('website_id=?', $website->getId());
  42. } else {
  43. $condition = $connection->quoteInto('website_id=?', $website);
  44. }
  45. $this->addFilter('website_id', $condition, 'string');
  46. return $this;
  47. }
  48. /**
  49. * Add status filter
  50. *
  51. * @param int $status
  52. * @return $this
  53. */
  54. public function addStatusFilter($status)
  55. {
  56. $condition = $this->getConnection()->quoteInto('status=?', $status);
  57. $this->addFilter('status', $condition, 'string');
  58. return $this;
  59. }
  60. /**
  61. * Set order by customer
  62. *
  63. * @param string $sort
  64. * @return $this
  65. */
  66. public function setCustomerOrder($sort = 'ASC')
  67. {
  68. $this->getSelect()->order('customer_id ' . $sort);
  69. return $this;
  70. }
  71. }