Collection.php 1.6 KB

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